-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from EverythingMe/feature_roles
Feature: basic permissions system
- Loading branch information
Showing
12 changed files
with
126 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from playhouse.migrate import Migrator | ||
from redash import db | ||
from redash import models | ||
|
||
|
||
if __name__ == '__main__': | ||
db.connect_db() | ||
migrator = Migrator(db.database) | ||
with db.database.transaction(): | ||
migrator.add_column(models.User, models.User.permissions, 'permissions') | ||
models.User.update(permissions=['admin'] + models.User.DEFAULT_PERMISSIONS).where(models.User.is_admin == True).execute() | ||
|
||
db.close_db(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="form-group"> | ||
<label class="control-label">Time Label</label> | ||
<input type="text" class="form-control" ng-model="cohortOptions.timeLabel"> | ||
<label class="control-label">People Label</label> | ||
<input type="text" class="form-control" ng-model="cohortOptions.peopleLabel"> | ||
|
||
<label class="control-label">Bucket Column</label> | ||
<select ng-model="bucket_column" ng-options="value as key for (key, value) in columns" class="form-control"></select> | ||
<label class="control-label">Bucket Total Value Column</label> | ||
<select ng-model="total_column" ng-options="value as key for (key, value) in columns" class="form-control"></select> | ||
<label class="control-label">Day Number Column</label> | ||
<select ng-model="value_column" ng-options="value as key for (key, value) in columns" class="form-control"></select> | ||
<label class="control-label">Day Value Column</label> | ||
<select ng-model="day_column" ng-options="value as key for (key, value) in columns" class="form-control"></select> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import functools | ||
from flask.ext.login import current_user | ||
from flask.ext.restful import abort | ||
|
||
|
||
class require_permissions(object): | ||
def __init__(self, permissions): | ||
self.permissions = permissions | ||
|
||
def __call__(self, fn): | ||
@functools.wraps(fn) | ||
def decorated(*args, **kwargs): | ||
has_permissions = reduce(lambda a, b: a and b, | ||
map(lambda permission: permission in current_user.permissions, | ||
self.permissions), | ||
True) | ||
|
||
if has_permissions: | ||
return fn(*args, **kwargs) | ||
else: | ||
abort(403) | ||
|
||
return decorated | ||
|
||
|
||
def require_permission(permission): | ||
return require_permissions((permission,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters