1996fanrui commented on code in PR #1792:
URL: 
https://github.com/apache/incubator-streampark/pull/1792#discussion_r991231832


##########
streampark-console/streampark-console-service/src/assembly/script/schema/mysql-schema.sql:
##########
@@ -375,6 +375,7 @@ create table `t_user` (
   `password` varchar(128) collate utf8mb4_general_ci not null comment 
'password',
   `email` varchar(128) collate utf8mb4_general_ci default null comment 'email',
   `user_type` int  not null comment 'user type 1:admin 2:user',
+  `team_id` bigint default null comment 'latest team id',

Review Comment:
   Rename `team_id` to `latest_team_id` may be more clear.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/entity/User.java:
##########
@@ -98,16 +98,8 @@ public class User implements Serializable {
     private String nickName;
 
     /**
-     * shiro-redis v3.1.0 must have getAuthCacheKey() or getId() function # 
Principal id field name.
-     * The field which you can get unique id to identify this principal. # For 
example, if you use UserInfo as
-     * Principal class, the id field maybe userId, userName, email, etc. # 
Remember to add getter to
-     * this id field. For example, getUserId(), getUserName(), getEmail(), 
etc. # Default value is
-     * authCacheKey or id, that means your principal object has a method 
called "getAuthCacheKey()" or
-     * "getId()"
-     *
-     * @return userId as Principal id field name
+     * The last set teamId
      */
-    public Long getAuthCacheKey() {
-        return userId;
-    }
+    private Long teamId;

Review Comment:
   This `teamId` also should be renamed to `latestTeamId`



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/UserService.java:
##########
@@ -106,4 +106,8 @@ public interface UserService extends IService<User> {
     Set<String> getPermissions(String username);
 
     List<User> getNoTokenUser();
+
+    void setLatestTeam(Long teamId, Long userId);
+
+    void checkTeam(User user);

Review Comment:
   How about `fillInTeam`?
   
   This method not just check team.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java:
##########
@@ -99,4 +100,9 @@ public List<Team> findUserTeams(Long userId) {
         }
         return baseMapper.findUserTeams(userId);
     }
+
+    @Override
+    public Team getDefaultTeam() {
+        return getById(Constant.DEFAULT_TEAM_ID);
+    }

Review Comment:
   This file too.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java:
##########
@@ -177,12 +184,35 @@ public List<User> getNoTokenUser() {
         return users;
     }
 
+    @Override
+    public void setLatestTeam(Long teamId, Long userId) {
+        User user = getById(userId);
+        AssertUtils.checkArgument(user != null);
+        user.setTeamId(teamId);
+        this.baseMapper.updateById(user);
+    }
+
+    @Override
+    public void checkTeam(User user) {
+        if (user.getTeamId() == null) {
+            List<Team> teams = memberService.findUserTeams(user.getUserId());
+            if (CollectionUtils.isEmpty(teams)) {
+                throw new ApiException("There is no team to assign, please 
contact the administrator!");

Review Comment:
   I create a new user, and doesn't belong to any team. When the user login the 
platform, the front-end just show `No permission, please contact the 
administrator`.
   
   So I guess this alert doesn't take affect.



##########
streampark-console/streampark-console-service/src/main/resources/mapper/system/UserMapper.xml:
##########
@@ -33,6 +33,7 @@
         <result column="sex" jdbcType="CHAR" property="sex"/>
         <result column="avatar" jdbcType="VARCHAR" property="avatar"/>
         <result column="description" jdbcType="VARCHAR" 
property="description"/>
+        <result column="team_id" jdbcType="BIGINT" property="teamId"/>

Review Comment:
   This too.



##########
streampark-console/streampark-console-webapp/src/views/system/member/MemberAdd.vue:
##########
@@ -119,10 +117,7 @@ export default {
       this.form.validateFields((err, member) => {
         if (!err && this.validateStatus === 'success') {
           this.loading = true
-          post({
-            ...member,

Review Comment:
   The member page cann't be refresh when I switch the team. It may be missed 
case.



##########
streampark-console/streampark-console-webapp/src/views/user/SignIn.vue:
##########
@@ -161,25 +215,57 @@ export default {
         if (!err) {
           const loginParams = {...values}
           SignIn(loginParams)
-            .then(resp => {
-              if (resp.code != null) {
-                const message = 'SignIn failed,' + (resp.code === 0 ? ' 
authentication error' : ' current User is locked.')
-                this.$message.error(message)
-              } else {
-                this.$router.push({path: '/flink/app'})
+            .then(() => {
+              this.$router.push({path: '/flink/app'})
+            }).catch(resp => {
+              const code = resp.code
+              if (code != null && code != undefined) {
+                if (code == 0 || code == 1) {
+                  const message = 'SignIn failed,' + (resp.code === 0 ? ' 
authentication error' : ' current User is locked.')
+                  this.$message.error(message)
+                } else if (resp.code == 403) {
+                  this.loginInfo = values
+                  this.teamVisible = true
+                  this.userId = resp.data
+                  teams({
+                    userId: this.userId
+                  }).then((r) => {
+                    this.teamList = r.data
+                  })
+                } else {
+                  console.log(resp)
+                }
               }
-            })
-            .catch(err => console.log(err))
-            .finally(() => {
+          }).finally(() => {
               state.loginBtn = false
-            })
+          })
         } else {
           setTimeout(() => {
             state.loginBtn = false
           }, 600)
         }
       })
-    }
+    },
+

Review Comment:
   When the user login the platform, the team show the teamId, it should show 
the teamName



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java:
##########
@@ -33,4 +33,6 @@ public class Constant {
     public static final String APP_MENU_ID = "100015";
     public static final String APP_DETAIL_MENU_ID = "100018";
 
+    public static final String DEFAULT_TEAM_ID = "100000";
+

Review Comment:
   ```suggestion
   ```
   
   This code isn't used, it can be deleted.



##########
streampark-console/streampark-console-service/src/main/resources/mapper/system/TeamMapper.xml:
##########
@@ -47,8 +47,8 @@
 
     <select id="findUserTeams" resultType="team" parameterType="team">
         select t.* from t_team t
-        join t_user_role ur
-        on t.id = ur.team_id
+        join t_member m
+        on t.id = m.team_id
         where ur.user_id = #{userId}

Review Comment:
   `ur`should be changed to `m`. It's a bug, the `test_user3` cannot login 
platform.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/DetailException.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.streampark.console.base.exception;
+
+/**
+ * api business exceptions, as different from internal errors, need to return 
a friendly exception message
+ */
+public class DetailException extends RuntimeException {

Review Comment:
   The `DetailException` isn't clear, it doesn't has specific information. How 
about `ApiBusinessException`?



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/TeamService.java:
##########
@@ -39,4 +39,5 @@ public interface TeamService extends IService<Team> {
 
     List<Team> findUserTeams(Long userId);
 
+    Team getDefaultTeam();

Review Comment:
   The code can be removed as well.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to