fuweng11 commented on code in PR #8100:
URL: https://github.com/apache/inlong/pull/8100#discussion_r1209647609


##########
inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongUserRoleEntityMapper.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.apache.inlong.manager.dao.mapper;
+
+import org.apache.inlong.manager.dao.entity.InlongUserRoleEntity;
+import org.apache.inlong.manager.pojo.user.InlongRolePageRequest;
+
+import com.github.pagehelper.Page;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface InlongUserRoleEntityMapper {
+
+    int insert(InlongUserRoleEntity record);
+
+    InlongUserRoleEntity selectById(Integer id);
+
+    int updateById(InlongUserRoleEntity record);
+
+    Page<InlongUserRoleEntity> listByCondition(InlongRolePageRequest request);

Review Comment:
   selectByCondition()



##########
inlong-manager/manager-dao/src/main/resources/mappers/InlongUserRoleEntityMapper.xml:
##########
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd";>
+<mapper 
namespace="org.apache.inlong.manager.dao.mapper.InlongUserRoleEntityMapper">
+    <resultMap id="BaseResultMap" 
type="org.apache.inlong.manager.dao.entity.InlongUserRoleEntity">
+        <id column="id" jdbcType="INTEGER" property="id"/>
+        <result column="user_name" jdbcType="VARCHAR" property="username"/>
+        <result column="role_code" jdbcType="VARCHAR" property="roleCode"/>
+        <result column="disabled" jdbcType="SMALLINT" property="disabled"/>
+        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
+        <result column="creator" jdbcType="VARCHAR" property="creator"/>
+        <result column="modifier" jdbcType="VARCHAR" property="modifier"/>
+        <result column="create_time" jdbcType="TIMESTAMP" 
property="createTime"/>
+        <result column="modify_time" jdbcType="TIMESTAMP" 
property="modifyTime"/>
+        <result column="version" jdbcType="INTEGER" property="version"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id, user_name, role_code, disabled, is_deleted, creator, modifier, 
create_time, modify_time, version
+    </sql>
+
+    <insert id="insert" useGeneratedKeys="true" keyProperty="id"
+            
parameterType="org.apache.inlong.manager.dao.entity.InlongUserRoleEntity">
+        insert into inlong_user_role (id, user_name, role_code,
+                                      disabled, creator, modifier)
+        values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, 
#{roleCode,jdbcType=VARCHAR},
+                #{disabled,jdbcType=SMALLINT},

Review Comment:
   #{disabled,jdbcType=SMALLINT},#{creator,jdbcType=VARCHAR}, 
#{modifier,jdbcType=VARCHAR})



##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.apache.inlong.manager.web.controller;
+
+import org.apache.inlong.manager.common.enums.OperationType;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.InlongRoleInfo;
+import org.apache.inlong.manager.pojo.user.InlongRolePageRequest;
+import org.apache.inlong.manager.pojo.user.InlongRoleRequest;
+import org.apache.inlong.manager.service.operationlog.OperationLog;
+import org.apache.inlong.manager.service.user.InlongRoleService;
+
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api")
+@Api(tags = "INLONG-USER-API")
+public class InlongRoleController {
+
+    @Autowired
+    private InlongRoleService inlongRoleService;
+
+    @RequestMapping(value = "/role/inlong/get/{id}", method = 
RequestMethod.GET)
+    @ApiOperation(value = "Get tenant role")
+    @ApiImplicitParam(name = "id", dataTypeClass = Integer.class, required = 
true)
+    public Response<InlongRoleInfo> get(@PathVariable int id) {
+        return Response.success(inlongRoleService.get(id));
+    }
+
+    @RequestMapping(value = "/role/inlong/save", method = RequestMethod.POST)
+    @OperationLog(operation = OperationType.CREATE)
+    @ApiOperation(value = "Save tenant role")
+    public Response<Integer> save(@Validated @RequestBody InlongRoleRequest 
request) {
+        return Response.success(inlongRoleService.save(request));
+    }
+
+    @RequestMapping(value = "/role/inlong/list", method = RequestMethod.POST)
+    @ApiOperation(value = "List tenant by paginating")

Review Comment:
   @RequiresRoles(value = UserRoleCode.ADMIN)



##########
inlong-manager/manager-web/sql/apache_inlong_manager.sql:
##########
@@ -580,6 +580,29 @@ CREATE TABLE IF NOT EXISTS `user_role`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4 COMMENT ='User Role Table';
 
+-- ----------------------------
+-- Table structure for inlong_user_role
+-- ----------------------------
+CREATE TABLE IF NOT EXISTS `inlong_user_role`
+(
+    `id`          int(11)      NOT NULL AUTO_INCREMENT,
+    `user_name`   varchar(256) NOT NULL COMMENT 'Username',
+    `role_code`   varchar(256) NOT NULL COMMENT 'User role code',
+    `disabled`    tinyint(1)   NOT NULL DEFAULT '0' COMMENT 'Whether to 
disabled, 0: enabled, 1: disabled',
+    `is_deleted`  int(11)               DEFAULT '0' COMMENT 'Whether to 
delete, 0 is not deleted, if greater than 0, delete',
+    `creator`     varchar(256) NOT NULL COMMENT 'Creator name',
+    `modifier`    varchar(256)          DEFAULT NULL COMMENT 'Modifier name',
+    `create_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 
'Create time',
+    `modify_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP COMMENT 'Modify time',
+    `version`     int(11)      NOT NULL DEFAULT '1' COMMENT 'Version number, 
which will be incremented by 1 after modification',
+    PRIMARY KEY (`id`),
+    UNIQUE KEY `unique_user_role` (`user_name`, `role_code`, `is_deleted`)

Review Comment:
   unique_inlong_user_role



##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.apache.inlong.manager.web.controller;
+
+import org.apache.inlong.manager.common.enums.OperationType;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.InlongRoleInfo;
+import org.apache.inlong.manager.pojo.user.InlongRolePageRequest;
+import org.apache.inlong.manager.pojo.user.InlongRoleRequest;
+import org.apache.inlong.manager.service.operationlog.OperationLog;
+import org.apache.inlong.manager.service.user.InlongRoleService;
+
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api")
+@Api(tags = "INLONG-USER-API")
+public class InlongRoleController {
+
+    @Autowired
+    private InlongRoleService inlongRoleService;
+
+    @RequestMapping(value = "/role/inlong/get/{id}", method = 
RequestMethod.GET)
+    @ApiOperation(value = "Get tenant role")
+    @ApiImplicitParam(name = "id", dataTypeClass = Integer.class, required = 
true)

Review Comment:
   @RequiresRoles(value = UserRoleCode.ADMIN)



##########
inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongUserRoleEntityMapper.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.apache.inlong.manager.dao.mapper;
+
+import org.apache.inlong.manager.dao.entity.InlongUserRoleEntity;
+import org.apache.inlong.manager.pojo.user.InlongRolePageRequest;
+
+import com.github.pagehelper.Page;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface InlongUserRoleEntityMapper {
+
+    int insert(InlongUserRoleEntity record);
+
+    InlongUserRoleEntity selectById(Integer id);

Review Comment:
   Whether a more username lookup is required?



##########
inlong-manager/manager-web/sql/changes-1.8.0.sql:
##########
@@ -39,9 +39,30 @@ CREATE TABLE IF NOT EXISTS `inlong_tenant`
     `modify_time`  datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP COMMENT 'Modify time',
     `version`      int(11)      NOT NULL DEFAULT '1' COMMENT 'Version number, 
which will be incremented by 1 after modification',
     PRIMARY KEY (`id`),
-    UNIQUE KEY `unique_user_role_key` (`tenant`, `is_deleted`)
+    UNIQUE KEY `unique_tenant_key` (`name`, `is_deleted`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8 COMMENT ='Inlong tenant table';
 
 INSERT INTO `inlong_tenant`(`name`, `description`, `creator`, `modifier`)
-VALUES ('public', 'Default tenant', 'admin', 'admin');
\ No newline at end of file
+VALUES ('public', 'Default tenant', 'inlong_init', 'inlong_init');
+
+-- To support distinguish inlong user permission and tenant permission 
control, please see https://github.com/apache/inlong/issues/8098
+CREATE TABLE IF NOT EXISTS `inlong_user_role`
+(
+    `id`          int(11)      NOT NULL AUTO_INCREMENT,
+    `user_name`   varchar(256) NOT NULL COMMENT 'Username',
+    `role_code`   varchar(256) NOT NULL COMMENT 'User role code',
+    `disabled`    tinyint(1)   NOT NULL DEFAULT '0' COMMENT 'Whether to 
disabled, 0: enabled, 1: disabled',
+    `is_deleted`  int(11)               DEFAULT '0' COMMENT 'Whether to 
delete, 0 is not deleted, if greater than 0, delete',
+    `creator`     varchar(256) NOT NULL COMMENT 'Creator name',
+    `modifier`    varchar(256)          DEFAULT NULL COMMENT 'Modifier name',
+    `create_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 
'Create time',
+    `modify_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP COMMENT 'Modify time',
+    `version`     int(11)      NOT NULL DEFAULT '1' COMMENT 'Version number, 
which will be incremented by 1 after modification',
+    PRIMARY KEY (`id`),
+    UNIQUE KEY `unique_user_role` (`user_name`, `role_code`, `is_deleted`)

Review Comment:
   unique_inlong_user_role



##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.apache.inlong.manager.web.controller;
+
+import org.apache.inlong.manager.common.enums.OperationType;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.InlongRoleInfo;
+import org.apache.inlong.manager.pojo.user.InlongRolePageRequest;
+import org.apache.inlong.manager.pojo.user.InlongRoleRequest;
+import org.apache.inlong.manager.service.operationlog.OperationLog;
+import org.apache.inlong.manager.service.user.InlongRoleService;
+
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api")
+@Api(tags = "INLONG-USER-API")
+public class InlongRoleController {
+
+    @Autowired
+    private InlongRoleService inlongRoleService;
+
+    @RequestMapping(value = "/role/inlong/get/{id}", method = 
RequestMethod.GET)
+    @ApiOperation(value = "Get tenant role")
+    @ApiImplicitParam(name = "id", dataTypeClass = Integer.class, required = 
true)
+    public Response<InlongRoleInfo> get(@PathVariable int id) {
+        return Response.success(inlongRoleService.get(id));
+    }
+
+    @RequestMapping(value = "/role/inlong/save", method = RequestMethod.POST)
+    @OperationLog(operation = OperationType.CREATE)
+    @ApiOperation(value = "Save tenant role")

Review Comment:
   @RequiresRoles(value = UserRoleCode.ADMIN)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to