Skip to content

Conversation

@mario-nt
Copy link
Contributor

@mario-nt mario-nt commented Mar 6, 2024

Resolves #448

@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 7c1a08f to 5eb405a Compare March 7, 2024 16:41
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 5eb405a to 0cba420 Compare March 11, 2024 23:28
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 0cba420 to dfb5b8e Compare March 18, 2024 11:32
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from dfb5b8e to 37e3eb9 Compare March 18, 2024 22:10
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 6506e68 to 90a82e0 Compare March 19, 2024 14:31
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 90a82e0 to c5bbf9f Compare March 20, 2024 10:51
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from c5bbf9f to 3144445 Compare March 20, 2024 12:05
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 3144445 to 51c9757 Compare March 20, 2024 12:12
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 51c9757 to 27c6b01 Compare March 20, 2024 15:13
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 27c6b01 to 30a113d Compare March 20, 2024 15:22
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 30a113d to b18da74 Compare March 20, 2024 15:28
@josecelano josecelano self-requested a review March 21, 2024 18:16
Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

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

Alternative draft implementation where the service knows the needed role (not the handler).

#546

Comment on lines 26 to 53
pub async fn authorize_user(&self, user_id: UserId, admin_required: bool) -> Result<(), ServiceError> {
// Checks if the user exists in the database
let authorization_info = self
.user_authorization_repository
.get_user_authorization_from_id(&user_id)
.await?;

//If admin privilages are required, it checks if the user is an admin
if admin_required {
Self::authorize_admin_user(&authorization_info)
} else {
Ok(())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Hi @mario-nt I think we should remove the admin_required parameter otherwise the handler has to know if the action must be performed by an admin. The main idea was removing the responsibility of knowing which role can do the task from the axum handlers.

This implementation extracts only part of the responsibility.

I have created a PR to show you what I had in mind for this issue:

#546

It's a lot of changes but only because I want to test the service and I wanted to create mocks for the user repository. But the service itself it's very simple. The main problem is all contexts are coupled with the authorization service for the time being. But we were discussing that. I think it's OK for now.

@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 1dfcbab to 9d8069d Compare May 28, 2024 14:22
@mario-nt mario-nt force-pushed the #448-move-authorization-logic-to-new-layer branch from 565ab57 to 9d8069d Compare May 28, 2024 15:04
@josecelano josecelano added the Needs Rebase Base Branch has Incompatibilities label Jun 3, 2024
josecelano added a commit that referenced this pull request Jun 4, 2024
478e234 feat: [#448] new authorization service implemented in the other services (Mario)
9ebd7b5 feat: [#448] new authorization service (Mario)
b1d5536 feat: [#448] new user repository trait (Mario)
a2ce990  feat: [#448] added mockall dependency (Mario)

Pull request description:

  Resolves #448.

  Replaces #520.

ACKs for top commit:
  josecelano:
    ACK478e2349f159da7d08b60382fd80a3f236067637

Tree-SHA512: ec93e9d95ff8b934397bd1bb13cc76077b33d2abd962bad0b667b134768066ed33aced0b174830eea7947a0e9f53273fe062147ee15342eaf1db8a5dfaaa3cfd
@mario-nt
Copy link
Contributor Author

mario-nt commented Jun 4, 2024

Superseded by #614

@josecelano
Copy link
Member

Hi @mario-nt can we close this? It looks pretty outdated.

@mario-nt
Copy link
Contributor Author

Hi @mario-nt can we close this? It looks pretty outdated.

Hi, yes, this was superseded as mentioned in #614

@josecelano
Copy link
Member

Hi @mario-nt can we close this? It looks pretty outdated.

Hi, yes, this was superseded as mentioned in #614

OK.

@josecelano josecelano closed this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Rebase Base Branch has Incompatibilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move authorization logic to new layer.

2 participants