Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -17,25 +17,32 @@
package io.cloudbeaver;

import io.cloudbeaver.model.WebConnectionConfig;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
import org.jkiss.utils.CommonUtils;

import java.util.Map;

public class WebConnectionConfigInputHandler<T extends WebConnectionConfig, C extends DataSourceDescriptor> {
private static final Log log = Log.getLog(WebConnectionConfigInputHandler.class);
protected final T input;
protected final DBPDataSourceRegistry registry;
protected final WebSession webSession;

public WebConnectionConfigInputHandler(@NotNull DBPDataSourceRegistry registry, T configInput) {
public WebConnectionConfigInputHandler(@NotNull DBPDataSourceRegistry registry, T configInput, WebSession webSession) {
this.registry = registry;
this.input = configInput;
this.webSession = webSession;
}

public C createDataSourceContainer() throws DBWebException {
Expand All @@ -47,9 +54,7 @@

C newDataSource = createDataSourceContainerFromInput(driver);

if (ServletAppUtils.getServletApplication().getAppConfiguration() instanceof WebAppConfiguration webAppConfiguration) {
newDataSource.setNavigatorSettings(webAppConfiguration.getDefaultNavigatorSettings());
}
presetNavigatorSettings(newDataSource);

WebDataSourceUtils.saveAuthProperties(
newDataSource,
Expand All @@ -61,6 +66,29 @@
return newDataSource;
}

private <C extends DataSourceDescriptor> void presetNavigatorSettings(C newDataSource) {
// if (ServletAppUtils.getServletApplication().getAppConfiguration() instanceof WebAppConfiguration webAppConfiguration) {
// newDataSource.setNavigatorSettings(webAppConfiguration.getDefaultNavigatorSettings());
// }

Check warning on line 72 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebConnectionConfigInputHandler.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 73. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebConnectionConfigInputHandler.java:72:1: warning: Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 73. (com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck)
try {
DBPProject project = newDataSource.getProject();
String projectId = project.getId();
Map<String, Object> projectNavigatorSettings = webSession.getUserContext().getSecurityController().getObjectSettings(
projectId, SMObjectType.project,
ServletAppUtils.getServletApplication().getAppConfiguration().getDefaultUserTeam(),
DataSourceNavigatorSettings.getSettingsKeySet()
);
if (!CommonUtils.isEmpty(projectNavigatorSettings)) {
DataSourceNavigatorSettings navigatorSettings = new DataSourceNavigatorSettings();
navigatorSettings.loadSettings(projectNavigatorSettings);
newDataSource.setNavigatorSettings(navigatorSettings);
}
} catch (Exception e) {
log.warn("Error loading navigator settings", e);
}

}

public void updateDataSource(@NotNull C dataSource) throws DBWebException {
dataSource.setId(dataSource.getId());
if (!CommonUtils.isEmpty(input.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.cloudbeaver.model.WebConnectionConfig;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
Expand Down Expand Up @@ -252,6 +253,7 @@ public void refreshProjectSettings() throws DBException {
Map<String, Object> loadedSettings = webSession.getSecurityController().getObjectSettings(
getId(),
SMObjectType.project,
ServletAppUtils.getServletApplication().getAppConfiguration().getDefaultUserTeam(),
null
);
projectSettings.clear();
Expand Down Expand Up @@ -359,7 +361,7 @@ public WebConnectionConfig getConnectionConfigInput(@Nullable Map<String, Object

@NotNull
protected WebConnectionConfigInputHandler getInputConfigHandler(@NotNull Map<String, Object> configMap) {
return new WebConnectionConfigInputHandler<>(getDataSourceRegistry(), getConnectionConfigInput(configMap));
return new WebConnectionConfigInputHandler<>(getDataSourceRegistry(), getConnectionConfigInput(configMap), webSession);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,4 @@ private static RMProject createRmProjectFromWebProject(Path path, RMLocalProject

return project;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ extend type Query {

"Returns project settings that are specified for a current user"
rmUserProjectSettings(projectId: ID!): Object @since(version: "25.2.1")

"Returns project settings that are specified for a subject"
rmAdminUserProjectSettings(projectId: ID!, subjectId: String!): Object @since(version: "25.2.3")
Copy link
Member

Choose a reason for hiding this comment

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

maybe rmAdminDefaultProjectSettings?

}

extend type Mutation {
Expand Down Expand Up @@ -137,4 +140,9 @@ extend type Mutation {
rmAddUserProjectSettings(projectId: ID!, settings: Object!): Boolean! @since(version: "25.2.1")
"Deletes project settings that are specified for a current user"
rmDeleteUserProjectSettings(projectId: ID!, settingIds: [String!]!): Boolean! @since(version: "25.2.1")

"Adds project settings (e.g. enables simple view for a project) for a subject"
rmAdminAddUserProjectSettings(projectId: ID!, subjectId:String!, settings: Object!): Boolean! @since(version: "25.2.3")
"Deletes project settings that are specified for a subject"
rmAdminDeleteUserProjectSettings(projectId: ID!, subjectId:String!, settingIds: [String!]!): Boolean! @since(version: "25.2.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,29 @@
@NotNull @WebObjectId String projectId,
@Nullable List<String> settings
) throws DBWebException;

@NotNull

Check warning on line 218 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '196'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java:218:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '196'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
@WebProjectAction(requireProjectPermissions = DBWConstants.PERMISSION_ADMIN)
Map<String, Object> getProjectSettings(
@NotNull WebSession webSession,
@NotNull @WebObjectId String projectId,
@NotNull String subjectId,
@Nullable String settingId
) throws DBWebException;

@WebProjectAction(requireProjectPermissions = DBWConstants.PERMISSION_ADMIN)

Check warning on line 227 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '204'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java:227:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '204'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
boolean addProjectSettings(
@NotNull WebSession webSession,
@NotNull @WebObjectId String projectId,
@NotNull String subjectId,
@NotNull Map<String, Object> settings
) throws DBWebException;

@WebProjectAction(requireProjectPermissions = DBWConstants.PERMISSION_ADMIN)

Check warning on line 235 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '211'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java:235:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '211'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
boolean deleteProjectSettings(
@NotNull WebSession webSession,
@NotNull @WebObjectId String projectId,
@NotNull String subjectId,
@Nullable List<String> settings
) throws DBWebException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public void bindWiring(DBWBindingContext model) {
getArgument(env, "settingId")
)
)
.dataFetcher(
"rmAdminUserProjectSettings", env -> getService(env).getProjectSettings(
getWebSession(env),
getArgumentVal(env, "projectId"),
getArgumentVal(env, "subjectId"),
getArgument(env, "settingId")
)
)
;
model.getMutationType()
.dataFetcher("rmCreateResource",
Expand Down Expand Up @@ -152,6 +160,22 @@ public void bindWiring(DBWBindingContext model) {
getArgument(env, "settingIds")
)
)
.dataFetcher(
"rmAdminAddUserProjectSettings", env -> getService(env).addProjectSettings(
getWebSession(env),
getArgumentVal(env, "projectId"),
getArgumentVal(env, "subjectId"),
getArgumentVal(env, "settings")
)
)
.dataFetcher(
"rmAdminDeleteUserProjectSettings", env -> getService(env).deleteProjectSettings(
getWebSession(env),
getArgumentVal(env, "projectId"),
getArgumentVal(env, "subjectId"),
getArgument(env, "settingIds")
)
)

;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,22 +469,79 @@
}
}

@Override
public boolean addProjectSettings(@NotNull WebSession webSession, @NotNull String projectId, @NotNull Map<String, Object> settings)
throws DBWebException {

Check warning on line 474 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'throws' has incorrect indentation level 4, expected level should be 12. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java:474:5: warning: 'throws' has incorrect indentation level 4, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

try {
validateProject(webSession, projectId);
//fixme transactional
SMController securityController = webSession.getSecurityController();
securityController.deleteObjectSettings(
projectId,
SMObjectType.project,
settings.keySet()
);
securityController.setObjectSettings(
projectId,
SMObjectType.project,
settings
);
return true;
} catch (DBException e) {
throw new DBWebException("Error adding object settings", e);
}
}

@NotNull
@Override
public Map<String, Object> getProjectSettings(@NotNull WebSession webSession, @NotNull String projectId, @Nullable String settingId)
throws DBWebException {

Check warning on line 499 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'throws' has incorrect indentation level 4, expected level should be 12. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java:499:5: warning: 'throws' has incorrect indentation level 4, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
try {
validateProject(webSession, projectId);
//todo accumulate settings from user and team. For now just return team settings
return webSession.getSecurityController().getObjectSettings(
projectId,
SMObjectType.project,
ServletAppUtils.getServletApplication().getAppConfiguration().getDefaultUserTeam(),
settingId == null ? null : Set.of(settingId)
);
} catch (DBException e) {
throw new DBWebException("Error getting project settings", e);
}
}

@Override
public boolean deleteProjectSettings(@NotNull WebSession webSession, @NotNull String projectId, @Nullable List<String> settings)
throws DBWebException {

Check warning on line 516 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'throws' has incorrect indentation level 4, expected level should be 12. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java:516:5: warning: 'throws' has incorrect indentation level 4, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
try {
validateProject(webSession, projectId);
webSession.getSecurityController().deleteObjectSettings(
projectId,
SMObjectType.project,
settings == null ? null : new HashSet<>(settings)
);
return true;
} catch (DBException e) {
throw new DBWebException("Error deleting object settings", e);
}
}

@NotNull

Check warning on line 530 in server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '496'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java:530:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '496'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
@Override
public Map<String, Object> getProjectSettings(
@NotNull WebSession webSession,
@NotNull String projectId,
@Nullable String subjectId,
@Nullable String settingId
) throws DBWebException {
try {
var project = webSession.getProjectById(projectId);
if (project == null) {
throw new DBWebException("Project '" + projectId + "' not found");
}
validateProject(webSession, projectId);
return webSession.getSecurityController().getObjectSettings(
projectId,
SMObjectType.project,
settingId
subjectId,
settingId == null ? null : Set.of(settingId)
);
} catch (DBException e) {
throw new DBWebException("Error getting project settings", e);
Expand All @@ -495,16 +552,23 @@
public boolean addProjectSettings(
@NotNull WebSession webSession,
@NotNull String projectId,
@NotNull String subjectId,
@NotNull Map<String, Object> settings
) throws DBWebException {
try {
var project = webSession.getProjectById(projectId);
if (project == null) {
throw new DBWebException("Project '" + projectId + "' not found");
}
webSession.getSecurityController().setObjectSettings(
validateProject(webSession, projectId);
//fixme transactional
SMAdminController adminSecurityController = webSession.getAdminSecurityController();
adminSecurityController.deleteObjectSettings(
projectId,
SMObjectType.project,
subjectId,
settings.keySet()
);
adminSecurityController.setObjectSettings(
projectId,
SMObjectType.project,
subjectId,
settings
);
return true;
Expand All @@ -517,16 +581,15 @@
public boolean deleteProjectSettings(
@NotNull WebSession webSession,
@NotNull String projectId,
@NotNull String subjectId,
@Nullable List<String> settings
) throws DBWebException {
try {
var project = webSession.getProjectById(projectId);
if (project == null) {
throw new DBWebException("Project '" + projectId + "' not found");
}
webSession.getSecurityController().deleteObjectSettings(
validateProject(webSession, projectId);
webSession.getAdminSecurityController().deleteObjectSettings(
projectId,
SMObjectType.project,
subjectId,
settings == null ? null : new HashSet<>(settings)
);
return true;
Expand All @@ -535,6 +598,13 @@
}
}

private void validateProject(@NotNull WebSession webSession, @NotNull String projectId) throws DBWebException {
var project = webSession.getProjectById(projectId);
if (project == null) {
throw new DBWebException("Project '" + projectId + "' not found");
}
}

private RMController getResourceController(WebSession webSession) {
return webSession.getRmController();
}
Expand Down
Loading
Loading