{"action":"created","comment":{"url":"https://api.github.com/repos/nus-ncl/service-web/pulls/comments/92553667","pull_request_review_id":13070812,"id":92553667,"diff_hunk":"@@ -2560,12 +2568,130 @@ public String rejectTeam(\n         return \"redirect:/admin\";\n     }\n \n+    @RequestMapping(\"/admin/teams/{teamId}\")\n+    public String setupTeamRestriction(\n+            @PathVariable final String teamId,\n+            @RequestParam(value = \"action\", required=true) final String action,\n+            final RedirectAttributes redirectAttributes,\n+            HttpSession session) throws IOException\n+    {\n+        final String logMessage = \"Updating restriction settings for team {}: {}\";\n+\n+        // check if admin\n+        if (!validateIfAdmin(session)) {\n+            log.warn(logMessage, teamId, PERMISSION_DENIED);\n+            return NO_PERMISSION_PAGE;\n+        }\n+\n+        Team2 team = invokeAndExtractTeamInfo(teamId);\n+\n+        // check if team is approved before restricted\n+        if (\"restrict\".equals(action) && team.getStatus().equals(TeamStatus.APPROVED.name())) {\n+            return restrictTeam(team, redirectAttributes);\n+        }\n+        // check if team is restricted before freeing it back to approved\n+        else if (\"free\".equals(action) && team.getStatus().equals(TeamStatus.RESTRICTED.name())) {\n+            return freeTeam(team, redirectAttributes);\n+        } else {\n+            log.warn(logMessage, teamId, \"Cannot \" + action + \" team with status \" + team.getStatus());\n+            redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + \"Cannot \" + action + \" team \" + team.getName() + \" with status \" + team.getStatus());\n+            return \"redirect:/admin\";\n+        }\n+    }\n+\n+    private String restrictTeam(final Team2 team, RedirectAttributes redirectAttributes) throws IOException {\n+        log.info(\"Restricting team {}\", team.getId());\n+\n+        HttpEntity<String> request = createHttpEntityHeaderOnly();\n+        ResponseEntity response = restTemplate.exchange(\n+                properties.getSioTeamsStatusUrl(team.getId(), TeamStatus.RESTRICTED),\n+                HttpMethod.PUT, request, String.class);\n+        String responseBody = response.getBody().toString();\n+\n+        if (RestUtil.isError(response.getStatusCode())) {\n+            MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);\n+            ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());\n+            String logMessage = \"Failed to restrict team {}: {}\";\n+            switch (exceptionState) {\n+                case TEAM_NOT_FOUND_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), TEAM_NOT_FOUND);\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + TEAM_NOT_FOUND);\n+                    break;\n+                case INVALID_STATUS_TRANSITION_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), error.getMessage());\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + error.getMessage());\n+                    break;\n+                case INVALID_TEAM_STATUS_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), error.getMessage());\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + error.getMessage());\n+                    break;\n+                case FORBIDDEN_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), PERMISSION_DENIED);\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + PERMISSION_DENIED);\n+                    break;\n+                default:\n+                    log.warn(logMessage, team.getId(), exceptionState.getExceptionName());\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);\n+            }\n+            return \"redirect:/admin\";\n+        } else {\n+            // good\n+            log.info(\"Team {} has been restricted\", team.getId());\n+            redirectAttributes.addFlashAttribute(MESSAGE_SUCCESS, \"Team \" + team.getName() + \" status has been changed to \" + TeamStatus.RESTRICTED.name());\n+            return \"redirect:/admin\";\n+        }\n+    }\n+\n+    private String freeTeam(final Team2 team, RedirectAttributes redirectAttributes) throws IOException {\n+        log.info(\"Freeing team {}\", team.getId());\n+\n+        HttpEntity<String> request = createHttpEntityHeaderOnly();\n+        ResponseEntity response = restTemplate.exchange(\n+                properties.getSioTeamsStatusUrl(team.getId(), TeamStatus.APPROVED),\n+                HttpMethod.PUT, request, String.class);\n+        String responseBody = response.getBody().toString();\n+\n+        if (RestUtil.isError(response.getStatusCode())) {\n+            MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);\n+            ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());\n+            String logMessage = \"Failed to free team {}: {}\";\n+            switch (exceptionState) {\n+                case TEAM_NOT_FOUND_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), TEAM_NOT_FOUND);\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + TEAM_NOT_FOUND);\n+                    break;\n+                case INVALID_STATUS_TRANSITION_EXCEPTION:\n+                    log.warn(logMessage, team.getId(), error.getMessage());\n+                    redirectAttributes.addFlashAttribute(MESSAGE, ERROR_PREFIX + error.getMessage());\n+                    break;\n+                case INVALID_TEAM_STATUS_EXCEPTION:","path":"src/main/java/sg/ncl/MainController.java","position":153,"original_position":196,"commit_id":"397cf726d67a0d8150c8b3a5ccd25d3f0fdffa4e","original_commit_id":"397cf726d67a0d8150c8b3a5ccd25d3f0fdffa4e","user":{"login":"ChrisZhong","id":1946052,"avatar_url":"https://avatars.githubusercontent.com/u/1946052?v=3","gravatar_id":"","url":"https://api.github.com/users/ChrisZhong","html_url":"https://github.com/ChrisZhong","followers_url":"https://api.github.com/users/ChrisZhong/followers","following_url":"https://api.github.com/users/ChrisZhong/following{/other_user}","gists_url":"https://api.github.com/users/ChrisZhong/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisZhong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisZhong/subscriptions","organizations_url":"https://api.github.com/users/ChrisZhong/orgs","repos_url":"https://api.github.com/users/ChrisZhong/repos","events_url":"https://api.github.com/users/ChrisZhong/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisZhong/received_events","type":"User","site_admin":false},"body":"![MINOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-minor.png) This case's code block is the same as the block for the case on line 2663. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://sonarqube.com/coding_rules#rule_key=squid%3AS1871)\n","created_at":"2016-12-15T06:58:50Z","updated_at":"2016-12-15T06:58:50Z","html_url":"https://github.com/nus-ncl/service-web/pull/153#discussion_r92553667","pull_request_url":"https://api.github.com/repos/nus-ncl/service-web/pulls/153","_links":{"self":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/comments/92553667"},"html":{"href":"https://github.com/nus-ncl/service-web/pull/153#discussion_r92553667"},"pull_request":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/153"}}},"pull_request":{"url":"https://api.github.com/repos/nus-ncl/service-web/pulls/153","id":97882805,"html_url":"https://github.com/nus-ncl/service-web/pull/153","diff_url":"https://github.com/nus-ncl/service-web/pull/153.diff","patch_url":"https://github.com/nus-ncl/service-web/pull/153.patch","issue_url":"https://api.github.com/repos/nus-ncl/service-web/issues/153","number":153,"state":"open","locked":false,"title":"DEV-854 implement suspend team on web-service","user":{"login":"teye","id":6906654,"avatar_url":"https://avatars.githubusercontent.com/u/6906654?v=3","gravatar_id":"","url":"https://api.github.com/users/teye","html_url":"https://github.com/teye","followers_url":"https://api.github.com/users/teye/followers","following_url":"https://api.github.com/users/teye/following{/other_user}","gists_url":"https://api.github.com/users/teye/gists{/gist_id}","starred_url":"https://api.github.com/users/teye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teye/subscriptions","organizations_url":"https://api.github.com/users/teye/orgs","repos_url":"https://api.github.com/users/teye/repos","events_url":"https://api.github.com/users/teye/events{/privacy}","received_events_url":"https://api.github.com/users/teye/received_events","type":"User","site_admin":false},"body":null,"created_at":"2016-12-14T03:50:52Z","updated_at":"2016-12-15T06:58:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e46967a9e14d1e8df539ccdfc5441cf38ba43b7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nus-ncl/service-web/pulls/153/commits","review_comments_url":"https://api.github.com/repos/nus-ncl/service-web/pulls/153/comments","review_comment_url":"https://api.github.com/repos/nus-ncl/service-web/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nus-ncl/service-web/issues/153/comments","statuses_url":"https://api.github.com/repos/nus-ncl/service-web/statuses/397cf726d67a0d8150c8b3a5ccd25d3f0fdffa4e","head":{"label":"nus-ncl:DEV-854","ref":"DEV-854","sha":"397cf726d67a0d8150c8b3a5ccd25d3f0fdffa4e","user":{"login":"nus-ncl","id":15359055,"avatar_url":"https://avatars.githubusercontent.com/u/15359055?v=3","gravatar_id":"","url":"https://api.github.com/users/nus-ncl","html_url":"https://github.com/nus-ncl","followers_url":"https://api.github.com/users/nus-ncl/followers","following_url":"https://api.github.com/users/nus-ncl/following{/other_user}","gists_url":"https://api.github.com/users/nus-ncl/gists{/gist_id}","starred_url":"https://api.github.com/users/nus-ncl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nus-ncl/subscriptions","organizations_url":"https://api.github.com/users/nus-ncl/orgs","repos_url":"https://api.github.com/users/nus-ncl/repos","events_url":"https://api.github.com/users/nus-ncl/events{/privacy}","received_events_url":"https://api.github.com/users/nus-ncl/received_events","type":"Organization","site_admin":false},"repo":{"id":54450246,"name":"service-web","full_name":"nus-ncl/service-web","owner":{"login":"nus-ncl","id":15359055,"avatar_url":"https://avatars.githubusercontent.com/u/15359055?v=3","gravatar_id":"","url":"https://api.github.com/users/nus-ncl","html_url":"https://github.com/nus-ncl","followers_url":"https://api.github.com/users/nus-ncl/followers","following_url":"https://api.github.com/users/nus-ncl/following{/other_user}","gists_url":"https://api.github.com/users/nus-ncl/gists{/gist_id}","starred_url":"https://api.github.com/users/nus-ncl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nus-ncl/subscriptions","organizations_url":"https://api.github.com/users/nus-ncl/orgs","repos_url":"https://api.github.com/users/nus-ncl/repos","events_url":"https://api.github.com/users/nus-ncl/events{/privacy}","received_events_url":"https://api.github.com/users/nus-ncl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nus-ncl/service-web","description":"Development of official NCL UI","fork":false,"url":"https://api.github.com/repos/nus-ncl/service-web","forks_url":"https://api.github.com/repos/nus-ncl/service-web/forks","keys_url":"https://api.github.com/repos/nus-ncl/service-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nus-ncl/service-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nus-ncl/service-web/teams","hooks_url":"https://api.github.com/repos/nus-ncl/service-web/hooks","issue_events_url":"https://api.github.com/repos/nus-ncl/service-web/issues/events{/number}","events_url":"https://api.github.com/repos/nus-ncl/service-web/events","assignees_url":"https://api.github.com/repos/nus-ncl/service-web/assignees{/user}","branches_url":"https://api.github.com/repos/nus-ncl/service-web/branches{/branch}","tags_url":"https://api.github.com/repos/nus-ncl/service-web/tags","blobs_url":"https://api.github.com/repos/nus-ncl/service-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nus-ncl/service-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nus-ncl/service-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/nus-ncl/service-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nus-ncl/service-web/statuses/{sha}","languages_url":"https://api.github.com/repos/nus-ncl/service-web/languages","stargazers_url":"https://api.github.com/repos/nus-ncl/service-web/stargazers","contributors_url":"https://api.github.com/repos/nus-ncl/service-web/contributors","subscribers_url":"https://api.github.com/repos/nus-ncl/service-web/subscribers","subscription_url":"https://api.github.com/repos/nus-ncl/service-web/subscription","commits_url":"https://api.github.com/repos/nus-ncl/service-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/nus-ncl/service-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/nus-ncl/service-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/nus-ncl/service-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/nus-ncl/service-web/contents/{+path}","compare_url":"https://api.github.com/repos/nus-ncl/service-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nus-ncl/service-web/merges","archive_url":"https://api.github.com/repos/nus-ncl/service-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nus-ncl/service-web/downloads","issues_url":"https://api.github.com/repos/nus-ncl/service-web/issues{/number}","pulls_url":"https://api.github.com/repos/nus-ncl/service-web/pulls{/number}","milestones_url":"https://api.github.com/repos/nus-ncl/service-web/milestones{/number}","notifications_url":"https://api.github.com/repos/nus-ncl/service-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nus-ncl/service-web/labels{/name}","releases_url":"https://api.github.com/repos/nus-ncl/service-web/releases{/id}","deployments_url":"https://api.github.com/repos/nus-ncl/service-web/deployments","created_at":"2016-03-22T06:15:58Z","updated_at":"2016-10-24T07:12:44Z","pushed_at":"2016-12-15T06:56:41Z","git_url":"git://github.com/nus-ncl/service-web.git","ssh_url":"git@github.com:nus-ncl/service-web.git","clone_url":"https://github.com/nus-ncl/service-web.git","svn_url":"https://github.com/nus-ncl/service-web","homepage":null,"size":31051,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"nus-ncl:master","ref":"master","sha":"ac6ce4c33612bb52f7d55730bd5619a76c7677c0","user":{"login":"nus-ncl","id":15359055,"avatar_url":"https://avatars.githubusercontent.com/u/15359055?v=3","gravatar_id":"","url":"https://api.github.com/users/nus-ncl","html_url":"https://github.com/nus-ncl","followers_url":"https://api.github.com/users/nus-ncl/followers","following_url":"https://api.github.com/users/nus-ncl/following{/other_user}","gists_url":"https://api.github.com/users/nus-ncl/gists{/gist_id}","starred_url":"https://api.github.com/users/nus-ncl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nus-ncl/subscriptions","organizations_url":"https://api.github.com/users/nus-ncl/orgs","repos_url":"https://api.github.com/users/nus-ncl/repos","events_url":"https://api.github.com/users/nus-ncl/events{/privacy}","received_events_url":"https://api.github.com/users/nus-ncl/received_events","type":"Organization","site_admin":false},"repo":{"id":54450246,"name":"service-web","full_name":"nus-ncl/service-web","owner":{"login":"nus-ncl","id":15359055,"avatar_url":"https://avatars.githubusercontent.com/u/15359055?v=3","gravatar_id":"","url":"https://api.github.com/users/nus-ncl","html_url":"https://github.com/nus-ncl","followers_url":"https://api.github.com/users/nus-ncl/followers","following_url":"https://api.github.com/users/nus-ncl/following{/other_user}","gists_url":"https://api.github.com/users/nus-ncl/gists{/gist_id}","starred_url":"https://api.github.com/users/nus-ncl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nus-ncl/subscriptions","organizations_url":"https://api.github.com/users/nus-ncl/orgs","repos_url":"https://api.github.com/users/nus-ncl/repos","events_url":"https://api.github.com/users/nus-ncl/events{/privacy}","received_events_url":"https://api.github.com/users/nus-ncl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nus-ncl/service-web","description":"Development of official NCL UI","fork":false,"url":"https://api.github.com/repos/nus-ncl/service-web","forks_url":"https://api.github.com/repos/nus-ncl/service-web/forks","keys_url":"https://api.github.com/repos/nus-ncl/service-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nus-ncl/service-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nus-ncl/service-web/teams","hooks_url":"https://api.github.com/repos/nus-ncl/service-web/hooks","issue_events_url":"https://api.github.com/repos/nus-ncl/service-web/issues/events{/number}","events_url":"https://api.github.com/repos/nus-ncl/service-web/events","assignees_url":"https://api.github.com/repos/nus-ncl/service-web/assignees{/user}","branches_url":"https://api.github.com/repos/nus-ncl/service-web/branches{/branch}","tags_url":"https://api.github.com/repos/nus-ncl/service-web/tags","blobs_url":"https://api.github.com/repos/nus-ncl/service-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nus-ncl/service-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nus-ncl/service-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/nus-ncl/service-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nus-ncl/service-web/statuses/{sha}","languages_url":"https://api.github.com/repos/nus-ncl/service-web/languages","stargazers_url":"https://api.github.com/repos/nus-ncl/service-web/stargazers","contributors_url":"https://api.github.com/repos/nus-ncl/service-web/contributors","subscribers_url":"https://api.github.com/repos/nus-ncl/service-web/subscribers","subscription_url":"https://api.github.com/repos/nus-ncl/service-web/subscription","commits_url":"https://api.github.com/repos/nus-ncl/service-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/nus-ncl/service-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/nus-ncl/service-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/nus-ncl/service-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/nus-ncl/service-web/contents/{+path}","compare_url":"https://api.github.com/repos/nus-ncl/service-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nus-ncl/service-web/merges","archive_url":"https://api.github.com/repos/nus-ncl/service-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nus-ncl/service-web/downloads","issues_url":"https://api.github.com/repos/nus-ncl/service-web/issues{/number}","pulls_url":"https://api.github.com/repos/nus-ncl/service-web/pulls{/number}","milestones_url":"https://api.github.com/repos/nus-ncl/service-web/milestones{/number}","notifications_url":"https://api.github.com/repos/nus-ncl/service-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nus-ncl/service-web/labels{/name}","releases_url":"https://api.github.com/repos/nus-ncl/service-web/releases{/id}","deployments_url":"https://api.github.com/repos/nus-ncl/service-web/deployments","created_at":"2016-03-22T06:15:58Z","updated_at":"2016-10-24T07:12:44Z","pushed_at":"2016-12-15T06:56:41Z","git_url":"git://github.com/nus-ncl/service-web.git","ssh_url":"git@github.com:nus-ncl/service-web.git","clone_url":"https://github.com/nus-ncl/service-web.git","svn_url":"https://github.com/nus-ncl/service-web","homepage":null,"size":31051,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/153"},"html":{"href":"https://github.com/nus-ncl/service-web/pull/153"},"issue":{"href":"https://api.github.com/repos/nus-ncl/service-web/issues/153"},"comments":{"href":"https://api.github.com/repos/nus-ncl/service-web/issues/153/comments"},"review_comments":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/153/comments"},"review_comment":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nus-ncl/service-web/pulls/153/commits"},"statuses":{"href":"https://api.github.com/repos/nus-ncl/service-web/statuses/397cf726d67a0d8150c8b3a5ccd25d3f0fdffa4e"}}}}
{"actor":{"display_login":"ChrisZhong"}}