mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 11:40:05 -03:30
Testing to whether a user can attach/unattach is now deferred to the model.
This commit is contained in:
@@ -44,17 +44,24 @@ class CommonModel(models.Model):
|
||||
def can_user_read(cls, user, obj):
|
||||
raise exceptions.NotImplementedError()
|
||||
|
||||
@classmethod
|
||||
def can_user_add(cls, user):
|
||||
return user.is_superuser
|
||||
|
||||
@classmethod
|
||||
def can_user_attach(cls, user, obj, sub_obj, relationship):
|
||||
''' whether you can add sub_obj to obj using the relationship type in a subobject view '''
|
||||
if relationship in [ 'projects', 'admins', 'users' ]:
|
||||
if not sub_obj.can_user_read(user, sub_obj):
|
||||
print "DEBUG: can't attach"
|
||||
return False
|
||||
print "DEBUG: defer"
|
||||
return cls.can_user_administrate(user, obj)
|
||||
raise Exception("unknown relationship type: %s" % relationship)
|
||||
|
||||
@classmethod
|
||||
def can_user_unattach(cls, user, obj, relationship):
|
||||
def can_user_unattach(cls, user, obj, sub_obj, relationship):
|
||||
print "DEBUG: CUA?"
|
||||
return cls.can_user_administrate(user, obj)
|
||||
|
||||
class Tag(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user