public async Task <RuleResult> Execute(BaseRequest obj) { var username = User.Identity.Name.ToUpper(); var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username); if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser) { obj.Approved = true; return(Success()); } if (obj.RequestType == RequestType.Movie && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie)) { obj.Approved = true; } if (obj.RequestType == RequestType.TvShow && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv)) { obj.Approved = true; } if (obj.RequestType == RequestType.Album && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic)) { obj.Approved = true; } return(Success()); // We don't really care, we just don't set the obj to approve }
public async Task <RuleResult> Execute(BaseRequest obj) { var currentUser = await User.GetUser(); var username = currentUser.UserName.ToUpper(); var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username); if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser) { return(Success()); } if (obj.RequestType == RequestType.Movie) { var movie = (MovieRequests)obj; var hasAutoApprove = await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie); if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMovie) || hasAutoApprove) { if (movie.Is4kRequest && !hasAutoApprove) { var has4kPermission = await _manager.IsInRoleAsync(user, OmbiRoles.Request4KMovie); if (has4kPermission) { return(Success()); } } else { return(Success()); } } return(Fail(ErrorCode.NoPermissionsRequestMovie, "You do not have permissions to Request a Movie")); } if (obj.RequestType == RequestType.TvShow) { if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestTv) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv)) { return(Success()); } return(Fail(ErrorCode.NoPermissionsRequestTV, "You do not have permissions to Request a TV Show")); } if (obj.RequestType == RequestType.Album) { if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMusic) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic)) { return(Success()); } return(Fail(ErrorCode.NoPermissionsRequestAlbum, "You do not have permissions to Request an Album")); } throw new InvalidDataException("Permission check failed: unknown RequestType"); }
public async Task <RuleResult> Execute(BaseRequest obj) { var username = User.Identity.Name.ToUpper(); var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username); if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser) { return(Success()); } if (obj.RequestType == RequestType.Movie) { if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMovie) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie)) { return(Success()); } return(Fail("You do not have permissions to Request a Movie")); } if (obj.RequestType == RequestType.TvShow) { if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestTv) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv)) { return(Success()); } return(Fail("You do not have permissions to Request a TV Show")); } if (obj.RequestType == RequestType.Album) { if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMusic) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic)) { return(Success()); } return(Fail("You do not have permissions to Request an Album")); } throw new InvalidDataException("Permission check failed: unknown RequestType"); }
public async Task <RuleResult> Execute(BaseRequest obj) { var user = await _manager.Users.FirstOrDefaultAsync(x => x.UserName.Equals(User.Identity.Name, StringComparison.InvariantCultureIgnoreCase)); if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser) { obj.Approved = true; return(Success()); } if (obj.RequestType == RequestType.Movie && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie)) { obj.Approved = true; } if (obj.RequestType == RequestType.TvShow && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv)) { obj.Approved = true; } if (obj.RequestType == RequestType.Album && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic)) { obj.Approved = true; } return(Success()); // We don't really care, we just don't set the obj to approve }