Skip to content

Allow AuthorizationHandlers to customize authorization status check process#2438

Merged
mrcasals merged 8 commits intodecidim:masterfrom
podemos-info:enhancement/improved-authorizations-step2
Jan 12, 2018
Merged

Allow AuthorizationHandlers to customize authorization status check process#2438
mrcasals merged 8 commits intodecidim:masterfrom
podemos-info:enhancement/improved-authorizations-step2

Conversation

@leio10
Copy link
Copy Markdown
Contributor

@leio10 leio10 commented Jan 4, 2018

🎩 What? Why?

This change is the second part of #2435, explained in #2314. It adds a DefaultActionAuthorizer class with public methods that could be overriden by child classes. The class to be used for each handler is defined in the handler's WorkflowManifest.

Most of the logic of the status_data method of the ActionAuthorizer class was moved to the authorize method of the new class.

More than the half of the effort of this PR was to allow authorization handler to inform the user about the implemented logic, this include:

  • Allow to define new status codes, with all it related translations. Authorization modals view was refactored to implement this.
  • Show additional messages to the user. This change is also included in authorization modals view changes.
  • Allow forms to change behavior based on the authorization options. These options are added to query string when redirecting the user to the form.

A future PR should allow authorization handlers to define forms for options setting and avoid admin users to learn JSON.

📌 Related Issues

📋 Subtasks

  • Add hooks
  • Add an example of use
  • Complete tests
  • Update docs and changelog

📷 Screenshots (optional)

admin
modal
form

👻 GIF

hook

@leio10 leio10 force-pushed the enhancement/improved-authorizations-step2 branch from 9f2f426 to 8c9b635 Compare January 4, 2018 18:48
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 4, 2018

Codecov Report

Merging #2438 into master will increase coverage by <.01%.
The diff coverage is 99.31%.

@@            Coverage Diff             @@
##           master    #2438      +/-   ##
==========================================
+ Coverage   98.68%   98.69%   +<.01%     
==========================================
  Files        1296     1297       +1     
  Lines       30363    30354       -9     
==========================================
- Hits        29964    29958       -6     
+ Misses        399      396       -3

@leio10 leio10 force-pushed the enhancement/improved-authorizations-step2 branch 6 times, most recently from 1e92d7c to 464d13e Compare January 5, 2018 16:47

module Decidim
module Verifications
class Hooks
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be called DefaultHooks, as it comes with a default implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, not sure about hook as a name for this abstraction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about calling it DefaultAuthorizationHandlerAuthorizer? it is a little long, but I think is the most accurate name, since it provides the logic for ActionAuthorizer that is inside the specific authorization handler. I would also change all references to hooks with authorizer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about using DefaultActionAuthorizer and action_authorizer as a method name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will prepare that change. 👍

These are particulary useful when used within verification options, which are
set in the admin zone related to a feature action. As a result, a verification
method will be allowed to change the authorization logic and the appearance based
on the context where the authorization is being performed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe mention an example so a developer or a user can understand its value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And also an example on how to set it at the admin zone (like the screenshot)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you think about this? I'm not very good in english developer-human communications, any help would be very appreciated. 😅

oriolgual
oriolgual previously approved these changes Jan 8, 2018
Copy link
Copy Markdown
Contributor

@oriolgual oriolgual left a comment

Choose a reason for hiding this comment

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

Nice work!

oriolgual
oriolgual previously approved these changes Jan 8, 2018
Copy link
Copy Markdown
Contributor

@oriolgual oriolgual left a comment

Choose a reason for hiding this comment

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

Works for me!

@leio10 leio10 force-pushed the enhancement/improved-authorizations-step2 branch from 3a0f03e to 689c6aa Compare January 8, 2018 15:03
oriolgual
oriolgual previously approved these changes Jan 9, 2018
@ghost ghost assigned mrcasals Jan 9, 2018
@ghost ghost added the in-progress label Jan 9, 2018
@leio10 leio10 force-pushed the enhancement/improved-authorizations-step2 branch 2 times, most recently from 4dca389 to ddca15c Compare January 10, 2018 13:32
@mrcasals
Copy link
Copy Markdown
Contributor

@leio10 is this ready for reviews?

@mrcasals mrcasals removed their assignment Jan 12, 2018
@leio10 leio10 force-pushed the enhancement/improved-authorizations-step2 branch from ddca15c to c972392 Compare January 12, 2018 08:51
@leio10
Copy link
Copy Markdown
Contributor Author

leio10 commented Jan 12, 2018

@mrcasals it should be ready to merge now.
The root of the conflicts is the changelog file, because I'm trying to fix a typo in the markdown used to refer to the related PR in the last six entries: we are using [\1234] instead of [\#1234]. Everyone is copying the format from last entry in the CHANGELOG, so everyone is making the same mistake 🙈. So, it will be mergeable until the next merge to the master, when conflicts will appear again.

@mrcasals
Copy link
Copy Markdown
Contributor

@leio10 LOL thanks!! I'm gonna review it and hopefully we can merge this without any other conflicts!

@leio10
Copy link
Copy Markdown
Contributor Author

leio10 commented Jan 12, 2018

@mrcasals It seems that codecov is stuck with this PR 😢

@mrcasals
Copy link
Copy Markdown
Contributor

@leio10 shhhhhhhhh 🤐

@mrcasals mrcasals merged commit dc04987 into decidim:master Jan 12, 2018
@ghost ghost removed the in-progress label Jan 12, 2018
@mrcasals
Copy link
Copy Markdown
Contributor

Merged! 🎉

About CodeCov, it's not the first time it gets stuck, and in some other PRs we've skipped the checks and merged the Pr anyway.

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.

4 participants