outposts: fix permissions not being updated when providers are modified
This commit is contained in:
parent
7ea5c22b6c
commit
6a669992a8
|
@ -104,25 +104,22 @@ class Outpost(models.Model):
|
|||
return datetime.fromtimestamp(value)
|
||||
return None
|
||||
|
||||
def _create_user(self) -> User:
|
||||
"""Create user and assign permissions for all required objects"""
|
||||
@property
|
||||
def user(self) -> User:
|
||||
"""Get/create user with access to all required objects"""
|
||||
users = User.objects.filter(username=f"pb-outpost-{self.uuid.hex}")
|
||||
if not users.exists():
|
||||
user: User = User.objects.create(username=f"pb-outpost-{self.uuid.hex}")
|
||||
user.set_unusable_password()
|
||||
user.save()
|
||||
else:
|
||||
user = users.first()
|
||||
for model in self.get_required_objects():
|
||||
assign_perm(
|
||||
f"{model._meta.app_label}.view_{model._meta.model_name}", user, model
|
||||
)
|
||||
return user
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
"""Get/create user with access to all required objects"""
|
||||
user = User.objects.filter(username=f"pb-outpost-{self.uuid.hex}")
|
||||
if user.exists():
|
||||
return user.first()
|
||||
return self._create_user()
|
||||
|
||||
@property
|
||||
def token(self) -> Token:
|
||||
"""Get/create token for auto-generated user"""
|
||||
|
|
|
@ -41,7 +41,7 @@ def outpost_send_update(model_class: str, model_pk: Any):
|
|||
"""Send outpost update to all registered outposts, irregardless to which passbook
|
||||
instance they are connected"""
|
||||
model = path_to_class(model_class)
|
||||
outpost_model: OutpostModel = model.objects.get(model_pk)
|
||||
outpost_model: OutpostModel = model.objects.get(pk=model_pk)
|
||||
for outpost in outpost_model.outpost_set.all():
|
||||
channel_layer = get_channel_layer()
|
||||
for channel in outpost.channels:
|
||||
|
|
Reference in New Issue