-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
294 additions
and
33 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
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,30 @@ | ||
# Generated by Django 2.2.6 on 2019-11-01 13:38 | ||
|
||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
User = get_user_model() | ||
try: | ||
default_owner = User.objects.filter(is_superuser=True).first().id | ||
except: | ||
default_owner = None | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('projman', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='cmproject', | ||
name='owner', | ||
field=models.ForeignKey(default=default_owner, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
preserve_default=False, | ||
), | ||
] |
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,30 @@ | ||
import rules | ||
|
||
# Delegate to keycloak in future iteration | ||
|
||
# Predicates | ||
@rules.predicate | ||
def is_project_owner(user, project): | ||
if not project: | ||
return False | ||
return project.owner == user | ||
|
||
|
||
@rules.predicate | ||
def is_chart_owner(user, proj_chart): | ||
# Should have update rights on the parent project | ||
if not proj_chart: | ||
return False | ||
return user.has_perm('projects.change_project', proj_chart.project) | ||
|
||
|
||
# Permissions | ||
rules.add_perm('projects.view_project', rules.is_authenticated) | ||
rules.add_perm('projects.add_project', is_project_owner | rules.is_staff) | ||
rules.add_perm('projects.change_project', is_project_owner | rules.is_staff) | ||
rules.add_perm('projects.delete_project', is_project_owner | rules.is_staff) | ||
|
||
rules.add_perm('charts.view_chart', rules.is_authenticated) | ||
rules.add_perm('charts.add_chart', is_chart_owner | rules.is_staff) | ||
rules.add_perm('charts.change_chart', is_chart_owner | rules.is_staff) | ||
rules.add_perm('charts.delete_chart', is_chart_owner | rules.is_staff) |
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
Oops, something went wrong.