Skip to content

Commit

Permalink
Cb 4460 shared query history for the team (#2598)
Browse files Browse the repository at this point in the history
* CB-5067 team supervisor

* CB-4460 extended team members info api

* CB-5118 support supervisor role

* CB-4460 api fix

* CB-4460 change role name

* CB-4460 gql fix

* CB-4460 fix unexpected team role modification

* CB-4460 fix unexpected team role modification

* CB-4460 fix unexpected team role modification

* CB-4460 fix anonymous preferences

* CB-4460 adjust compare fn


---------

Co-authored-by: naumov <[email protected]>
  • Loading branch information
alexander-skoblikov and devnaumov authored May 14, 2024
1 parent 6061ec3 commit 6416486
Show file tree
Hide file tree
Showing 45 changed files with 695 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public Map<String, Object> getConfigurationParameters() {
return Collections.emptyMap();
}

@NotNull
public String[] getTeams() {
return user.getUserTeams();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ public List<String> getAvailableAuthRoles() {
return List.of();
}

public List<String> getAvailableTeamRoles() {
return List.of();
}

@Override
public WSEventController getEventController() {
return eventController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ type AdminConnectionGrantInfo {
subjectType: AdminSubjectType!
}

type AdminUserTeamGrantInfo @since(version: "24.0.5"){
userId: ID!
teamRole: String
}

type AdminObjectPermissions {
objectId: ID!
permissions: [String!]!
Expand Down Expand Up @@ -53,6 +58,7 @@ type AdminTeamInfo {
metaParameters: Object!

grantedUsers: [ID!]!
grantedUsersInfo: [AdminUserTeamGrantInfo!]! @since(version: "24.0.5")
grantedConnections: [AdminConnectionGrantInfo!]!

teamPermissions: [ID!]!
Expand Down Expand Up @@ -128,6 +134,7 @@ extend type Query {
listTeams(teamId: ID): [AdminTeamInfo!]!
listPermissions: [AdminPermissionInfo!]!
listAuthRoles: [String!]!
listTeamRoles: [String!]!
listTeamMetaParameters: [ObjectPropertyInfo!]!

createUser(userId: ID!, enabled: Boolean!, authRole: String): AdminUserInfo!
Expand All @@ -150,6 +157,8 @@ extend type Query {

setUserAuthRole(userId: ID!, authRole: String): Boolean

setUserTeamRole(userId: ID!, teamId: ID!, teamRole: String): Boolean @since(version: "24.0.5")

#### Connection management

# All connection configurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.security.SMDataSourceGrant;
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.model.security.SMTeamMemberInfo;
import org.jkiss.dbeaver.model.security.user.SMTeam;

import java.util.ArrayList;
Expand Down Expand Up @@ -88,4 +89,8 @@ public String[] getGrantedUsers() throws DBException {
return session.getAdminSecurityController().getTeamMembers(getTeamId());
}

@Property
public List<SMTeamMemberInfo> getGrantedUsersInfo() throws DBException {
return session.getAdminSecurityController().getTeamMembersInfo(getTeamId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ AdminUserInfo createUser(
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
List<String> listAuthRoles();

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
List<String> listTeamRoles();

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
boolean deleteUser(@NotNull WebSession webSession, String userName) throws DBWebException;

Expand Down Expand Up @@ -202,4 +205,10 @@ WebPropertyInfo saveUserMetaParameter(WebSession webSession, String id, String d
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean setUserAuthRole(WebSession webSession, String userId, String authRole) throws DBWebException;

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean setUserTeamRole(
@NotNull WebSession webSession, @NotNull String userId,
@NotNull String teamId, @Nullable String teamRole
) throws DBWebException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
env -> getService(env).listPermissions(getWebSession(env)))
.dataFetcher("listAuthRoles",
env -> getService(env).listAuthRoles())
.dataFetcher("listTeamRoles",
env -> getService(env).listTeamRoles())
.dataFetcher("listTeamMetaParameters",
env -> getService(env).listTeamMetaParameters(getWebSession(env)))
.dataFetcher("createUser",
Expand Down Expand Up @@ -106,6 +108,14 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
env -> getService(env).enableUser(getWebSession(env), env.getArgument("userId"), env.getArgument("enabled")))
.dataFetcher("setUserAuthRole",
env -> getService(env).setUserAuthRole(getWebSession(env), env.getArgument("userId"), env.getArgument("authRole")))
.dataFetcher("setUserTeamRole",
env -> getService(env).setUserTeamRole(
getWebSession(env),
env.getArgument("userId"),
env.getArgument("teamId"),
env.getArgument("teamRole")
)
)
.dataFetcher("searchConnections", env -> getService(env).searchConnections(getWebSession(env), env.getArgument("hostNames")))
.dataFetcher("getConnectionSubjectAccess",
env -> getService(env).getConnectionSubjectAccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public List<String> listAuthRoles() {
return CBApplication.getInstance().getAvailableAuthRoles();
}

@Override
public List<String> listTeamRoles() {
return CBApplication.getInstance().getAvailableTeamRoles();
}

@Override
public boolean deleteUser(@NotNull WebSession webSession, String userName) throws DBWebException {
if (CommonUtils.equalObjects(userName, webSession.getUser().getUserId())) {
Expand Down Expand Up @@ -392,6 +397,21 @@ public Boolean setUserAuthRole(WebSession webSession, String userId, String auth
}
}

@Override
public Boolean setUserTeamRole(
@NotNull WebSession webSession,
@NotNull String userId,
@NotNull String teamId,
@Nullable String teamRole
) throws DBWebException {
try {
webSession.getAdminSecurityController().setUserTeamRole(userId, teamId, teamRole);
return true;
} catch (Exception e) {
throw new DBWebException("Error updating user auth role", e);
}
}

////////////////////////////////////////////////////////////////////
// Connection management

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ type UserInfo {
metaParameters: Object!
# User configuration parameters
configurationParameters: Object!
# User teams
teams: [UserTeamInfo!]!
}

type UserTeamInfo {
teamId: String!
teamName: String!
teamRole: String
}

extend type Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.user.WebUser;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.meta.Property;
Expand Down Expand Up @@ -88,4 +89,19 @@ public Map<String, Object> getConfigurationParameters() throws DBWebException {
return session.getUserContext().getPreferenceStore().getCustomUserParameters();
}

@NotNull
@Property
public List<WebUserTeamInfo> getTeams() throws DBWebException {
if (session.getUserContext().isNonAnonymousUserAuthorizedInSM()) {
try {
return Arrays.stream(session.getSecurityController().getCurrentUserTeams())
.map(WebUserTeamInfo::new)
.toList();
} catch (DBException e) {
throw new DBWebException("Error reading user's teams", e);
}
} else {
return List.of();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed 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 io.cloudbeaver.service.auth;

import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.security.user.SMUserTeam;

public class WebUserTeamInfo {
@NotNull
private final SMUserTeam userTeam;

public WebUserTeamInfo(@NotNull SMUserTeam userTeam) {
this.userTeam = userTeam;
}

@NotNull
@Property
public String getTeamId() {
return userTeam.getTeamId();
}

@NotNull
@Property
public String getTeamName() {
return userTeam.getTeamName();
}

@Nullable
@Property
public String getTeamRole() {
return userTeam.getTeamRole();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ CREATE TABLE {table_prefix}CB_USER_TEAM
(
USER_ID VARCHAR(128) NOT NULL,
TEAM_ID VARCHAR(128) NOT NULL,
TEAM_ROLE VARCHAR(128),

GRANT_TIME TIMESTAMP NOT NULL,
GRANTED_BY VARCHAR(128) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE {table_prefix}CB_USER_TEAM
ADD TEAM_ROLE VARCHAR(128) NULL;
Loading

0 comments on commit 6416486

Please sign in to comment.