MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / create_org

Function create_org

app/api/agentops/opsboard/views/orgs.py:226–259  ·  view source on GitHub ↗

Create a new organization and add the authenticated user as owner.

(
    *,
    request: Request,
    orm: Session = Depends(get_orm_session),
    body: OrgCreateSchema,
)

Source from the content-addressed store, hash-verified

224
225
226def create_org(
227 *,
228 request: Request,
229 orm: Session = Depends(get_orm_session),
230 body: OrgCreateSchema,
231) -> OrgResponse:
232 """
233 Create a new organization and add the authenticated user as owner.
234 """
235 if not (user := UserModel.get_by_id(orm, request.state.session.user_id)):
236 raise HTTPException(status_code=500, detail="User not found")
237
238 org: OrgModel = OrgModel(name=body.name)
239 orm.add(org)
240 orm.flush() # generate the id
241
242 # TODO user may not have an email address here
243 # this displays in the UI for the user in the list of org members
244 user_org: UserOrgModel = UserOrgModel(
245 user_id=user.id,
246 org_id=org.id,
247 role=OrgRoles.owner,
248 user_email=user.email,
249 is_paid=True, # Mark owner as paid from creation
250 )
251 orm.add(user_org)
252
253 orm.commit()
254
255 # Reload with relationships to ensure we have users loaded
256 org = OrgModel.get_by_id(orm, org.id)
257
258 org.set_current_user(request.state.session.user_id)
259 return OrgResponse.model_validate(org)
260
261
262def update_org(

Callers 2

test_create_orgFunction · 0.90

Calls 4

set_current_userMethod · 0.95
OrgModelClass · 0.85
UserOrgModelClass · 0.85
get_by_idMethod · 0.45

Tested by 2

test_create_orgFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…