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

Feature custom grant types #37

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Conversation

flbulgarelli
Copy link
Member

@flbulgarelli flbulgarelli commented May 17, 2019

This PR refactors in a non backward-compatible way some important slugs and grants semantics:

  • Grants can not be converted to slugs anymore - to_mumukit_slug was removed
  • */*-like strings are not a valid slugs anymore
  • _/_-like strings are not valid grants anymore
  • Permissions.has_permissions? has been deprecated
  • Several methods have being renamed
  • Now it is possible to define new custom grants
  • Authorization of slugs and grants is now split into two different methods: allows? and includes?
  • authorized_by? is now provided as a way to use slugs and grant polymorphically, using a double dispatch
  • Validation messages have been improved
  • Now granted_organizations is provided as a way to tell which are the explicitly granted organizations for a grant, instead of depending on to_mumukit_slug

@flbulgarelli flbulgarelli force-pushed the feature-custom-grant-types branch from 319c607 to 26ea92d Compare May 21, 2019 16:35
@flbulgarelli flbulgarelli marked this pull request as ready for review May 22, 2019 16:05
grant = grant_like.to_mumukit_grant
case grant
when FirstPartGrant then grant.first == first
when SingleGrant then grant.slug.first == first
Copy link
Contributor

Choose a reason for hiding this comment

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

We could delegate first to slug in SingleGrant and compact this two lines like:

when FirstPartGrant, SingleGrant then grant.first == first

true
end

def includes?(_)
Copy link
Contributor

@luchotc luchotc May 28, 2019

Choose a reason for hiding this comment

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

_grant_like to make it more explicit?

@@ -114,7 +133,7 @@ def match(pattern, part)

def self.validate_slug!(slug)
unless slug =~ /\A[^\/\n]+\/[^\/\n]+\z/
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should use SLUG_REGEXP here now?

Copy link
Contributor

Choose a reason for hiding this comment

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

This one is checking for SOMETHING/SOMETHING while the other one is checking the validity of that SOMETHING as far as I understand. Using SLUG_REGEXP as part of this validation, wouldn't make this one more restrictive and the other validations obsolete? (You are the king of regex, so correct me if I'm wrong).

I do agree that it feels quite odd that the validations are distributed between this method and the initialization.

Copy link
Member

Choose a reason for hiding this comment

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

I do agree that it feels quite odd that the validations are distributed between this method and the initialization.

right, that's what I was going for, it seems odd that we're doing two different regexp validations over the same thing. We could end up with cases where, for a given slug, initialize fails but validate_slug! passes... isn't that weird?

Copy link
Member

@julian-berbel julian-berbel May 28, 2019

Choose a reason for hiding this comment

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

I was thinking we could just replace the [^\/\n] parts in this regex with a SLUG_REGEXP interpolation, but I just noticed that would cause trouble because SLUG_REGEXP is anchored... maybe we could do something like

SLUG_PART = /[[[:alnum:]]_ .-]+/
ANCHORED_SLUG_PART = /^#{SLUG_PART}$/
SLUG_REGEXP = /^#{SLUG_PART}\/#{SLUG_PART}$/

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not even sure we actually need this method 🤷‍♂️

@luchotc
Copy link
Contributor

luchotc commented Aug 6, 2019

@flbulgarelli This PR is very close to be finished.
Do you have time to finish it or do you prefer that any of us continue it?

@flbulgarelli
Copy link
Member Author

Go ahead! I don't think i will be able to work on it soon

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