コード例 #1
0
        public void TestCreateProject()
        {
            var project     = RandomProject();
            var projectUser = new ProjectWithUser(project);
            var id          = ((_controller.Post(projectUser).Result as ObjectResult).Value as ProjectWithUser).Id as string;

            project.Id = id;
            Assert.Contains(project, _projectService.GetAllProjects().Result);
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] Project project)
        {
            await _projectService.Create(project);

            // Get user
            var currentUserId = _permissionService.GetUserId(HttpContext);
            var currentUser   = await _userService.GetUser(currentUserId);

            // Give Project admin privileges to user who creates a Project
            var userRole = new UserRole
            {
                Permissions = new List <int>
                {
                    (int)Permission.DeleteEditSettingsAndUsers,
                    (int)Permission.ImportExport,
                    (int)Permission.MergeAndCharSet,
                    (int)Permission.Unused,
                    (int)Permission.WordEntry
                },
                ProjectId = project.Id
            };

            userRole = await _userRoleService.Create(userRole);

            // Update user with userRole
            if (currentUser.ProjectRoles.Equals(null))
            {
                currentUser.ProjectRoles = new Dictionary <string, string>();
            }

            // Generate the userRoles and update the user
            currentUser.ProjectRoles.Add(project.Id, userRole.Id);
            await _userService.Update(currentUserId, currentUser);

            // Generate the JWT based on those new userRoles
            currentUser = await _userService.MakeJwt(currentUser);

            await _userService.Update(currentUserId, currentUser);

            var output = new ProjectWithUser(project)
            {
                UpdatedUser = currentUser
            };

            return(new OkObjectResult(output));
        }