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

RESTWS-941: Any authenticated user should be able to read available modules #610

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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 @@ -88,7 +88,7 @@ public Object create(SimpleObject post, RequestContext context) throws ResponseE
throw new IllegalRequestException("Cannot execute action " + action.getAction() + " on empty set of modules.");
} else {
if (action.getAction() == Action.INSTALL) {
if (installUri == null || !ResourceUtils.isUrl(installUri)) {
if (!ResourceUtils.isUrl(installUri)) {
throw new IllegalRequestException("The installUri needs to be a URL for this action to be performed");
}
}
Expand Down Expand Up @@ -171,11 +171,7 @@ private Module installModule(Collection<Module> modules, String installUri, Serv
}
catch (MalformedURLException e) {
throw new APIException(e.getMessage(), e);
}
catch (IOException e) {
throw new APIException(e.getMessage(), e);
}
finally {
} finally {
if (tempModule == null && moduleFile != null) {
FileUtils.deleteQuietly(moduleFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public class ModuleResource1_8 extends BaseDelegatingReadableResource<Module> im

private ModuleFactoryWrapper moduleFactoryWrapper = new ModuleFactoryWrapper();

private String moduleActionLink = ModuleActionResource1_8.class.getAnnotation(Resource.class).name();
private final String moduleActionLink = ModuleActionResource1_8.class.getAnnotation(Resource.class).name();

public void setModuleFactoryWrapper(ModuleFactoryWrapper moduleFactoryWrapper) {
this.moduleFactoryWrapper = moduleFactoryWrapper;
}

@Override
public Module getByUniqueId(String uniqueId) {
moduleFactoryWrapper.checkPrivilege();
moduleFactoryWrapper.checkReadonlyPrivilege();
return moduleFactoryWrapper.getModuleById(uniqueId);
}

Expand Down Expand Up @@ -136,11 +136,11 @@ public Model getGETModel(Representation rep) {
}

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingReadableResource#doGetAll(RequestContext)
*/
@Override
public NeedsPaging<Module> doGetAll(RequestContext context) throws ResponseException {
moduleFactoryWrapper.checkPrivilege();
moduleFactoryWrapper.checkReadonlyPrivilege();
return new NeedsPaging<Module>(new ArrayList<Module>(moduleFactoryWrapper.getLoadedModules()), context);
}

Expand Down Expand Up @@ -185,7 +185,7 @@ public Object upload(MultipartFile file, RequestContext context) throws Response
module = moduleFactoryWrapper.loadModule(moduleFile);
moduleFactoryWrapper.startModule(module, servletContext);

if (existingModule != null && dependentModulesStopped.size() > 0
if (existingModule != null && !dependentModulesStopped.isEmpty()
&& moduleFactoryWrapper.isModuleStarted(module)) {
startModules(dependentModulesStopped, existingModule, servletContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@ public void checkPrivilege() throws APIAuthenticationException {
throw new APIAuthenticationException("Privilege required: " + PrivilegeConstants.MANAGE_MODULES);
}
}

public void checkReadonlyPrivilege() throws APIAuthenticationException {
if (!Context.isAuthenticated()) {
throw new APIAuthenticationException("User must be authenticated");
}
}
}
Loading