async def query_create(conn, organization_id: OrganizationID, self_granted_role: RealmGrantedRole) -> None: assert self_granted_role.granted_by.user_id == self_granted_role.user_id assert self_granted_role.role == RealmRole.OWNER realm_internal_id = await conn.fetchval(_q_insert_realm, organization_id, self_granted_role.realm_id) if not realm_internal_id: raise RealmAlreadyExistsError() await conn.execute( _q_insert_realm_role, realm_internal_id, organization_id, self_granted_role.user_id, self_granted_role.certificate, self_granted_role.granted_by, self_granted_role.granted_on, ) await conn.execute(_q_insert_realm_encryption_revision, realm_internal_id) await send_signal( conn, "realm.roles_updated", organization_id=organization_id, author=self_granted_role.granted_by, realm_id=self_granted_role.realm_id, user=self_granted_role.user_id, role_str=self_granted_role.role.value, )
async def query_create(conn, organization_id: OrganizationID, self_granted_role: RealmGrantedRole) -> None: assert self_granted_role.granted_by is not None assert self_granted_role.granted_by.user_id == self_granted_role.user_id assert self_granted_role.role == RealmRole.OWNER realm_internal_id = await conn.fetchval(*_q_insert_realm( organization_id=organization_id, realm_id=self_granted_role.realm_id)) if not realm_internal_id: raise RealmAlreadyExistsError() await conn.execute(*_q_insert_realm_role( realm_internal_id=realm_internal_id, organization_id=organization_id, user_id=self_granted_role.user_id, certificate=self_granted_role.certificate, certified_by=self_granted_role.granted_by, certified_on=self_granted_role.granted_on, )) await conn.execute(*_q_insert_realm_encryption_revision( _id=realm_internal_id)) await send_signal( conn, BackendEvent.REALM_ROLES_UPDATED, organization_id=organization_id, author=self_granted_role.granted_by, realm_id=self_granted_role.realm_id, user=self_granted_role.user_id, role_str=self_granted_role.role.value, )
async def create(self, organization_id: OrganizationID, self_granted_role: RealmGrantedRole) -> None: assert self_granted_role.granted_by.user_id == self_granted_role.user_id assert self_granted_role.role == RealmRole.OWNER key = (organization_id, self_granted_role.realm_id) if key not in self._realms: self._realms[key] = Realm(granted_roles=[self_granted_role]) await self._send_event( "realm.roles_updated", organization_id=organization_id, author=self_granted_role.granted_by, realm_id=self_granted_role.realm_id, user=self_granted_role.user_id, role=self_granted_role.role, ) else: raise RealmAlreadyExistsError()