예제 #1
0
        public async Task <bool> HasPermissionToEditParticipantAsync(int id, int invitationId, CancellationToken cancellationToken)
        {
            if (await InvitationHelper.HasIpoAdminPrivilege(_permissionCache, _plantProvider, _currentUserProvider))
            {
                return(true);
            }

            var invitation = await(from i in _context.QuerySet <Invitation>()
                                   where i.Id == invitationId
                                   select i).SingleAsync(cancellationToken);

            switch (invitation.Status)
            {
            case IpoStatus.Planned when await CurrentUserIsValidCompleterParticipantAsync(invitationId, cancellationToken):
            case IpoStatus.Completed when await CurrentUserIsValidAccepterParticipantAsync(invitationId, cancellationToken):
                return(true);
            }

            var participant = await(from p in _context.QuerySet <Participant>()
                                    where EF.Property <int>(p, "InvitationId") == invitationId &&
                                    p.Id == id
                                    select p).SingleAsync(cancellationToken);

            if (participant.SignedAtUtc != null)
            {
                return(false);
            }

            if (participant.FunctionalRoleCode == null &&
                participant.AzureOid == _currentUserProvider.GetCurrentUserOid())
            {
                return(true);
            }

            var person = await _personApiService.GetPersonInFunctionalRoleAsync(
                _plantProvider.Plant,
                _currentUserProvider.GetCurrentUserOid().ToString(),
                participant.FunctionalRoleCode);

            return(person != null);
        }
        private async Task UpdateAsPersonInFunctionalRoleAsync(
            Invitation invitation,
            string functionalRoleCode,
            IEnumerable <UpdateAttendedStatusAndNoteOnParticipantForCommand> participants)
        {
            var person = await _personApiService.GetPersonInFunctionalRoleAsync(
                _plantProvider.Plant,
                _currentUserProvider.GetCurrentUserOid().ToString(),
                functionalRoleCode);

            if (person != null)
            {
                UpdateParticipantStatusesAndNotes(invitation, participants);
            }
            else
            {
                throw new IpoValidationException($"Person was not found in functional role with code '{functionalRoleCode}'");
            }
        }