Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Improve the search_owner when query the app list #1828

Merged
merged 8 commits into from
Oct 15, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ private Map<String, Object> generateUserInfo(JWTToken token, User user) {

Set<String> permissions = this.userService.getPermissions(username);
userInfo.put("permissions", permissions);
user.setPassword("******");
user.setSalt("******");
user.dataMasking();
userInfo.put("user", user);
return userInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ public RestResponse setTeam(Long teamId) {
userService.setLatestTeam(teamId, user.getUserId());

//2) get latest userInfo
user.setPassword("******");
user.setSalt("******");
user.dataMasking();

Map<String, Object> infoMap = new HashMap<>(8);
infoMap.put("user", user);
Expand All @@ -205,4 +204,11 @@ public RestResponse setTeam(Long teamId) {
return new RestResponse().data(infoMap);
}

@PostMapping("appOwners")
public RestResponse appOnwers(Long teamId) {
List<User> userList = userService.findByAppOwner(teamId);
userList.forEach((u) -> u.dataMasking());
return RestResponse.success(userList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ public class User implements Serializable {
*/
private Long teamId;

public void dataMasking() {
this.setPassword("******");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, @wolfboys Thank you for your contribution。Strings with special meanings are recommended to be extracted as public variables,do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, @wolfboys Thank you for your contribution。Strings with special meanings are recommended to be extracted as public variables,do you think?

Great suggestion, I agree with you. I'll fix it later

this.setSalt("******");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {

IPage<User> findUserDetail(Page page, @Param("user") User user);

@Select("SELECT u.* FROM t_user u LEFT JOIN t_access_token t ON u.USER_ID = t.USER_ID WHERE t.USER_ID IS NULL")
List<User> getNoTokenUser();

List<User> findByAppOwner(@Param("userId") Long userId, @Param("teamId") Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ public interface UserService extends IService<User> {

void fillInTeam(User user);

List<User> findByAppOwner(Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.streampark.console.system.mapper.UserMapper;
import org.apache.streampark.console.system.service.MemberService;
import org.apache.streampark.console.system.service.MenuService;
import org.apache.streampark.console.system.service.TeamService;
import org.apache.streampark.console.system.service.UserService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
Expand Down Expand Up @@ -58,14 +57,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Autowired
private MemberService memberService;

@Autowired
private MenuService menuService;

@Autowired
private CommonService commonService;

@Autowired
private TeamService teamService;
private MenuService menuService;

@Override
public User findByName(String username) {
Expand Down Expand Up @@ -206,6 +202,11 @@ public void fillInTeam(User user) {
}
}

@Override
public List<User> findByAppOwner(Long teamId) {
return baseMapper.findByAppOwner(commonService.getUserId(), teamId);
}

private void setUserRoles(User user, String[] roles) {
Arrays.stream(roles).forEach(roleId -> {
Member ur = new Member();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-- Records of t_team
-- ----------------------------
insert into `t_team` values (100000, 'default', 'The default team', now(), now());
insert into `t_team` values (100001, 'test_team1', 'The test team1', now(), now());
insert into `t_team` values (100001, 'test', 'The test team', now(), now());


-- ----------------------------
Expand Down Expand Up @@ -152,14 +152,14 @@ insert into `t_setting` values (15, 'docker.register.namespace', null, 'Namespac
-- Records of t_user
-- ----------------------------
insert into `t_user` values (100000, 'admin', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 1, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100001, 'test_user1', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100002, 'test_user2', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100003, 'test_user3', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100001, 'test1', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100002, 'test2', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);
insert into `t_user` values (100003, 'test3', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 2, null, '1', now(), now(),null,'0',null,null);

-- ----------------------------
-- Records of t_member
-- ----------------------------
insert into `t_member` values (100000, 100000, 100001, 100001, now(), now()); -- test_user1 is the developer of the default team
insert into `t_member` values (100001, 100001, 100001, 100001, now(), now()); -- test_user1 is the developer of the test_team1 team
insert into `t_member` values (100002, 100000, 100002, 100001, now(), now()); -- test_user2 is the developer of the test_team1 team
insert into `t_member` values (100003, 100001, 100003, 100001, now(), now()); -- test_user3 is the developer of the test_team1 team
insert into `t_member` values (100001, 100001, 100001, 100001, now(), now()); -- test_user1 is the developer of the test team
insert into `t_member` values (100002, 100000, 100002, 100001, now(), now()); -- test_user2 is the developer of the test team
insert into `t_member` values (100003, 100001, 100003, 100001, now(), now()); -- test_user3 is the developer of the test team
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,34 @@
order by ${user.sortField} ${user.sortOrder}
</if>
</select>

<select id="getNoTokenUser" resultType="user" parameterType="user">
select u.* from t_user u left join t_access_token t
on u.user_id = t.user_id
where t.user_id is null
</select>

<select id="findByAppOwner" resultType="user" parameterType="user">
select u.* from t_user u
inner join (
select distinct(user_id) as user_id from (
select a.user_id
from t_user a
inner join t_flink_app b
on a.user_id = b.user_id
where a.user_id = #{userId}
and a.user_type = 1
union all
select u.user_id
from t_user u
inner join t_member m
on u.user_id = m.user_id
inner join t_flink_app p
on u.user_id = p.user_id
where m.team_id = #{teamId}
)
) as t
where u.user_id = t.user_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't use this sql?

select u.* from t_user u 
inner join (
select distinct(user_id) from t_flink_app where m.team_id = #{teamId}
) t
where u.user_id = t.user_id

The new sql has some advantages:

  • It is more simple.
  • It is easy to understand for other developers.
  • And it can show all apps owner for current team.
  • When some team members leave or move to other teams, we should also be able to filter his apps.
  • For the System Admin team, Admins often have some test jobs. AdminA should be able to filter AdminB's apps.

The new sql is simple and feature rich, why use a complex sql?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't use this sql?

select u.* from t_user u 
inner join (
select distinct(user_id) from t_flink_app where m.team_id = #{teamId}
) t
where u.user_id = t.user_id

The new sql has some advantages:

  • It is more simple.
  • It is easy to understand for other developers.
  • And it can show all apps owner for current team.
  • When some team members leave or move to other teams, we should also be able to filter his apps.
  • For the System Admin team, Admins often have some test jobs. AdminA should be able to filter AdminB's apps.

The new sql is simple and feature rich, why use a complex sql?

oh, Perfect 👍 😂

</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export default {
CHECK_NAME: '/user/check/name',
CHECK_PASSWORD: '/user/check/password',
SET_TEAM: '/user/setTeam',
INIT_TEAM: '/user/initTeam'
INIT_TEAM: '/user/initTeam',
APP_OWNERS: '/user/appOwners'
},
Token: {
LIST: '/token/list',
Expand Down
4 changes: 4 additions & 0 deletions streampark-console/streampark-console-webapp/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ export function setTeam(queryParam) {
export function initTeam(queryParam) {
return http.post(api.User.INIT_TEAM, queryParam)
}

export function appOwners(queryParam) {
return http.post(api.User.APP_OWNERS, queryParam)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ import {activeURL} from '@/api/flinkCluster'
import {Terminal} from 'xterm'
import 'xterm/css/xterm.css'
import SvgIcon from '@/components/SvgIcon'
import {list as listUser} from '@/api/user'
import {appOwners} from '@/api/user'

export default {
components: {Ellipsis, State, SvgIcon},
Expand Down Expand Up @@ -1309,8 +1309,8 @@ export default {

mounted() {
this.handleDashboard()
listUser({'pageSize': '9999'}).then((resp) => {
this.users = resp.data.records
appOwners().then((resp) => {
this.users = resp.data
})
this.handleInitTagsOptions()
this.handleFetch(true)
Expand Down