Skip to content

Commit

Permalink
[Feature] Added menu && tenant Optimization (#2161)
Browse files Browse the repository at this point in the history
* added menu web

* added menu

* Spotless Apply

* added menu

* added menu

* added menu

* modify user tenant

* Spotless Apply

* menu about

* Spotless Apply

* modify user tenant

* Spotless Apply

* modify user tenant

* menu about

* Spotless Apply

* modify user

* modify user

* Spotless Apply

* Spotless Apply

* added menu

* Spotless Apply

* added update

* modify code

* Spotless Apply

* modify code

* Spotless Apply

* support added menu

* modify code

* modify code

* modify code

* feat: Add menu mapper

* feat: Add role-menu mapper

* modify code

* Spotless Apply

* modify code

* Spotless Apply

* ADDED  I18N

---------

Co-authored-by: zhu-mingye <[email protected]>
Co-authored-by: G-XD <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2023
1 parent 7420707 commit 387ccd0
Show file tree
Hide file tree
Showing 89 changed files with 3,693 additions and 211 deletions.
4 changes: 4 additions & 0 deletions dinky-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-jwt</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
Expand Down
41 changes: 36 additions & 5 deletions dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;

/**
* AppConfiguration
Expand Down Expand Up @@ -72,15 +73,45 @@ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
// 注册Sa-Token的路由拦截器

registry.addInterceptor(new SaInterceptor())
// registry.addInterceptor(new SaInterceptor(handle -> {
// // 根据路由划分模块,不同模块不同鉴权
// SaRouter.match("/api/alertGroup/**", r ->
// StpUtil.checkPermission("alertGroup"));
// SaRouter.match("/api/alertHistory/**", r ->
// StpUtil.checkPermission("alertHistory"));
// SaRouter.match("/api/alertInstance/**", r ->
// StpUtil.checkPermission("alertInstance"));
// SaRouter.match("/api/catalogue/**", r ->
// StpUtil.checkPermission("catalogue"));
// SaRouter.match("/api/clusterConfiguration/**", r ->
// StpUtil.checkPermission("clusterConfiguration"));
// SaRouter.match("/api/cluster/**", r ->
// StpUtil.checkPermission("clusterInstance"));
// SaRouter.match("/api/database/**", r ->
// StpUtil.checkPermission("database"));
// SaRouter.match("/api/document/**", r ->
// StpUtil.checkPermission("document"));
// SaRouter.match("/api/fragment/**", r ->
// StpUtil.checkPermission("fragment"));
// SaRouter.match("/api/git/**", r -> StpUtil.checkPermission("git"));
// SaRouter.match("/api/history/**", r ->
// StpUtil.checkPermission("history"));
//
// }))
// .addPathPatterns("/api/**")
// .excludePathPatterns("/api/login")
// .excludePathPatterns("/druid/**")
// .excludePathPatterns("/openapi/**");

registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
.addPathPatterns("/api/**")
.excludePathPatterns("/api/login")
.excludePathPatterns("/druid/**")
.excludePathPatterns("/openapi/**");
.excludePathPatterns(
"/api/login", "/api/ldap/ldapEnableStatus",
"/druid/**", "/openapi/**");

registry.addInterceptor(new TenantInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/login")
.excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus")
.addPathPatterns("/api/alertGroup/**")
.addPathPatterns("/api/alertHistory/**")
.addPathPatterns("/api/alertInstance/**")
Expand Down
10 changes: 5 additions & 5 deletions dinky-admin/src/main/java/org/dinky/configure/CorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public class CorsConfig {

@Bean
public CorsFilter corsFilter() {
// log.info("设置跨域");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
// 允许任何头
// allow all domain
corsConfiguration.addAllowedHeader("*");
// 允许任何方法(post、get等)
// allow all method
corsConfiguration.addAllowedMethod("*");
//
// allow all origin
corsConfiguration.addExposedHeader("*");
// allow all origin
corsConfiguration.addAllowedOriginPattern("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// 对接口配置跨域设置
// set path pattern to apply this configuration to
source.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(source);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;

@Configuration
public class SaTokenConfigure {
// Sa-Token 整合 jwt (Simple 简单模式)
@Bean
public StpLogic getStpLogicJwt() {
return new StpLogicJwtForSimple();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -73,6 +75,7 @@ public Result<UserDTO> login(@RequestBody LoginDTO loginDTO) {
*/
@DeleteMapping("/outLogin")
@ApiOperation(value = "LogOut", notes = "LogOut")
@SaIgnore
public Result<Void> outLogin() {
userService.outLogin();
return Result.succeed(I18nMsgUtils.getMsg(Status.SIGN_OUT_SUCCESS));
Expand All @@ -84,6 +87,7 @@ public Result<Void> outLogin() {
* @return {@link Result}{@link UserDTO} obtain the current user's UserDTO
*/
@GetMapping("/current")
@SaCheckLogin
@ApiOperation(value = "Current User Info", notes = "Current User Info")
public Result<UserDTO> getCurrentUserInfo() {
return userService.queryCurrentUserInfo();
Expand All @@ -96,6 +100,7 @@ public Result<UserDTO> getCurrentUserInfo() {
* @return {@link Result}{@link Tenant} the specified tenant
*/
@PostMapping("/chooseTenant")
@SaCheckLogin
@ApiOperation(value = "Choose Tenant To Login", notes = "Choose Tenant To Login")
public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId) {
return userService.chooseTenant(tenantId);
Expand All @@ -107,6 +112,7 @@ public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId
* @return {@link Result}{@link SaTokenInfo}
*/
@GetMapping("/tokenInfo")
@SaCheckLogin
@ApiOperation(value = "Query Current User Token Info", notes = "Query Current User Token Info")
public Result<SaTokenInfo> getTokenInfo() {
return Result.succeed(StpUtil.getTokenInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public Result<Void> saveOrUpdate(@RequestBody AlertGroup alertGroup) throws Exce
* @return {@link ProTableResult} with {@link AlertGroup}
*/
@PostMapping
@Log(title = "Query AlertGroup List", businessType = BusinessType.QUERY)
@ApiOperation("Query AlertGroup List")
public ProTableResult<AlertGroup> listAlertGroups(@RequestBody JsonNode para) {
return alertGroupService.selectForProTable(para);
Expand Down Expand Up @@ -122,7 +121,6 @@ public Result<Void> deleteMul(@RequestBody JsonNode para) {
*/
@GetMapping("/listEnabledAll")
@ApiOperation("Query AlertGroup List Of Enable")
@Log(title = "Query AlertGroup List Of Enable", businessType = BusinessType.QUERY)
public Result<List<AlertGroup>> listEnabledAll() {
return Result.succeed(alertGroupService.listEnabledAll());
}
Expand Down Expand Up @@ -167,7 +165,6 @@ public Result<Void> deleteGroupById(@RequestParam("id") Integer id) {
* @return {@link ProTableResult} with {@link AlertHistory}
*/
@PostMapping("/history")
@Log(title = "Query AlertHistory List", businessType = BusinessType.QUERY)
@ApiOperation("Query AlertHistory List")
public ProTableResult<AlertHistory> listAlertHistory(@RequestBody JsonNode para) {
return alertHistoryService.selectForProTable(para);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -54,6 +55,7 @@ public class LdapController {
@Autowired UserService userService;

@GetMapping("/ldapEnableStatus")
@SaIgnore
public Result<Boolean> ldapStatus() {
return Result.succeed(
SystemConfiguration.getInstances().getLdapEnable().getValue(), "获取成功");
Expand Down
120 changes: 120 additions & 0 deletions dinky-admin/src/main/java/org/dinky/controller/MenuController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.controller;

import org.dinky.annotation.Log;
import org.dinky.data.dto.RoleMenuDto;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.Menu;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.service.MenuService;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/menu")
@RequiredArgsConstructor
public class MenuController {

private final MenuService menuService;

/**
* save or update menu
*
* @param menu {@link Menu}
* @return {@link Result} with {@link Void}
*/
@PutMapping("addOrUpdate")
@Log(title = "Insert OR Update Menu ", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("INSERT OR UPDATE Menu")
public Result<Void> saveOrUpdateMenu(@RequestBody Menu menu) {
if (menuService.saveOrUpdate(menu)) {
return Result.succeed(Status.SAVE_SUCCESS);
} else {
return Result.failed(Status.SAVE_FAILED);
}
}

/**
* list Menus
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} with {@link Menu}
*/
@GetMapping("listMenus")
@ApiOperation("Query Menu List")
public Result<List<Menu>> listMenus() {
return Result.data(menuService.list());
}

/**
* delete menu by id
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@DeleteMapping("/delete")
@ApiOperation("Delete Menu By Id")
@Log(title = "Delete Menu By Id", businessType = BusinessType.DELETE)
public Result<Void> deleteMenuById(@RequestParam("id") Integer id) {
if (menuService.deleteMenuById(id)) {
return Result.succeed(Status.DELETE_SUCCESS);
} else {
return Result.failed(Status.DELETE_FAILED);
}
}

/**
* load role menu tree
*
* @param roleId role id
* @return {@link RoleMenuDto}
*/
@GetMapping(value = "/roleMenuTreeSelect/{roleId}")
@ApiOperation("Load Role Menu")
public Result<RoleMenuDto> roleMenuTreeSelect(@PathVariable("roleId") Integer roleId) {
List<Menu> menus = menuService.list();
RoleMenuDto menuVO =
RoleMenuDto.builder()
.roleId(roleId)
.selectedMenuIds(menuService.selectMenuListByRoleId(roleId))
.menus(menus)
.build();
return Result.succeed(menuVO);
}
}
Loading

0 comments on commit 387ccd0

Please sign in to comment.