Exemple #1
0
        protected override async Task <SFProjectUserEntity> InsertEntityAsync(SFProjectUserEntity entity)
        {
            UserEntity user = await _users.GetAsync(UserId);

            if (SystemRole == SystemRoles.User || entity.Role == null)
            {
                // get role from Paratext project
                string paratextId = await Projects.Query().Where(p => p.Id == entity.ProjectRef)
                                    .Select(p => p.ParatextId).SingleOrDefaultAsync();

                if (paratextId == null)
                {
                    throw new JsonApiException(StatusCodes.Status400BadRequest,
                                               "The specified project could not be found.");
                }
                Attempt <string> attempt = await _paratextService.TryGetProjectRoleAsync(user, paratextId);

                if (attempt.TryResult(out string role))
                {
                    entity.Role = role;
                }
                else
                {
                    entity.Role = SFProjectRoles.SFReviewer;
                }
            }

            return(await base.InsertEntityAsync(entity));
        }
Exemple #2
0
        protected override async Task <string> AddUserToProject(SFProjectEntity project)
        {
            string projectUserId = await base.AddUserToProject(project);

            if (projectUserId == null)
            {
                return(null);
            }

            // check if the user is a Paratext user
            // if so, set the user's project role from the Paratext project
            UserEntity user = await Users.GetAsync(User.UserId);

            if (user.ParatextId != null)
            {
                Attempt <string> attempt = await _paratextService.TryGetProjectRoleAsync(user, project.ParatextId);

                if (attempt.TryResult(out string role))
                {
                    await Projects.UpdateAsync(p => p.Users.Any(pu => pu.Id == projectUserId),
                                               update => update.Set(p => p.Users[ArrayPosition.FirstMatching].Role, role));
                }
            }
            return(projectUserId);
        }