Skip to content

Commit

Permalink
[Feature-1641][admin,client] Add Flink row level permissions (DataLin…
Browse files Browse the repository at this point in the history
…kDC#1831)

Co-authored-by: wenmo <32723967+wenmo@users.noreply.github.com>
  • Loading branch information
aiwenmo and aiwenmo authored Apr 2, 2023
1 parent a45fb09 commit e5bdefe
Show file tree
Hide file tree
Showing 41 changed files with 2,963 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
*
* 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.common.result.ProTableResult;
import org.dinky.common.result.Result;
import org.dinky.model.RoleSelectPermissions;
import org.dinky.service.RoleSelectPermissionsService;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/roleSelectPermissions")
public class RoleSelectPermissionsController {

@Autowired private RoleSelectPermissionsService roleSelectPermissionsService;

/** create or update roleSelectPermissions */
@PutMapping
public Result saveOrUpdateRole(@RequestBody RoleSelectPermissions roleSelectPermissions) {
if (roleSelectPermissionsService.saveOrUpdate(roleSelectPermissions)) {
return Result.succeed("新增成功");
} else {
return Result.failed("新增失败");
}
}

/** delete roleSelectPermissions by id */
@DeleteMapping
public Result deleteMul(@RequestBody JsonNode para) {
if (para.size() > 0) {
List<Integer> error = new ArrayList<>();
for (final JsonNode item : para) {
Integer id = item.asInt();
if (!roleSelectPermissionsService.removeById(id)) {
error.add(id);
}
}
if (error.size() == 0) {
return Result.succeed("删除成功");
} else {
return Result.succeed(
"删除部分成功,但" + error.toString() + "删除失败,共" + error.size() + "次失败。");
}
} else {
return Result.failed("请选择要删除的记录");
}
}

/** query roleSelectPermissions list */
@PostMapping
public ProTableResult<RoleSelectPermissions> listRoles(@RequestBody JsonNode para) {
return roleSelectPermissionsService.selectForProTable(para);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* 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.mapper;

import org.dinky.db.mapper.SuperMapper;
import org.dinky.model.RoleSelectPermissions;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/** role select permissions mapper interface */
@Mapper
public interface RoleSelectPermissionsMapper extends SuperMapper<RoleSelectPermissions> {

/**
* delete user role select permissions by role id
*
* @param roleIds role id
* @return delete status
*/
int deleteByRoleIds(@Param("roleIds") List<Integer> roleIds);

/**
* select user role data permissions by role ids
*
* @param roleIds role ids
* @return List<RoleSelectPermissions>
*/
List<RoleSelectPermissions> listRoleSelectPermissionsByRoleIds(
@Param("roleIds") List<Integer> roleIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.dinky.mapper;

import org.dinky.db.mapper.SuperMapper;
import org.dinky.model.Role;
import org.dinky.model.UserRole;

import org.apache.ibatis.annotations.Mapper;
Expand Down Expand Up @@ -52,4 +53,12 @@ public interface UserRoleMapper extends SuperMapper<UserRole> {
* @return delete status
*/
int deleteByRoleIds(@Param("roleIds") List<Integer> roleIds);

/**
* get role list by user id
*
* @param userId userId
* @return role list
*/
List<Role> getRoleByUserId(Integer userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
*
* 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.model;

import java.io.Serializable;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dinky_role_select_permissions")
public class RoleSelectPermissions implements Serializable {

private static final long serialVersionUID = 8676666963206334660L;

/** id */
@TableId(value = "id", type = IdType.AUTO)
private Integer id;

/** role id */
private Integer roleId;

/** table_name */
private String tableName;

/** expression */
private String expression;

/** create time */
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;

/** update time */
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;

/** role code */
@TableField(exist = false)
private String roleCode;

/** role name */
@TableField(exist = false)
private String roleName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* 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.service;

import org.dinky.db.service.ISuperService;
import org.dinky.model.RoleSelectPermissions;

import java.util.List;

public interface RoleSelectPermissionsService extends ISuperService<RoleSelectPermissions> {

/**
* delete user role select permissions by role id
*
* @param roleIds role id
* @return delete status
*/
boolean deleteByRoleIds(List<Integer> roleIds);

/**
* select user role data permissions by role id
*
* @param roleId role id
* @return List<RoleSelectPermissions>
*/
List<RoleSelectPermissions> listAllByRoleId(Integer roleId);

/**
* select user role data permissions by role ids
*
* @param roleIds role ids
* @return List<RoleSelectPermissions>
*/
List<RoleSelectPermissions> listRoleSelectPermissionsByRoleIds(List<Integer> roleIds);
}
10 changes: 10 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/RoleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.dinky.db.service.ISuperService;
import org.dinky.model.Role;

import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;

public interface RoleService extends ISuperService<Role> {
Expand Down Expand Up @@ -66,4 +68,12 @@ public interface RoleService extends ISuperService<Role> {
* @return {@link Result} of {@link Void}
*/
Result<Void> deleteRoleById(Integer id);

/**
* get role list by user id
*
* @param userId user id
* @return role list
*/
List<Role> getRoleByUserId(Integer userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.dinky.service;

import org.dinky.db.service.ISuperService;
import org.dinky.model.Role;
import org.dinky.model.UserRole;

import java.util.List;
Expand Down Expand Up @@ -57,4 +58,12 @@ public interface UserRoleService extends ISuperService<UserRole> {
* @return
*/
boolean deleteByRoleIds(List<Integer> roleIds);

/**
* query roles by user id
*
* @param userId user id
* @return role list
*/
List<Role> getRoleByUserId(Integer userId);
}
18 changes: 18 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
import org.dinky.dto.LoginDTO;
import org.dinky.dto.ModifyPasswordDTO;
import org.dinky.dto.UserDTO;
import org.dinky.model.Role;
import org.dinky.model.RoleSelectPermissions;
import org.dinky.model.Tenant;
import org.dinky.model.User;
import org.dinky.params.AssignRoleParams;

import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;

/**
Expand Down Expand Up @@ -134,4 +138,18 @@ public interface UserService extends ISuperService<User> {
* @return {@link Boolean}
*/
Boolean checkAdmin(Integer id);

/**
* get role by current user
*
* @return role list
*/
List<Role> getCurrentRole();

/**
* get role select permissions by current user
*
* @return role select permissions list
*/
List<RoleSelectPermissions> getCurrentRoleSelectPermissions();
}
Loading

0 comments on commit e5bdefe

Please sign in to comment.