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

[Ready to merge] Create Event specific Roles, Services, Permissions #885

Merged
merged 6 commits into from
Jun 16, 2016

Conversation

shivamMg
Copy link
Member

@shivamMg shivamMg commented Jun 16, 2016

>>> from open_event.models.permission import Permission
>>> for p in Permission.query.all():
...  create = 'Create' if p.can_create else ''
...  read = 'Read' if p.can_read else ''
...  update = 'Update' if p.can_update else ''
...  delete = 'Delete' if p.can_delete else ''
...  print p.role, p.service, create, read, update, delete
... 
<Role u'organizer'> <Service u'track'> Create Read Update Delete
<Role u'organizer'> <Service u'session'> Create Read Update Delete
<Role u'organizer'> <Service u'speaker'> Create Read Update Delete
<Role u'organizer'> <Service u'sponsor'> Create Read Update Delete
<Role u'organizer'> <Service u'microlocation'> Create Read Update Delete
# 
<Role u'coorganizer'> <Service u'track'>  Read Update 
<Role u'coorganizer'> <Service u'session'>  Read Update 
<Role u'coorganizer'> <Service u'speaker'>  Read Update 
<Role u'coorganizer'> <Service u'sponsor'>  Read Update 
<Role u'coorganizer'> <Service u'microlocation'>  Read Update 
#
<Role u'track_organizer'> <Service u'track'>  Read Update 
#
<Role u'moderator'> <Service u'track'>  Read

The permissions printed above adhere to #623

Update 2:

User class has the following methods to check its role:

user.is_organizer(event_id)
user.is_coorganizer(event_id)
user.is_track_organizer(event_id)
user.is_moderator(event_id)
user.is_speaker(event_id)

Update 3:

User class has the following methods to check permissions:

user.can_create(service, event_id)
user.can_read(service, event_id)
user.can_update(service, event_id)
user.can_delete(service, event_id)

e.g.

>>> from open_event.models.user import User
>>> from open_event.models.track import Track
>>> u = User.query.all()[0]
>>> u.can_create(Track, event_id=1)
True
>>> u.can_update(Track, event_id=1)
True
>>> u.can_update(Track, event_id=2)
False

Service contains:

track
session
speaker
sponsor
microlocation

Role contains:

organizer
coorganizer
track_organizer
moderator
speaker

@rafalkowalski @aditya1702 It's ready to merge. Please review. After you migrate and upgrade, drop_db first and then create_db again. It will create the above mentioned roles and services, and permissions between them.

You can define a user's role for an event in UsersEventsRoles

>>> from open_event.models.users_events_roles import UsersEventsRoles as UER
>>> from open_event.models.user import User
>>> from open_event.models.event import Event
>>> from open_event.models.role import Role
>>> r = Role.query.filter_by(name='track_organizer').first()
>>> e = Event.query.get(1)
>>> from open_event.helpers.data import save_to_db
>>> u = User(email='asd@email.com')
>>> save_to_db(u, 'asfd')
True
>>> uer = UER(user=u, event=e, role=r)
>>> save_to_db(uer, 'asdf')
True
>>> from open_event.models.session import Session
>>> from open_event.models.track import Track
# 'u' is a track organizer and can only update and read tracks for an event.
>>> u.can_delete(Track, 1)
False
>>> u.can_create(Track, 1)
False
>>> u.can_read(Track, 1)
True
>>> u.can_update(Track, 1)
True
>>> u.can_delete(Track, 1)
False

@shivamMg shivamMg self-assigned this Jun 16, 2016
@shivamMg shivamMg changed the title Create Event specific Roles, Services, Permissions [Do not merge] Create Event specific Roles, Services, Permissions Jun 16, 2016
@mariobehling
Copy link
Member

Checks are failing. Please check.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 79.345% when pulling dd47abd on shivamMg:perm-sys/create-fix into dee72b3 on fossasia:development.

@shivamMg
Copy link
Member Author

shivamMg commented Jun 16, 2016

@mariobehling I'm doing it in three parts:

  • Create event-specific roles (create db models)
  • Define event-specific methods for User
  • Define service-permission methods for User Done!

I'll fix tests all at once.

@codecov-io
Copy link

codecov-io commented Jun 16, 2016

Current coverage is 78.99%

Merging #885 into development will decrease coverage by 0.27%

@@           development       #885   diff @@
=============================================
  Files              105        106     +1   
  Lines             4582       4637    +55   
  Methods              0          0          
  Messages             0          0          
  Branches             0          0          
=============================================
+ Hits              3632       3663    +31   
- Misses             950        974    +24   
  Partials             0          0          

Powered by Codecov. Last updated by dee72b3...e1583e6

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 78.995% when pulling e1583e6 on shivamMg:perm-sys/create-fix into dee72b3 on fossasia:development.

@shivamMg shivamMg changed the title [Do not merge] Create Event specific Roles, Services, Permissions [Ready to merge] Create Event specific Roles, Services, Permissions Jun 16, 2016
@rafalkowalski rafalkowalski merged commit c772f36 into fossasia:development Jun 16, 2016
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.

5 participants