public async Task RemoveAsync(int triggerId) { VerifyManagementPermission(); if (await _triggerRepository.HasDependentsAsync(triggerId)) { throw new GraException("Trigger has dependents"); } var trigger = await _triggerRepository.GetByIdAsync(triggerId); trigger.IsDeleted = true; trigger.SecretCode = null; trigger.BadgeIds = new List <int>(); trigger.ChallengeIds = new List <int>(); await _triggerRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId), trigger); var requireSecretCode = await _siteLookupService.GetSiteSettingBoolAsync( GetCurrentSiteId(), SiteSettingKey.Events.RequireBadge); if (requireSecretCode == false) { await _eventRepository.DetachRelatedTrigger(triggerId); } }
public async Task RemoveAsync(int triggerId) { VerifyManagementPermission(); var dependentTriggers = await _triggerRepository.DependentTriggers(triggerId); if (dependentTriggers?.Count > 0) { var ex = new GraException("Trigger has dependencies"); foreach (var dependentTrigger in dependentTriggers) { ex.Data.Add(dependentTrigger.Key, dependentTrigger.Value); } throw ex; } var trigger = await _triggerRepository.GetByIdAsync(triggerId); trigger.IsDeleted = true; trigger.SecretCode = null; trigger.BadgeIds = new List <int>(); trigger.ChallengeIds = new List <int>(); await _triggerRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId), trigger); var requireSecretCode = await _siteLookupService.GetSiteSettingBoolAsync( GetCurrentSiteId(), SiteSettingKey.Events.RequireBadge); if (!requireSecretCode) { await _eventRepository.DetachRelatedTrigger(triggerId); } }
public async Task <string> GetSecretCodeForStreamingEventAsync(int eventId) { if (!await _siteLookupService.GetSiteSettingBoolAsync(GetCurrentSiteId(), SiteSettingKey.Events.StreamingShowCode)) { throw new GraException(Annotations.Validate.Permission); } return(await _eventRepository.GetSecretCodeForStreamingEventAsync(eventId)); }
public async Task <User> Update(User userToUpdate) { int requestingUserId = GetActiveUserId(); if (requestingUserId == userToUpdate.Id) { // users can only update some of their own fields var currentEntity = await _userRepository.GetByIdAsync(userToUpdate.Id); currentEntity.IsAdmin = await UserHasRoles(userToUpdate.Id); currentEntity.Age = userToUpdate.Age; currentEntity.AvatarId = userToUpdate.AvatarId; currentEntity.BranchName = null; currentEntity.CardNumber = userToUpdate.CardNumber?.Trim(); currentEntity.DailyPersonalGoal = userToUpdate.DailyPersonalGoal; currentEntity.Email = userToUpdate.Email?.Trim(); currentEntity.FirstName = userToUpdate.FirstName?.Trim(); currentEntity.IsHomeschooled = userToUpdate.IsHomeschooled; currentEntity.LastName = userToUpdate.LastName?.Trim(); currentEntity.PhoneNumber = userToUpdate.PhoneNumber?.Trim(); currentEntity.PostalCode = userToUpdate.PostalCode?.Trim(); currentEntity.ProgramId = userToUpdate.ProgramId; currentEntity.ProgramName = null; currentEntity.SchoolId = userToUpdate.SchoolId; currentEntity.SchoolNotListed = userToUpdate.SchoolNotListed; currentEntity.SystemName = null; //currentEntity.Username = userToUpdate.Username; bool restrictChangingSystemBranch = await _siteLookupService .GetSiteSettingBoolAsync(currentEntity.SiteId, SiteSettingKey.Users.RestrictChangingSystemBranch); if (!restrictChangingSystemBranch) { currentEntity.SystemId = userToUpdate.SystemId; currentEntity.BranchId = userToUpdate.BranchId; } var askEmailReminder = await _siteLookupService.GetSiteSettingBoolAsync( currentEntity.SiteId, SiteSettingKey.Users.AskPreregistrationReminder); if (askEmailReminder) { var site = await _siteLookupService.GetByIdAsync(currentEntity.SiteId); if (_siteLookupService.GetSiteStage(site) == SiteStage.RegistrationOpen) { currentEntity.PreregistrationReminderRequested = userToUpdate.PreregistrationReminderRequested; } } await ValidateUserFields(currentEntity); var updatedUser = await _userRepository .UpdateSaveAsync(requestingUserId, currentEntity); return(updatedUser); } else { _logger.LogError($"User {requestingUserId} doesn't have permission to update user {userToUpdate.Id}."); throw new GraException("Permission denied."); } }