コード例 #1
0
        public JsonResult PreferenceLayout(PreferenceRequest request)
        {
            var checkResult = CheckUsername(request.username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(request.preferenceLayout, 50, CornerCaseCheckHelper.Title))
            {
                return(JsonReturnHelper.ErrorReturn(111, "Invalid preferenceLayout"));
            }

            var user = _meshContext.Users.First(u => u.Email == request.username);

            try
            {
                user.LayoutPreference = request.preferenceLayout;
                _meshContext.Users.Update(user);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #2
0
        public JsonResult DeleteTeamKB(string username, int teamId, int knowledgeId)
        {
            var checkResult = CheckUsername(username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(teamId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(301, "Invalid teamId."));
            }

            if (!CornerCaseCheckHelper.Check(knowledgeId, 50, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(807, "Invalid knowledgeId."));
            }

            var team = _meshContext.Teams.FirstOrDefault(p => p.Id == teamId);

            if (team == null)
            {
                return(JsonReturnHelper.ErrorReturn(302, "Team does not exist."));
            }

            var memoCollection = _meshContext.TeamMemoCollections.First(p => p.TeamId == teamId);
            var knowledge      =
                _meshContext.TeamMemos.FirstOrDefault(
                    m => m.Id == knowledgeId && m.CollectionId == memoCollection.Id);

            if (knowledge == null)
            {
                return(JsonReturnHelper.ErrorReturn(805, "Invalid knowledgeId."));
            }

            var user = _meshContext.Users.First(u => u.Email == username);

            if (_permissionCheck.CheckTeamPermission(username, team) != PermissionCheckHelper.TeamAdmin ||
                knowledge.UserId != user.Id)
            {
                return(JsonReturnHelper.ErrorReturn(801, "Permission denied."));
            }

            try
            {
                _meshContext.TeamMemos.Remove(knowledge);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #3
0
        public JsonResult DeleteTask(string username, int projectId, int taskId)
        {
            var checkResult = CheckUsername(username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(projectId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(701, "Invalid projectId."));
            }

            if (!CornerCaseCheckHelper.Check(taskId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(501, "Invalid taskId."));
            }


            var user = _meshContext.Users.First(u => u.Email == username);

            var project = _meshContext.Projects.FirstOrDefault(p => p.Id == projectId);

            if (project == null)
            {
                return(JsonReturnHelper.ErrorReturn(707, "Project does not exist."));
            }

            var task = _meshContext.Tasks.FirstOrDefault(t => t.Id == taskId);

            if (task == null)
            {
                return(JsonReturnHelper.ErrorReturn(604, "Task does not exist."));
            }

            if (_permissionCheck.CheckProjectPermission(username, project) != PermissionCheckHelper.ProjectAdmin &&
                task.LeaderId != user.Id)
            {
                return(JsonReturnHelper.ErrorReturn(701, "Permission denied."));
            }

            try
            {
                _meshContext.Tasks.Remove(task);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #4
0
        public JsonResult DeleteBulletin(string username, int projectId, int bulletinId)
        {
            var checkResult = CheckUsername(username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(bulletinId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(401, "Invalid bulletinId."));
            }


            if (!CornerCaseCheckHelper.Check(projectId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(401, "Invalid projectId."));
            }

            //Check if target bulletin exists
            var user    = _meshContext.Users.First(u => u.Email == username);
            var project = _meshContext.Projects.Find(projectId);

            if (project == null)
            {
                return(JsonReturnHelper.ErrorReturn(420, "Project does not exist."));
            }
            var bulletin = _meshContext.Bulletins.Find(bulletinId);

            if (bulletin == null)
            {
                return(JsonReturnHelper.ErrorReturn(401, "Bulletin does not exist."));
            }

            if (project.AdminId != user.Id)
            {
                return(JsonReturnHelper.ErrorReturn(422, "Permission denied."));
            }

            try
            {
                _meshContext.Bulletins.Remove(bulletin);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #5
0
        public JsonResult UpdateUserPassword(UserRequest request)
        {
            if (!CornerCaseCheckHelper.Check(request.username, 50, CornerCaseCheckHelper.Username))
            {
                return(JsonReturnHelper.ErrorReturn(104, "Invalid username"));
            }

            if (!CornerCaseCheckHelper.Check(request.oldPassword, 0, CornerCaseCheckHelper.PassWord))
            {
                return(JsonReturnHelper.ErrorReturn(112, "Invalid oldPassword."));
            }

            if (!CornerCaseCheckHelper.Check(request.password, 0, CornerCaseCheckHelper.PassWord))
            {
                return(JsonReturnHelper.ErrorReturn(111, "Invalid password."));
            }

            if (request.password == request.oldPassword)
            {
                return(JsonReturnHelper.ErrorReturn(113, "The old and new passwords are the same."));
            }

            var user = _meshContext.Users.FirstOrDefault(u => u.Email == request.username);

            //Check Password
            if (user == null || !CheckHashPassword(request.oldPassword, user.PasswordSalt, user.PasswordDigest))
            {
                return(JsonReturnHelper.ErrorReturn(201, "Incorrect username or password."));
            }
            HashPassword hashPassword = GetHashPassword(request.password);

            try
            {
                user.PasswordDigest = hashPassword.PasswordDigest;
                user.PasswordSalt   = hashPassword.PasswordSalt;
                _meshContext.Users.Update(user);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #6
0
        public JsonResult InviteNewTeamMember(InviteRequest request)
        {
            var checkUsernameResult = CheckUsername(request.username);

            if (checkUsernameResult != null)
            {
                return(checkUsernameResult);
            }

            if (!CornerCaseCheckHelper.Check(request.inviteName, 50, CornerCaseCheckHelper.Username))
            {
                return(JsonReturnHelper.ErrorReturn(108, "Invalid inviteName"));
            }

            if (!CornerCaseCheckHelper.Check(request.teamId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(301, "Invalid teamId"));
            }

            var team = _meshContext.Teams.FirstOrDefault(t => t.Id == request.teamId);

            if (team == null)
            {
                return(JsonReturnHelper.ErrorReturn(302, "Team not exist."));
            }

            if (_permissionCheck.CheckTeamPermission(request.username, team) != PermissionCheckHelper.TeamAdmin)
            {
                return(JsonReturnHelper.ErrorReturn(305, "Permission denied."));
            }

            var inviteUser = _meshContext.Users.FirstOrDefault(u => u.Email == request.inviteName);

            if (inviteUser == null)
            {
                return(JsonReturnHelper.ErrorReturn(108, "Username or inviteName not exists."));
            }

            if (_permissionCheck.CheckTeamPermission(request.inviteName, team) != PermissionCheckHelper.TeamOutsider)
            {
                return(JsonReturnHelper.ErrorReturn(306, "User already in team."));
            }

            var cooperation = new Cooperation()
            {
                TeamId = request.teamId,
                UserId = inviteUser.Id
            };

            try
            {
                _meshContext.Cooperations.Add(cooperation);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #7
0
        public JsonResult DeleteNotification(string username, int type, int id)
        {
            var checkResult = CheckUsername(username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(id, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(910, "Invalid Id"));
            }
            var user = _meshContext.Users.First(u => u.Email == username);

            switch (type)
            {
            case BULLETIN:
            {
                var bulletin =
                    _meshContext.BulletinFeeds.FirstOrDefault(f => f.BulletinId == id && f.UserId == user.Id);
                if (bulletin == null)
                {
                    return(JsonReturnHelper.ErrorReturn(901, "Invalid bulletinId"));
                }

                try
                {
                    _meshContext.BulletinFeeds.Remove(bulletin);
                    _meshContext.SaveChanges();
                }
                catch (Exception e)
                {
                    _logger.LogError(e.ToString());
                    return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
                }

                return(JsonReturnHelper.SuccessReturn());
            }

            case TASK:
            {
                var task = _meshContext.TaskFeeds.FirstOrDefault(f => f.TaskId == id && f.UserId == user.Id);
                if (task == null)
                {
                    return(JsonReturnHelper.ErrorReturn(902, "Invalid TaskId"));
                }

                try
                {
                    _meshContext.TaskFeeds.Remove(task);
                    _meshContext.SaveChanges();
                }
                catch (Exception e)
                {
                    _logger.LogError(e.ToString());
                    return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
                }

                return(JsonReturnHelper.SuccessReturn());
            }

            default:
                return(JsonReturnHelper.ErrorReturn(900, "Invalid type."));
            }
        }
コード例 #8
0
        public JsonResult InviteNewProjectMember(ProjectRequest request)
        {
            var checkResult = CheckUsername(request.Username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(request.TeamId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(301, "Invalid teamId."));
            }

            if (!CornerCaseCheckHelper.Check(request.ProjectId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(701, "Invalid projectId."));
            }

            if (!CornerCaseCheckHelper.Check(request.InviteName, 50, CornerCaseCheckHelper.Username))
            {
                return(JsonReturnHelper.ErrorReturn(101, "Invalid inviteName"));
            }

            //Check if inviteUser exists
            var inviteUser = _meshContext.Users.FirstOrDefault(a => a.Email == request.InviteName);

            if (inviteUser == null)
            {
                return(JsonReturnHelper.ErrorReturn(704, "Admin does not exist."));
            }

            //Check if team exists
            var team = _meshContext.Teams.FirstOrDefault(t => t.Id == request.TeamId);

            if (team == null)
            {
                return(JsonReturnHelper.ErrorReturn(302, "Team does not exist."));
            }

            //Check if user in the team
            var teamUserCheckResult = _permissionCheck.CheckTeamPermission(request.Username, team);

            if (teamUserCheckResult == PermissionCheckHelper.TeamOutsider)
            {
                return(JsonReturnHelper.ErrorReturn(801, "Permission denied"));
            }

            //Check if inviteUser in the team
            var teamCheckResult = _permissionCheck.CheckTeamPermission(request.InviteName, team);

            if (teamCheckResult == PermissionCheckHelper.TeamOutsider)
            {
                return(JsonReturnHelper.ErrorReturn(801, "InviteUser is not in the team"));
            }

            //Check if project exists
            var project = _meshContext.Projects.FirstOrDefault(p => p.Id == request.ProjectId);

            if (project == null)
            {
                return(JsonReturnHelper.ErrorReturn(707, "Project does not exist."));
            }

            //Check if user is the admin of the project
            var projectCheckResult = _permissionCheck.CheckProjectPermission(request.Username, project);

            if (projectCheckResult != PermissionCheckHelper.ProjectAdmin)
            {
                return(JsonReturnHelper.ErrorReturn(701, "Permission denied."));
            }

            try
            {
                _meshContext.Develops.Add(new Develop()
                {
                    UserId    = inviteUser.Id,
                    ProjectId = project.Id
                });
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #9
0
        public JsonResult DeleteProject(string username, int teamId, int projectId)
        {
            var checkResult = CheckUsername(username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(teamId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(301, "Invalid teamId."));
            }

            if (!CornerCaseCheckHelper.Check(projectId, 0, CornerCaseCheckHelper.Id))
            {
                return(JsonReturnHelper.ErrorReturn(701, "Invalid projectId."));
            }


            //Check if team exists
            var team = _meshContext.Teams.FirstOrDefault(t => t.Id == teamId);

            if (team == null)
            {
                return(JsonReturnHelper.ErrorReturn(302, "Invalid teamId."));
            }

            //Check if project exists
            var project = _meshContext.Projects.FirstOrDefault(p => p.Id == projectId);

            if (project == null)
            {
                return(JsonReturnHelper.ErrorReturn(707, "Invalid projectId."));
            }

            //Check if user in the team
            var teamCheckResult = _permissionCheck.CheckTeamPermission(username, team);

            if (teamCheckResult == PermissionCheckHelper.TeamOutsider)
            {
                return(JsonReturnHelper.ErrorReturn(702, "Invalid username."));
            }

            //Check if user is the admin of the project
            var projectCheckResult = _permissionCheck.CheckProjectPermission(username, project);

            if (projectCheckResult != PermissionCheckHelper.ProjectAdmin)
            {
                return(JsonReturnHelper.ErrorReturn(701, "Permission denied."));
            }

            //Remove the project
            try
            {
                _meshContext.Projects.Remove(project);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }