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

Cb 4460 shared query history for the team #2598

Merged
merged 26 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
25db6ac
CB-5067 team supervisor
alexander-skoblikov Apr 30, 2024
1368e63
CB-4460 extended team members info api
alexander-skoblikov May 8, 2024
0bbb69f
CB-5118 support supervisor role
devnaumov May 9, 2024
d53b054
CB-4460 api fix
alexander-skoblikov May 10, 2024
f5883c0
CB-4460 change role name
devnaumov May 10, 2024
5d50eb2
Merge branch 'CB-4460-shared-query-history-for-the-team' of https://g…
devnaumov May 10, 2024
78927c4
CB-4460 gql fix
alexander-skoblikov May 10, 2024
7e9cca4
CB-4460 fix unexpected team role modification
alexander-skoblikov May 10, 2024
814f16a
CB-4460 fix unexpected team role modification
alexander-skoblikov May 10, 2024
ea2ba04
CB-4460 fix unexpected team role modification
alexander-skoblikov May 10, 2024
82eb48e
CB-4460 fix anonymous preferences
alexander-skoblikov May 10, 2024
a26dd4a
CB-4460 adjust compare fn
devnaumov May 10, 2024
5805c7b
CB-4460 execute update team role query
alexander-skoblikov May 10, 2024
c08f64a
CB-4460 execute team deletion query
alexander-skoblikov May 10, 2024
fca25ad
Merge branch 'devel' into CB-4460-shared-query-history-for-the-team
devnaumov May 10, 2024
20e93b0
CB-4460 code cleanup
devnaumov May 10, 2024
c9257cf
CB-4460 qql schema review fix
alexander-skoblikov May 13, 2024
4c4ec33
CB-4460 remove unused table
alexander-skoblikov May 13, 2024
0947071
CB-4460 review fixes
devnaumov May 13, 2024
5f5f688
Merge branch 'CB-4460-shared-query-history-for-the-team' of https://g…
devnaumov May 13, 2024
1600861
CB-4460 do not render icon component if there is not icons provided
devnaumov May 13, 2024
06db2bd
CB-4460 change ru locale for supervisor
devnaumov May 13, 2024
f5db296
CB-4460 add supervisor description
devnaumov May 13, 2024
9f97018
Merge branch 'devel' into CB-4460-shared-query-history-for-the-team
devnaumov May 14, 2024
f2e2d6d
Merge branch 'devel' into CB-4460-shared-query-history-for-the-team
devnaumov May 14, 2024
ed4c72a
CB-4460 remove unused styles
devnaumov May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
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]!
alexander-skoblikov marked this conversation as resolved.
Show resolved Hide resolved
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

alexander-skoblikov marked this conversation as resolved.
Show resolved Hide resolved
#### 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 @@
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
List<String> listAuthRoles();

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)

Check warning on line 72 in server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java#L72

Missing a Javadoc comment.
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 @@
@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)
Boolean setUserAuthRole(WebSession webSession, String userId, String authRole) throws DBWebException;

@WebAction(requirePermissions = DBWConstants.PERMISSION_ADMIN)

Check warning on line 208 in server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/DBWServiceAdmin.java#L208

Missing a Javadoc comment.
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 @@ -63,6 +63,20 @@ CREATE TABLE {table_prefix}CB_AUTH_PERMISSIONS
FOREIGN KEY (SUBJECT_ID) REFERENCES {table_prefix}CB_AUTH_SUBJECT (SUBJECT_ID) ON DELETE CASCADE
);

CREATE TABLE {table_prefix}CB_TEAM_PERMISSIONS
(
USER_ID VARCHAR(128) NOT NULL,
TEAM_ID VARCHAR(128) NOT NULL,
PERMISSION_ID VARCHAR(64) NOT NULL,

GRANT_TIME TIMESTAMP NOT NULL,
GRANTED_BY VARCHAR(128) NOT NULL,

PRIMARY KEY (USER_ID, TEAM_ID, PERMISSION_ID),
FOREIGN KEY (USER_ID) REFERENCES {table_prefix}CB_AUTH_SUBJECT (SUBJECT_ID) ON DELETE CASCADE,
FOREIGN KEY (TEAM_ID) REFERENCES {table_prefix}CB_AUTH_SUBJECT (SUBJECT_ID) ON DELETE NO ACTION
);

CREATE TABLE {table_prefix}CB_OBJECT_PERMISSIONS
(
OBJECT_ID VARCHAR(128) NOT NULL,
Expand Down Expand Up @@ -130,6 +144,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
Loading