public async Task <IActionResult> AddGroup(string key, [FromBody] AddGroupToCollectionRequest request) { try { var userKey = _contextAccessor.UserKeyFromContext(); bool userCanAccessCollection = await UserCanAccessCollection(userKey, key, _hiarcDatabase, AccessLevelGroup.ReadWriteOrHigher); if (userCanAccessCollection) { await _hiarcDatabase.AddGroupToCollection(key, request); return(Ok(new Empty())); } else { return(StatusCode(StatusCodes.Status403Forbidden)); } } catch (InvalidOperationException ex) { _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status403Forbidden)); } catch (Exception ex) { return(BuildErrorResponse(ex, _logger)); } }
public async Task <Empty> AddGroupToCollection(string collectionKey, string groupKey, string accessLevel, string asUserKey = null, string bearerToken = null, bool logToConsole = true) { var request = new AddGroupToCollectionRequest() { GroupKey = groupKey, AccessLevel = accessLevel }; var result = await Put <AddGroupToCollectionRequest, Empty>(request, $"collections/{collectionKey}/groups", asUserKey, bearerToken); if (logToConsole) { Console.WriteLine($"Added Group to Collection: Collection=\"{collectionKey}\", Group=\"{groupKey}\", AccessLevel=\"{accessLevel}\""); } ; return(result); }