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

TAN-852 - Permissions service refactor #7844

Merged
merged 74 commits into from
May 22, 2024

Conversation

jamesspeake
Copy link
Contributor

@jamesspeake jamesspeake commented May 8, 2024

A refactor from 2 services with too many methods and mixed focus:

  • PermissionsService
    • ParticipationPermissionsService

To 7 services - namespaced in Permissions:::

  • PermissionsUpdateService - Dedicated to updating permissions
  • UserRequirementsService - Just the logic for return flexible registration requirements
  • BasePermissionsService - 2 methods denied_reason_for_action & action_descriptors - all other classes then inherit and extend these methods
    • InitiativesPermissionsService
    • PhasePermissionsService
      • ProjectPermissionsService
      • IdeaPermissionsService

Action descriptors are now generated via a method on the PermissionsServices instead of directly in the serializer.

Further documentation can be found here - https://www.notion.so/citizenlab/Permissions-service-d0e193dc551949a3bdc60dd0c500d75d

Changelog

Technical

  • Refactored permissions services to reduce duplication and make denied reasons for actions clearer
  • Performance improvements to action descriptors, projects and ideas endpoints

@@ -48,7 +48,7 @@ def index_mini
).find_records
ideas = paginate SortByParamsService.new.sort_ideas(ideas, params, current_user)

render json: linked_json(ideas, WebApi::V1::IdeaMiniSerializer, params: jsonapi_serializer_params(pcs: ParticipationPermissionsService.new))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the permissions service entirely as the mini serializer doesn't use it

include: include
}
else
{
params: jsonapi_serializer_params(pcs: ParticipationPermissionsService.new),
params: jsonapi_serializer_params(pcs: IdeaPermissionsService.new),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not clear if there is any benefit in passing the service in as a param, but have left it for now

@cl-dev-bot
Copy link
Collaborator

cl-dev-bot commented May 8, 2024

Warnings
⚠️ The PR title contains no Jira issue key (case-sensitive)
⚠️ The branch name contains no Jira issue key (case-sensitive)
Messages
📖 Changelog provided 🎉
📖

Run the e2e tests

📖 Check translation progress

Generated by 🚫 dangerJS against bc13dbe

@@ -94,3 +94,18 @@
end

ActiveJob::Base.queue_adapter = :test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hadn't meant to check this in yet - but this is a method I've added which I was going to use to help analyse where the performance blocks are within the permissions code

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we delete it now?

@jamesspeake jamesspeake added this to the Permissions & Auth milestone May 8, 2024
@@ -272,7 +272,7 @@ def anonymous_not_allowed?

case @post_type
when 'Idea'
!ParticipationPermissionsService.new.get_current_phase(@comment.post.project).allow_anonymous_participation
!TimelineService.new.current_phase_not_archived(@comment.post.project).allow_anonymous_participation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this method from permissions into the timeline service where it belongs


module Permissions
class PermissionsService
USER_DENIED_REASONS = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a mix of language between 'denied reason' and 'disabled reason'. Decided to go with 'denied' until the output of the action descriptor - where it changes to disabled as that's what the FE is expecting

jamesspeake and others added 29 commits May 16, 2024 09:51
…cludes data and eliminate 2 queries per action descriptor
…rformance-users-etc

TAN-1813 - Permissions performance (2)
…rformance

TAN-1813 - Permissions performance improvements (1)
# Conflicts:
#	back/spec/acceptance/ideas_spec.rb
@jamesspeake jamesspeake merged commit 10d46fb into master May 22, 2024
10 checks 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.

None yet

3 participants