Skip to content

Conversation

@shreyanshdwivedi
Copy link
Member

Fixes #6001

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

Short description of what this resolves:

Currently, owners of the event cannot be differentiated. So organizer event role is to be changed to owner, to differentiate and make it clear

Changes proposed in this pull request:

Adds event owner role to the system

@auto-label auto-label bot added the feature label Jun 13, 2019
@fossasia fossasia deleted a comment Jun 13, 2019
@fossasia fossasia deleted a comment Jun 13, 2019
@shreyanshdwivedi shreyanshdwivedi changed the title feat: Adds event owner role to the system [WIP] feat: Adds event owner role to the system Jun 13, 2019
@auto-label auto-label bot removed the feature label Jun 13, 2019
@shreyanshdwivedi
Copy link
Member Author

@iamareebjamal I wanted to ask on thing. How are we storing roles in db? I see 6 roles in db but couldn't find any migration which adds those roles.
I want to update the roles table and insert owner at id=1. Can you please give me a little background?

@abhinavk96
Copy link
Contributor

abhinavk96 commented Jun 13, 2019 via email

@fossasia fossasia deleted a comment Jun 13, 2019
@shreyanshdwivedi
Copy link
Member Author

Actually there are a few tables where id 1 is being used to associate event and role. So I thought I could add a role at id 1 which will automatically make the user the owner. I thought I could do it in a single go.
However now I feel that there might be more than 1 organizer in production and there can be only one owner. So this will not be good.
I will add role and use its id to make 1st organizer the event owner.

@abhinavk96
Copy link
Contributor

abhinavk96 commented Jun 13, 2019 via email

@iamareebjamal
Copy link
Member

I believe the roles are created in the create DB script

This is problematic

Make a non conflicting migration for it

@abhinavk96
Copy link
Contributor

@shreyanshdwivedi here,

def create_roles():

@shreyanshdwivedi
Copy link
Member Author

@CosmicCoder96 yes I got that earlier but how will it reflect in my db because changing it is not affecting my roles table.
I think I'll have to make a migration file to add roles in db as mentioned by @iamareebjamal above. But if the order of the roles will change, their ids will changes and other tables which stores id of roles will be affected.
I'll check what I can do to avoid any conflicts

@abhinavk96
Copy link
Contributor

@shreyanshdwivedi @iamareebjamal I don't think looking up for roles using their ID is ever a good idea, their name or slug is their distinguishing factor, shouldn't they be referred to using that, in which case this task can be merely reduced to adding the owner role in the populate script, and writing a migration which adds the role of owner, IF no other role with the name owner exists.

@shreyanshdwivedi Can you point me to where

Actually there are a few tables where id 1 is being used to associate event and role

I think they should be replaced with

role = Role.query.filter_by(name=ORGANIZER).first()

Like it has been used at some places in the app. (This example is from the events API).

@shreyanshdwivedi
Copy link
Member Author

@CosmicCoder96 you can refer to users_events_roles table in db for instance where event_id, user_id and role_id are the columns.

@abhinavk96
Copy link
Contributor

@shreyanshdwivedi For the legacy data, for each event, in the user events table the record which was inserted first (with an organizer relationship), denotes the creator of the event. You can leave the original data as is, create a migration to add owner role if it does not exist in roles table, and also add it to the end of populate db file. Next, add a migration to find the implicit creator of the event, (using the above logic), find the id of the entry in roles table whose name is 'OWNER' and insert into user_events_roles table the user_id, role_id(for the owner, whatever it may be ) and the event ID. What do you think?

@shreyanshdwivedi
Copy link
Member Author

I totally agree to the steps you suggested. Just one thing, when we find out the owner of the event, I'll suggest to update the role_id of the entry in users_events_roles table rather than inserting a new one as it may lead to confusion later. If we update the role_id only, it'll be better. Does it sound correct?

@abhinavk96
Copy link
Contributor

abhinavk96 commented Jun 14, 2019 via email

@shreyanshdwivedi
Copy link
Member Author

@CosmicCoder96 yes. An event owner will have all the rights of an organizer just like an organizer has all the rights of a coorganizer but the roles will still be different. Later we will provide more rights to the owner

@fossasia fossasia deleted a comment Jun 14, 2019
@fossasia fossasia deleted a comment Jun 14, 2019
@fossasia fossasia deleted a comment Jun 14, 2019
@fossasia fossasia deleted a comment Jun 14, 2019
@fossasia fossasia deleted a comment Jun 14, 2019
@fossasia fossasia deleted a comment Jul 1, 2019
@shreyanshdwivedi
Copy link
Member Author

@uds5501 @iamareebjamal plz review

Copy link
Member

@iamareebjamal iamareebjamal left a comment

Choose a reason for hiding this comment

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

Change function name

adds migration file

Updates migration to add owner and update role

Updates docs

fix hound errors
@shreyanshdwivedi
Copy link
Member Author

@iamareebjamal did the changes. Please review

@fossasia fossasia deleted a comment Jul 1, 2019
@fossasia fossasia deleted a comment Jul 1, 2019
iamareebjamal
iamareebjamal previously approved these changes Jul 1, 2019
@shreyanshdwivedi
Copy link
Member Author

@CosmicCoder96 please review

abhinavk96
abhinavk96 previously approved these changes Jul 2, 2019
@fossasia fossasia deleted a comment Jul 2, 2019
@fossasia fossasia deleted a comment Jul 2, 2019
@iamareebjamal
Copy link
Member

Fix Travis Build

@iamareebjamal
Copy link
Member

Most probably due to split migration heads, and the script did not fail correctly

@shreyanshdwivedi
Copy link
Member Author

Yeah I'll have to update the migration to recent merged one
Error: Multiple heads are present; please specify a single target revision is in travis failure

@shreyanshdwivedi shreyanshdwivedi dismissed stale reviews from abhinavk96 and iamareebjamal via 4b7a324 July 2, 2019 07:56
@fossasia fossasia deleted a comment Jul 2, 2019
@fossasia fossasia deleted a comment Jul 2, 2019
@shreyanshdwivedi
Copy link
Member Author

@CosmicCoder96 @iamareebjamal please review

@iamareebjamal iamareebjamal merged commit 41c1deb into fossasia:development Jul 2, 2019
@shreyanshdwivedi shreyanshdwivedi deleted the addOwnerRole branch July 2, 2019 09:46
iamareebjamal pushed a commit to iamareebjamal/open-event-server that referenced this pull request Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce event owner user role

8 participants