Skip to content

Commit

Permalink
[fix] パーミッションが無限に増える仕様を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
木瓜丸 committed Oct 5, 2020
1 parent 980a12b commit 7e2a1c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mitama/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mitama.nodes import User, Group, Relation
from mitama.db.types import Column, Integer, Node
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.schema import UniqueConstraint

class PermissionMixin(object):
'''パーミッションのモデルの実装を支援します
Expand Down Expand Up @@ -34,6 +35,13 @@ class SomePermission(PermissionMixin, db.Model):
@declared_attr
def __tablename__(cls):
return '__'+cls.__name__.lower()+'_permission'
@declared_attr
def __table_args__(cls):
if hasattr(cls, 'target'):
unique = UniqueConstraint('node', 'target', name='unique')
else:
unique = UniqueConstraint('node', name='unique')
return (unique, )
node = Column(Node)
targetUpPropagate = False
targetDownPropagate = False
Expand Down Expand Up @@ -71,10 +79,7 @@ def is_accepted(cls, node, target = None):
:param node: UserまたはGroupのインスタンス
:param target: 許可対象
'''
query = cls.query.filter(cls.node == node)
if hasattr(cls, 'target'):
query = query.filter(cls.target == target)
perms = query.all()
perms = cls.query.filter(cls.node == node).all()
for perm in perms:
if perm.is_target(target) or perm.is_target(None):
return True
Expand Down

0 comments on commit 7e2a1c9

Please sign in to comment.