public GroupsAndRequestsDto GetGroupsAndRequestsOfUser(string securityToken) { try { var session = CheckSession(securityToken); var result = new GroupsAndRequestsDto(); var groups = _dao.GetByUser(session.IdUser); var groupsResult = Mapper.Map <List <GroupDetailsDto> >(groups); for (var i = 0; i < groups.Count; i++) { groupsResult[i].IsAdministrable = groups[i].IdAdmin == session.IdUser; } result.Groups = groupsResult; using (var userGroupServices = new UserGroupServices()) { result.Requests = userGroupServices.GetRequestsOfUser(securityToken); } return(result); } catch (FileSharingException) { throw; } catch (Exception e) { throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e); } }
void CheckAuthorizationToFile(SessionDto session, File file) { if (file.IdUser != session.IdUser && !file.IsPublic) { UserGroupDto userGroup = null; if (file.IdGroup.HasValue) { using (var userGroupServices = new UserGroupServices()) { userGroup = userGroupServices.Read(session.SecurityToken, session.IdUser, file.IdGroup.Value); } } if (userGroup?.DateInclusionApproval == null) { throw new FileSharingException(FileSharingException.UNAUTHORIZED, "You do not have permissions to read this file"); } } }
public long Create(string securityToken, string name) { try { var session = CheckSession(securityToken); var similarName = _dao.QueryByName(name, 0, 0); if (similarName.Count > 0 && similarName.Find(g => g.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) != null) { throw new FileSharingException(FileSharingException.GROUP_NAME_ALREADY_IN_USE, "Group name already in use"); } var groupDom = new Group { Name = name, IdAdmin = session.IdUser }; groupDom = _dao.Create(groupDom); Audit(session.IdUser, groupDom.Id.ToString(), typeof(Group).Name, ActionDto.Create, "Group created: " + groupDom); using (var userGroupService = new UserGroupServices()) { var userGroup = new UserGroupDto { IdUser = session.IdUser, IdGroup = groupDom.Id, DateInclusionRequest = DateTime.Now, DateInclusionApproval = DateTime.Now }; userGroupService.Create(securityToken, userGroup); } return(groupDom.Id); } catch (FileSharingException) { throw; } catch (Exception e) { throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e); } }