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/grant_CREATE_to_collaborator #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/browser/templates/repo-settings.html
Expand Up @@ -83,6 +83,11 @@ <h4>Add Collaborators</h4>
<input type="checkbox" name="db_privileges" value="TRIGGER" checked/> trigger
</label>
</div>
<div class="checkbox">
<label title="Allows ability to create tables in the repo.">
<input type="checkbox" name="db_privileges" value="CREATE" checked/> create
</label>
</div>
<p class="help-block">Permissions for repo files:</p>
<div class="checkbox">
<label title="Allows read access to files and cards in the repo">
Expand Down
15 changes: 15 additions & 0 deletions src/core/db/backend/pg.py
Expand Up @@ -208,6 +208,12 @@ def add_collaborator(self, repo, collaborator, db_privileges=[]):
for privilege in db_privileges:
self._check_for_injections(privilege)

grantCreatePrivilege = False
if 'CREATE' in db_privileges:
grantCreatePrivilege = True
db_privileges.remove('CREATE')


query = ('BEGIN;'
'GRANT USAGE ON SCHEMA %s TO %s;'
'GRANT %s ON ALL TABLES IN SCHEMA %s TO %s;'
Expand All @@ -221,6 +227,15 @@ def add_collaborator(self, repo, collaborator, db_privileges=[]):
collaborator, repo, privileges_str, collaborator]
params = tuple(map(lambda x: AsIs(x), params))
res = self.execute_sql(query, params)

query = ('BEGIN;'
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that this grants CREATE to all users when added as collaborators. There's no check grantCreatePrivilege's value.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also has one too many spaces, though that's more of a silly codeclimate issue.
https://codeclimate.com/github/datahuborg/datahub/pull/204

'GRANT CREATE ON SCHEMA %s TO %s;'
'COMMIT;'
)
params = [repo, collaborator]
params = tuple(map(lambda x: AsIs(x), params))
res = self.execute_sql(query, params)

return res['status']

def delete_collaborator(self, repo, collaborator):
Expand Down
2 changes: 1 addition & 1 deletion src/core/db/manager.py
Expand Up @@ -395,7 +395,7 @@ def add_collaborator(

invalid_db_privileges = set(db_privileges) - {
'SELECT', 'INSERT', 'UPDATE', 'DELETE',
'TRUNCATE', 'REFERENCES', 'TRIGGER'}
'TRUNCATE', 'REFERENCES', 'TRIGGER', 'CREATE'}
if len(invalid_db_privileges) > 0:
raise ValueError(
"Unsupported db privileges: \"{0}\"".format(
Expand Down