public async Task <IActionResult> AddMemberGroups(string memberRef, [FromBody] JArray groupRefs) { if (groupRefs.Count == 0) { throw Errors.GenericBadRequest; } var system = await ResolveSystem("@me"); var member = await ResolveMember(memberRef); if (member == null) { throw Errors.MemberNotFound; } if (member.System != system.Id) { throw Errors.NotOwnMemberError; } var groups = new List <GroupId>(); foreach (var JgroupRef in groupRefs) { var groupRef = JgroupRef.Value <string>(); var group = await ResolveGroup(groupRef, cache : true); if (group == null) { throw Errors.GroupNotFound; } if (group.System != system.Id) { throw Errors.NotOwnGroupErrorWithRef(groupRef); } groups.Add(group.Id); } var existingGroups = await _repo.GetMemberGroups(member.Id).Select(x => x.Id).ToListAsync(); groups = groups.Where(x => !existingGroups.Contains(x)).ToList(); if (groups.Count > 0) { await _repo.AddGroupsToMember(member.Id, groups); } return(NoContent()); }
public async Task <IActionResult> OverwriteMemberGroups(string memberRef, [FromBody] JArray groupRefs) { var system = await ResolveSystem("@me"); var member = await ResolveMember(memberRef); if (member == null) { throw Errors.MemberNotFound; } if (member.System != system.Id) { throw Errors.NotOwnMemberError; } var groups = new List <GroupId>(); foreach (var JgroupRef in groupRefs) { var groupRef = JgroupRef.Value <string>(); var group = await ResolveGroup(groupRef, cache : true); if (group == null) { throw Errors.GroupNotFoundWithRef(groupRef); } if (group.System != system.Id) { throw Errors.NotOwnGroupErrorWithRef(groupRef); } groups.Add(group.Id); } await _repo.ClearMemberGroups(member.Id); if (groups.Count > 0) { await _repo.AddGroupsToMember(member.Id, groups); } return(NoContent()); }
public async Task <IActionResult> RemoveMemberGroups(string memberRef, [FromBody] JArray groupRefs) { if (groupRefs.Count == 0) { throw Errors.GenericBadRequest; } var system = await ResolveSystem("@me"); var member = await ResolveMember(memberRef); if (member == null) { throw Errors.MemberNotFound; } if (member.System != system.Id) { throw Errors.NotOwnMemberError; } var groups = new List <GroupId>(); foreach (var JgroupRef in groupRefs) { var groupRef = JgroupRef.Value <string>(); var group = await ResolveGroup(groupRef); if (group == null) { throw Errors.GroupNotFoundWithRef(groupRef); } if (group.System != system.Id) { throw Errors.NotOwnGroupErrorWithRef(groupRef); } groups.Add(group.Id); } await _repo.RemoveGroupsFromMember(member.Id, groups); return(NoContent()); }