/// <summary> /// Changes a user role within the organization /// </summary> /// <param name="dbCtx"></param> /// <param name="user"></param> /// <returns></returns> public async Task ChangeOrganizationUserRoleAsync(DbContext dbCtx, MapHiveUser user) { //this basically needs to remove all the org roles for a user and add the specified one var ownerRole = await GetOrgOwnerRoleAsync(dbCtx); var adminRole = await GetOrgAdminRoleAsync(dbCtx); var memberRole = await GetOrgMemberRoleAsync(dbCtx); var addRole = memberRole; switch (user.OrganizationRole) { case OrganizationRole.Admin: addRole = adminRole; break; case OrganizationRole.Owner: addRole = ownerRole; break; } user.RemoveLink(ownerRole); user.RemoveLink(adminRole); user.RemoveLink(memberRole); if (user.OrganizationRole.HasValue) { user.AddLink(addRole); } await user.UpdateAsync(dbCtx); }
/// <summary> /// Adds a member to an organization /// </summary> /// <param name="dbCtx"></param> /// <param name="user"></param> /// <param name="role"></param> /// <returns></returns> public async Task AddOrganizationUserAsync(DbContext dbCtx, MapHiveUser user, OrganizationRole role = OrganizationRole.Member) { this.AddLink(user); await this.UpdateAsync(dbCtx); //by default assign a member role to a user var memberRole = await this.GetOrgRoleAsync(dbCtx, role); user.AddLink(memberRole); await user.UpdateAsync <MapHiveUser>(dbCtx); }
/// <summary> /// Adds a user to an org as an admin. /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="u"></param> /// <returns></returns> public static async Task AddAdminAsync(this Organization org, DbContext dbCtx, MapHiveUser u) { //first find the admin role - it should always be there as it is created on org create var adminR = await org.GetOrgAdminRoleAsync(dbCtx); //and next link it to a user u.AddLink(adminR); await u.UpdateWithNoIdentityChangesAsync <MapHiveUser>(dbCtx); //and also add a user to an org - this will not change anything if a user is already linked org.AddLink(u); await org.UpdateAsync(dbCtx, org.Uuid); }
/// <summary> /// /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="u"></param> /// <returns></returns> public static async Task AddOwnerAsync(this Organization org, DbContext dbCtx, MapHiveUser u) { //first find the owner role - it should always be there as it is created on org create var ownerR = await org.GetOrgOwnerRoleAsync(dbCtx); //and next link it to a user u.AddLink(ownerR); await u.UpdateWithNoIdentityChangesAsync <MapHiveUser>(dbCtx); //and also add a user to an org org.AddLink(u); await org.UpdateAsync(dbCtx); }