Skip to content

Commit

Permalink
CB-6059 create team with uppercase fix (#3142)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Daria Marutkina <[email protected]>
  • Loading branch information
3 people authored Dec 25, 2024
1 parent 398f9b7 commit aa778e0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions webapp/packages/core-authentication/src/TeamsResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

await this.setSubjectPermissions(newTeam.teamId, teamPermissions);

return this.get(teamId)!;
return this.get(newTeam.teamId)!;
}

async updateTeam({ teamId, teamPermissions, teamName, description }: TeamInfo): Promise<TeamInfo> {
Expand All @@ -73,7 +73,7 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

this.markOutdated(team.teamId);

return this.get(teamId)!;
return this.get(team.teamId)!;
}

async deleteTeam(key: ResourceKeySimple<string>, options?: { force: boolean }): Promise<Map<string, TeamInfo>> {
Expand Down

0 comments on commit aa778e0

Please sign in to comment.