Skip to content

Commit

Permalink
Merge pull request #1216 from WeBankPartners/master
Browse files Browse the repository at this point in the history
update dev
  • Loading branch information
Roy Wu(伍健君) authored Jan 28, 2021
2 parents 3417545 + 44d9354 commit 7ff9e91
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package com.webank.cmdb.controller.ui;

import static com.webank.cmdb.domain.AdmMenu.MENU_CMDB_ADMIN_BASE_DATA_MANAGEMENT;
import static com.webank.cmdb.domain.AdmMenu.MENU_ADMIN_CMDB_MODEL_MANAGEMENT;
import static com.webank.cmdb.domain.AdmMenu.MENU_ADMIN_PERMISSION_MANAGEMENT;
import static com.webank.cmdb.domain.AdmMenu.MENU_APPLICATION_DEPLOYMENT_DESIGN;
import static com.webank.cmdb.domain.AdmMenu.MENU_DESIGNING_CI_DATA_ENQUIRY;
import static com.webank.cmdb.domain.AdmMenu.MENU_DESIGNING_CI_DATA_MANAGEMENT;
import static com.webank.cmdb.domain.AdmMenu.MENU_DESIGNING_CI_INTEGRATED_QUERY_EXECUTION;

import java.util.List;
import java.util.Map;

Expand All @@ -32,6 +24,8 @@
import com.webank.cmdb.dto.QueryRequest;
import com.webank.cmdb.dto.QueryResponse;

import static com.webank.cmdb.domain.AdmMenu.*;

@RestController
@RequestMapping("/ui/v2")
public class UIEnumManagementController {
Expand Down Expand Up @@ -126,14 +120,30 @@ public void deleteCiTypeLayer(@PathVariable(value = "layer-id") int layerId) {
wrapperService.deleteEnumCodes(layerId);
}

@RolesAllowed({ MENU_ADMIN_CMDB_MODEL_MANAGEMENT, MENU_CMDB_ADMIN_BASE_DATA_MANAGEMENT })
@RolesAllowed({
MENU_ADMIN_CMDB_MODEL_MANAGEMENT,
MENU_CMDB_ADMIN_BASE_DATA_MANAGEMENT,
MENU_IDC_PLANNING_DESIGN,
MENU_IDC_RESOURCE_PLANNING,
MENU_APPLICATION_ARCHITECTURE_DESIGN,
MENU_APPLICATION_ARCHITECTURE_QUERY,
MENU_APPLICATION_DEPLOYMENT_DESIGN
})
@PostMapping("/enum/system/codes")
@ResponseBody
public Object querySystemEnumCodesWithRefResources(@RequestBody QueryRequest queryObject) {
return wrapperService.querySystemEnumCodesWithRefResources(queryObject);
}

@RolesAllowed({ MENU_ADMIN_CMDB_MODEL_MANAGEMENT, MENU_CMDB_ADMIN_BASE_DATA_MANAGEMENT })
@RolesAllowed({
MENU_ADMIN_CMDB_MODEL_MANAGEMENT,
MENU_CMDB_ADMIN_BASE_DATA_MANAGEMENT,
MENU_IDC_PLANNING_DESIGN,
MENU_IDC_RESOURCE_PLANNING,
MENU_APPLICATION_ARCHITECTURE_DESIGN,
MENU_APPLICATION_ARCHITECTURE_QUERY,
MENU_APPLICATION_DEPLOYMENT_DESIGN
})
@PostMapping("/enum/non-system/codes")
@ResponseBody
public Object queryNonSystemEnumCodesWithRefResources(@RequestBody QueryRequest queryObject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.webank.cmdb.controller.ui;

import com.webank.cmdb.controller.AbstractBaseControllerTest;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;

import static com.webank.cmdb.domain.AdmMenu.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class UIEnumManagementControllerTest extends AbstractBaseControllerTest {
private static final String QUERY_SYSTEM_CODE_URL = "/ui/v2/enum/system/codes";
private static final String QUERY_NON_SYSTEM_CODE_URL = "/ui/v2/enum/non-system/codes";

@Test
@WithMockUser(value = "test")
public void querySystemEnum_should_fail_for_user_without_appropriate_menu_permission() throws Exception {
shouldApiCallFailForInsufficientPermission(QUERY_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_IDC_PLANNING_DESIGN })
public void querySystemEnum_should_success_for_role_IDC_PLANNING_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_IDC_RESOURCE_PLANNING })
public void querySystemEnum_should_success_for_role_IDC_RESOURCE_PLANNING() throws Exception {
shouldApiCallSucceedSucceed(QUERY_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_ARCHITECTURE_DESIGN })
public void querySystemEnum_should_success_for_role_APPLICATION_ARCHITECTURE_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_ARCHITECTURE_QUERY })
public void querySystemEnum_should_success_for_role_APPLICATION_ARCHITECTURE_QUERY() throws Exception {
shouldApiCallSucceedSucceed(QUERY_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_DEPLOYMENT_DESIGN })
public void querySystemEnum_should_success_for_role_APPLICATION_DEPLOYMENT_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_SYSTEM_CODE_URL);
}


@Test
@WithMockUser(value = "test")
public void queryNonSystemEnum_should_fail_for_user_without_appropriate_menu_permission() throws Exception {
shouldApiCallFailForInsufficientPermission(QUERY_NON_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_IDC_PLANNING_DESIGN })
public void queryNonSystemEnum_should_success_for_role_IDC_PLANNING_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_NON_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_IDC_RESOURCE_PLANNING })
public void queryNonSystemEnum_should_success_for_role_IDC_RESOURCE_PLANNING() throws Exception {
shouldApiCallSucceedSucceed(QUERY_NON_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_ARCHITECTURE_DESIGN })
public void queryNonSystemEnum_should_success_for_role_APPLICATION_ARCHITECTURE_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_NON_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_ARCHITECTURE_QUERY })
public void queryNonSystemEnum_should_success_for_role_APPLICATION_ARCHITECTURE_QUERY() throws Exception {
shouldApiCallSucceedSucceed(QUERY_NON_SYSTEM_CODE_URL);
}

@Test
@WithMockUser(value = "test", authorities = { ROLE_PREFIX + MENU_APPLICATION_DEPLOYMENT_DESIGN })
public void queryNonSystemEnum_should_success_for_role_APPLICATION_DEPLOYMENT_DESIGN() throws Exception {
shouldApiCallSucceedSucceed(QUERY_NON_SYSTEM_CODE_URL);
}

private void shouldApiCallSucceedSucceed(String url) throws Exception {
mvc.perform(post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8).content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.statusCode", is("OK")))
.andExpect(jsonPath("$.data", notNullValue()))
;
}

private void shouldApiCallFailForInsufficientPermission(String url) throws Exception {
mvc.perform(post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8).content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.statusCode", is("ERROR")))
.andExpect(jsonPath("$.statusMessage", is("Access is denied")))
;
}
}

0 comments on commit 7ff9e91

Please sign in to comment.