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
20 changed files
with
326 additions
and
106 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,36 @@ | ||
import logging | ||
from casbin import persist | ||
from casbin.enforcer import Enforcer | ||
from casbin.model import Model | ||
from casbin.persist.adapter import Adapter | ||
from .models import CasbinData | ||
|
||
|
||
class TextAdapter(Adapter): | ||
def __init__(self, policy): | ||
self.policy = policy | ||
|
||
def load_policy(self, model): | ||
for line in self.policy.splitlines(): | ||
if not line.strip(): | ||
continue | ||
persist.load_policy_line(line.strip(), model) | ||
|
||
|
||
def get_enforcer(): | ||
data = CasbinData.objects.first() | ||
if data: | ||
m = Model() | ||
m.load_model_from_text(data.model) | ||
return Enforcer(m, TextAdapter(data.policy)) | ||
|
||
|
||
def enforce(sub, ctx, obj_type, action): | ||
try: | ||
enforcer = get_enforcer() | ||
if not enforcer: | ||
return False | ||
return enforcer.enforce(sub, ctx, obj_type, action) | ||
except Exception: | ||
logging.exception('Enforcer failed') | ||
return 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
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,52 @@ | ||
# Generated by Django 2.0.7 on 2019-05-08 09:30 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def set_assistant_flag(apps, schema_editor): | ||
""" | ||
проставление флажков для существующих файлов и команд о том, что они были созданы ассистентами | ||
""" | ||
EventMaterial = apps.get_model('isle', 'EventMaterial') | ||
EventTeamMaterial = apps.get_model('isle', 'EventTeamMaterial') | ||
Team = apps.get_model('isle', 'Team') | ||
User = apps.get_model('isle', 'User') | ||
assistants = list(User.objects.filter(unti_id__isnull=False, is_assistant=True).values_list('unti_id', flat=True)) | ||
EventMaterial.objects.filter(initiator__in=assistants).update(loaded_by_assistant=True) | ||
EventTeamMaterial.objects.filter(initiator__in=assistants).update(loaded_by_assistant=True) | ||
assistants = list(User.objects.filter(is_assistant=True).values_list('id', flat=True)) | ||
Team.objects.filter(creator_id__in=assistants).update(created_by_assistant=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('isle', '0044_auto_20190328_0215'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CasbinData', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('model', models.TextField()), | ||
('policy', models.TextField()), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='eventmaterial', | ||
name='loaded_by_assistant', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='eventteammaterial', | ||
name='loaded_by_assistant', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='team', | ||
name='created_by_assistant', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.RunPython(set_assistant_flag, reverse_code=migrations.RunPython.noop) | ||
] |
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
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.