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

O3-3002: Queue Module - REST endpoints can be accessed without authentication. #65

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

IamMujuziMoses
Copy link
Contributor

@IamMujuziMoses IamMujuziMoses commented Mar 28, 2024

Issue I worked on

see https://issues.openmrs.org/browse/O3-3002

Checklist: I completed these to help reviewers :)

  1. Added Authorized annotations to the service classes: QueueService, QueueEntryService, QueueRoomService and RoomProviderMapService.
  2. Created PrivilegeConstants class to contain all privilege names and their descriptions.

* AddOnStartup annotation.
*
* @see org.openmrs.annotation.AddOnStartup
* @since 1.8
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I have never seen version 1.8 of this module 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my bad, let me fix that, just to be clear, is 2.4.0 the current version?!

Copy link
Member

Choose a reason for hiding this comment

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

true dat!

Copy link

@TamtoMefotieJunie TamtoMefotieJunie left a comment

Choose a reason for hiding this comment

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

i think we can consider organizing the privilege constants in a logical order, such as alphabetically or by functionality, to improve readability and maintainability.

@dkayiwa
Copy link
Member

dkayiwa commented Apr 4, 2024

@IamMujuziMoses can you always include a link to the ticket as advised at? https://wiki.openmrs.org/display/docs/Pull+Request+Tips

Is there a reason why you added privileges to only some of the service methods instead of all?

@IamMujuziMoses
Copy link
Contributor Author

@dkayiwa the reason I had was that those methods that didn't get privileges called the methods that had privileges e.g. the QueueService method createQueue on which I didn't add privileges instead called saveQueue on which I added privileges, so I thought it wouldn't be necessary. Should I also add privileges on createQueue?!

@dkayiwa
Copy link
Member

dkayiwa commented Apr 4, 2024

The method's internal implementation details should not affect its public contract. By looking at createQueue i should know the required privilges without looking at its implementation details. Not so? 😊

@IamMujuziMoses
Copy link
Contributor Author

right, okay got it

@dkayiwa
Copy link
Member

dkayiwa commented Apr 4, 2024

right, okay got it

Can you do it also for other services in the module?

@IamMujuziMoses IamMujuziMoses requested a review from dkayiwa April 4, 2024 17:02
@HasAddOnStartupPrivileges
public class PrivilegeConstants {

// Add Privilege Constants
Copy link
Member

Choose a reason for hiding this comment

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

Do these comments add any value?


public interface QueueEntryService {
public interface QueueEntryService extends OpenmrsService {
Copy link
Member

Choose a reason for hiding this comment

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

@IamMujuziMoses is extending OpenmrsService related to this ticket?

@@ -45,6 +49,7 @@ public interface QueueService {
* @param queue the queue to be saved
* @return saved {@link org.openmrs.module.queue.model.Queue}
*/
@Authorized({ PrivilegeConstants.ADD_QUEUES, PrivilegeConstants.EDIT_QUEUES })
Copy link
Member

@dkayiwa dkayiwa Apr 11, 2024

Choose a reason for hiding this comment

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

Does the above require edit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think since it delegates saveQueue(), it should also requires the same privileges.

@@ -53,16 +58,19 @@ public interface QueueService {
* @param queue the queue to be saved
* @return saved {@link org.openmrs.module.queue.model.Queue}
*/
@Authorized({ PrivilegeConstants.ADD_QUEUES, PrivilegeConstants.EDIT_QUEUES })
Copy link
Member

Choose a reason for hiding this comment

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

Could there be a reason why for this service you are doing Add and Edit and yet for others you are doing Manage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

saveQueue() is used to both update and add new queues, so different privileges must be required, ergo the Add and Edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but I have realized that Manage also provides both the Add and Edit privileges at once which is better, let me change that, thanks🙂

@@ -135,5 +146,6 @@ String generateVisitQueueNumber(@NotNull Location location, @NotNull Queue queue
* @return the previous queue entry, null otherwise.
* @throws IllegalStateException if multiple previous queue entries are identified
*/
@Authorized({ PrivilegeConstants.GET_QUEUE_ENTRIES })
Copy link
Member

@dkayiwa dkayiwa Apr 11, 2024

Choose a reason for hiding this comment

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

How about the rest of the methods in this interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do the methods like generateVisitQueueNumber(), getSortWeightGenerator() and setSortWeightGenerator() require privileges as well?!

Copy link
Member

@dkayiwa dkayiwa Apr 11, 2024

Choose a reason for hiding this comment

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

Do you want them to be accessed without login?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely not. okay let me work on them.

@@ -9,6 +9,8 @@
*/
package org.openmrs.module.queue.api;

import static org.openmrs.util.PrivilegeConstants.*;
Copy link
Member

Choose a reason for hiding this comment

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

void closeActiveQueueEntries();

/**
* @return the instance of SortWeightGenerator that is configured via global property, or null if
* none configured
*/
@Authorized({ GET_GLOBAL_PROPERTIES })
Copy link
Member

Choose a reason for hiding this comment

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

This permission is too generic. Should anyone who can access global properties also have access to this?

@@ -124,6 +143,7 @@ String generateVisitQueueNumber(@NotNull Location location, @NotNull Queue queue
*
* @param sortWeightGenerator the SortWeightGenerator to set
*/
@Authorized({ MANAGE_GLOBAL_PROPERTIES })
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

@@ -9,6 +9,9 @@
*/
package org.openmrs.module.queue.api;

import static org.openmrs.util.PrivilegeConstants.ADD_VISITS;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to import static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought it was better than using canonical name in the @Authorized tag.

Long getCountOfQueueEntries(@NotNull QueueEntrySearchCriteria searchCriteria);

/**
* @param location
* @param queue
* @return VisitQueueNumber - used to identify patients in the queue instead of using patient name
*/
@Authorized({ ADD_VISITS, EDIT_VISITS })
Copy link
Member

@dkayiwa dkayiwa Apr 16, 2024

Choose a reason for hiding this comment

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

Why not use the manage privilege for the items where the visit queue number is used?

Copy link
Member

Choose a reason for hiding this comment

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

After looking at the implementation details of this method, i think your privileges are correct. 😊

Copy link
Member

Choose a reason for hiding this comment

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

Instead of import static, how about directly using org.openmrs.util.PrivilegeConstants.ADD_VISITS and org.openmrs.util.PrivilegeConstants.EDIT_VISITS

Optional<QueueRoom> getQueueRoomById(@NotNull int id);

/**
* @return {@link List} of all queue rooms
Copy link
Member

Choose a reason for hiding this comment

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

Though this ticket was not about documenting these methods, you decided to do so and hence should also include the method description. 😊


public interface QueueRoomService {

/**
* Gets a queue room given uuid.
Copy link
Member

Choose a reason for hiding this comment

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

given a uuid

QueueRoom saveQueueRoom(@NotNull QueueRoom queueRoom);

/**
Copy link
Member

Choose a reason for hiding this comment

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

Same as above for the method description.

List<QueueRoom> getQueueRooms(QueueRoomSearchCriteria searchCriteria);

/**
* Voids a queue room
Copy link
Member

Choose a reason for hiding this comment

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

Void and Retire are not the same.

* Voids a queue room
*
* @param queueRoom the queue room to retire
* @param voidReason the reason for voiding the queue room
Copy link
Member

Choose a reason for hiding this comment

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

It would be a retireReason instead of voidReason.


public interface RoomProviderMapService {

/**
* Gets a room provider map given uuid.
Copy link
Member

Choose a reason for hiding this comment

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

given a uuid

/**
* Gets a room provider map by id.
*
* @param id roomProviderMapId - the id of the room provider map to retrieve.
Copy link
Member

Choose a reason for hiding this comment

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

Is the param id or roomProviderMapId?

RoomProviderMap saveRoomProviderMap(@NotNull RoomProviderMap roomProviderMap);

/**
Copy link
Member

Choose a reason for hiding this comment

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

Description missing.

List<RoomProviderMap> getAllRoomProviderMaps();

/**
Copy link
Member

Choose a reason for hiding this comment

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

Description missing.

/**
* Voids a room provider map
*
* @param roomProviderMap the room provider map to retire
Copy link
Member

Choose a reason for hiding this comment

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

retire and void are not the same.

@IamMujuziMoses IamMujuziMoses requested a review from dkayiwa April 16, 2024 18:35
@dkayiwa dkayiwa merged commit 43117c9 into openmrs:main Apr 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants