Skip to content

Commit

Permalink
Merge pull request #1106 from ZakarFin/remove-old-code
Browse files Browse the repository at this point in the history
Remove unused code
  • Loading branch information
ZakarFin authored Jan 17, 2025
2 parents 376768d + e064538 commit 2f0371c
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void handlePut(ActionParameters params) throws ActionException {
.withMsg("Role")
.added(AuditLog.ResourceType.USER);
}
ResponseHelper.writeResponse(params, role2Json(role));
ResponseHelper.writeResponse(params, role.toJSON());
} catch (Exception se) {
throw new ActionException(se.getMessage(), se);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ private JSONObject roles2JsonArray(Role[] roles) throws JSONException {
final JSONArray roleValues = new JSONArray();
if (roles != null) {
for (Role role : roles) {
roleValues.put(role2Json(role));
roleValues.put(role.toJSON());
}
}

Expand All @@ -121,12 +121,4 @@ private JSONObject roles2JsonArray(Role[] roles) throws JSONException {

return response;
}

private JSONObject role2Json(Role role) throws JSONException {
JSONObject ro = new JSONObject();
ro.put("id", role.getId());
ro.put("name", role.getName());
return ro;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class LayerAdminMetadataHandlerTest extends JSONActionRouteTest {
@BeforeClass
public static void setup() throws Exception {
PropertyUtil.addProperty("oskari.user.service", DummyUserService.class.getCanonicalName(), true);
// So ViewsHandler doesn't try to connect to db
PropertyUtil.addProperty("view.default", "1", true);
setupPermissionsServiceMock();
TestHelper.registerTestDataSource();
handler.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class UserCredentialsTest extends JSONActionRouteTest {
public static void setup() throws Exception {
TestHelper.registerTestDataSource();
PropertyUtil.addProperty("oskari.user.service", DummyUserService.class.getCanonicalName(), true);
// So ViewsHandler doesn't try to connect to db
PropertyUtil.addProperty("view.default", "1", true);
}
@AfterClass
public static void tearDown() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* CRUD for layer and group order handling. Methods require admin user.
* @deprecated No longer used and is not flushing caches on updates
*/
@OskariActionRoute("LayerAndGroupOrder")
public class LayerAndGroupOrderHandler extends RestActionHandler {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.oskari.permissions.PermissionService;

import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

Expand All @@ -41,7 +42,6 @@ public class AppSetupHandler extends RestActionHandler {

private static final Logger LOG = LogFactory.getLogger(AppSetupHandler.class);

public static final String PROPERTY_DRAW_TOOLS_ENABLED = "actionhandler.Publish.drawToolsRoles";
static final String PROPERTY_VIEW_UUID = "oskari.publish.only.with.uuid";

static final String KEY_PUBDATA = "pubdata";
Expand Down Expand Up @@ -79,9 +79,6 @@ public class AppSetupHandler extends RestActionHandler {
private BundleService bundleService = null;
private PublishPermissionHelper permissionHelper = new PublishPermissionHelper();

private String[] drawToolsEnabledRoles = new String[0];


public void setMyPlacesService(final MyPlacesService service) {
permissionHelper.setMyPlacesService(service);
}
Expand Down Expand Up @@ -128,9 +125,6 @@ public void init() {
LOG.error(ex, "Publish template not available!!");
}

// setup roles authorized to enable drawing tools on published map
drawToolsEnabledRoles = PropertyUtil.getCommaSeparatedList(PROPERTY_DRAW_TOOLS_ENABLED);

final String[] configBundles = PropertyUtil.getCommaSeparatedList("actionhandler.AppSetup.bundles.simple");
if(configBundles.length > 0) {
LOG.info("Whitelisting more bundles due to configuration configured ", configBundles);
Expand All @@ -145,9 +139,7 @@ public void init() {
ViewModifier.BUNDLE_METADATACATALOGUE, ViewModifier.BUNDLE_METADATASEARCH, ViewModifier.BUNDLE_METADATAFLYOUT,
ViewModifier.BUNDLE_MAPROTATOR, ViewModifier.BUNDLE_MAPLEGEND, ViewModifier.BUNDLE_LAYERSWIPE,
ViewModifier.BUNDLE_ANNOUNCEMENTS));
for(String bundleId : configBundles) {
SIMPLE_BUNDLES.add(bundleId);
}
SIMPLE_BUNDLES.addAll(Arrays.asList(configBundles));

// List of bundles that the user is able to publish
// mapfull not included since it's assumed to be part of publisher template handled anyways
Expand All @@ -163,18 +155,18 @@ public void init() {
}

public void preProcess(ActionParameters params) throws ActionException {
// published maps are user content so only available for logged in users
// published maps are user content so only available for logged-in users
params.requireLoggedInUser();

// check permission if modifying existing view
final String viewUuid = params.getHttpParam(PARAM_UUID);
if(viewUuid == null) {
if (viewUuid == null) {
return;
}
// verify this is users own view
final View view = viewService.getViewWithConfByUuId(viewUuid);
final boolean hasPermission = viewService.hasPermissionToAlterView(view, params.getUser());
if(!hasPermission) {
if (!hasPermission) {
throw new ActionDeniedException("Not allowed to modify view with uuid: " + viewUuid);
}
}
Expand Down Expand Up @@ -226,7 +218,7 @@ protected View buildPublishedView(ActionParameters params) throws ActionExceptio

// setup view modifications
final JSONObject viewdata = publisherData.optJSONObject(KEY_VIEWCONFIG);
if(viewdata == null) {
if (viewdata == null) {
throw new ActionParamsException("Missing configuration for the view to be saved");
}

Expand All @@ -249,7 +241,7 @@ protected View buildPublishedView(ActionParameters params) throws ActionExceptio
if(viewdata.has(bundleid)) {
setupBundle(view, viewdata, bundleid, ALWAYSON_BUNDLES.contains(bundleid));

//toolbar -> add style info from metadata
// toolbar -> add style info from metadata
if (bundleid.equals(ViewModifier.BUNDLE_TOOLBAR)) {
setupToolbarStyleInfo(view);
}
Expand All @@ -259,18 +251,6 @@ protected View buildPublishedView(ActionParameters params) throws ActionExceptio
// reorder bundles - rpc bundle must have highest segment number
view.pushBundleLast(ViewModifier.BUNDLE_RPC);

// Setup publishedmyplaces2 bundle if user has configured it/has permission to do so
if(!user.hasAnyRoleIn(drawToolsEnabledRoles)) {
// remove myplaces functionality if user doesn't have permission to add them
Object drawTools = viewdata.remove(ViewModifier.BUNDLE_PUBLISHEDMYPLACES2);
if(drawTools != null) {
LOG.warn("User tried to add draw tools, but doesn't have any of the permitted roles. Removing draw tools!");
}
}

final Bundle myplaces = setupBundle(view, viewdata, ViewModifier.BUNDLE_PUBLISHEDMYPLACES2, false);
handleMyplacesDrawLayer(myplaces, user);

boolean isNew = view.getId() == -1;
AuditLog audit = AuditLog.user(params.getClientIp(), params.getUser())
.withParam("name", view.getName())
Expand All @@ -282,7 +262,7 @@ protected View buildPublishedView(ActionParameters params) throws ActionExceptio
View savedView = saveView(view);
// we might not have uuid before saving
audit.withParam("uuid", view.getUuid());
if(isNew) {
if (isNew) {
audit.added(AuditLog.ResourceType.EMBEDDED_VIEW);
} else {
audit.updated(AuditLog.ResourceType.EMBEDDED_VIEW);
Expand All @@ -291,6 +271,7 @@ protected View buildPublishedView(ActionParameters params) throws ActionExceptio
return savedView;
}

// TODO: is this still a thing?
private void setupToolbarStyleInfo(final View view) throws ActionParamsException {
final Bundle toolbarBundle = view.getBundleByName(ViewModifier.BUNDLE_TOOLBAR);
if (toolbarBundle == null) {
Expand Down
Loading

0 comments on commit 2f0371c

Please sign in to comment.