From aa778e0f9403ea6719a945598f1e30910dcb4ab0 Mon Sep 17 00:00:00 2001 From: Ainur <59531286+yagudin10@users.noreply.github.com> Date: Wed, 25 Dec 2024 13:36:53 +0200 Subject: [PATCH] CB-6059 create team with uppercase fix (#3142) * CB-6059 create team with uppercase fix * CB-6069 fixes error with team creation with teamId in upper case * CB-6059 fix potential npe --------- Co-authored-by: sergeyteleshev Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com> --- .../service/admin/impl/WebServiceAdmin.java | 19 ++++++++++++++++--- .../CBEmbeddedSecurityController.java | 14 ++++++++++++-- .../core-authentication/src/TeamsResource.ts | 4 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java index 6aaf00c790..96e1fab90a 100644 --- a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java +++ b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java @@ -210,14 +210,27 @@ public boolean deleteUser(@NotNull WebSession webSession, String userName) throw @NotNull @Override - public AdminTeamInfo createTeam(@NotNull WebSession webSession, String teamId, String teamName, String description) throws DBWebException { + public AdminTeamInfo createTeam( + @NotNull WebSession webSession, + @NotNull String teamId, + @Nullable String teamName, + @Nullable String description + ) throws DBWebException { if (teamId.isEmpty()) { throw new DBWebException("Empty team ID"); } + WebUser user = webSession.getUser(); + if (user == null) { + throw new DBWebException("Admin user is not found"); + } webSession.addInfoMessage("Create new team - " + teamId); try { - webSession.getAdminSecurityController().createTeam(teamId, teamName, description, webSession.getUser().getUserId()); - SMTeam newTeam = webSession.getAdminSecurityController().findTeam(teamId); + SMTeam newTeam = webSession.getAdminSecurityController().createTeam( + teamId, + teamName, + description, + user.getUserId() + ); return new AdminTeamInfo(webSession, newTeam); } catch (Exception e) { throw new DBWebException("Error creating new team", e); diff --git a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java index 8681a72ef4..b96bf96a45 100644 --- a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java +++ b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java @@ -1148,7 +1148,7 @@ WHERE AP.SUBJECT_ID IN (R.TEAM_ID,?) } @Override - public SMTeam findTeam(String teamId) throws DBCException { + public SMTeam findTeam(@NotNull String teamId) throws DBCException { return Arrays.stream(readAllTeams()) .filter(r -> r.getTeamId().equals(teamId)) .findFirst().orElse(null); @@ -1219,7 +1219,12 @@ private SMUser fetchUser(ResultSet dbResult) throws SQLException { } @Override - public void createTeam(String teamId, String name, String description, String grantor) throws DBCException { + public SMTeam createTeam( + @NotNull String teamId, + @Nullable String name, + @Nullable String description, + @NotNull String grantor + ) throws DBCException { if (CommonUtils.isEmpty(teamId)) { throw new DBCException("Empty team name is not allowed"); } @@ -1251,6 +1256,11 @@ public void createTeam(String teamId, String name, String description, String gr } catch (SQLException e) { throw new DBCException("Error saving team in database", e); } + SMTeam smTeam = new SMTeam(teamId, name, description, true); + for (String permission : getDefaultTeamPermissions()) { + smTeam.addPermission(permission); + } + return smTeam; } protected String[] getDefaultTeamPermissions() { diff --git a/webapp/packages/core-authentication/src/TeamsResource.ts b/webapp/packages/core-authentication/src/TeamsResource.ts index 832c1d880c..9128af0ed3 100644 --- a/webapp/packages/core-authentication/src/TeamsResource.ts +++ b/webapp/packages/core-authentication/src/TeamsResource.ts @@ -56,7 +56,7 @@ export class TeamsResource extends CachedMapResource { @@ -73,7 +73,7 @@ export class TeamsResource extends CachedMapResource, options?: { force: boolean }): Promise> {