Exemplo n.º 1
0
def update_permissions(sender, instance, **kwargs):
    """Permissions cleanup."""
    request = get_request()
    # request migth be None (management command context)
    if request:
        from_user = request.user
        if from_user == instance:
            raise exceptions.PermDeniedException(
                _("You can't delete your own account"))

        if not from_user.can_access(instance):
            raise exceptions.PermDeniedException

    # We send an additional signal before permissions are removed
    core_signals.account_deleted.send(sender="update_permissions",
                                      user=instance)
    owner = permissions.get_object_owner(instance)
    if owner == instance:
        # The default admin is being removed...
        owner = from_user
    # Change ownership of existing objects
    for ooentry in instance.objectaccess_set.filter(is_owner=True):
        if ooentry.content_object is not None:
            permissions.grant_access_to_object(owner, ooentry.content_object,
                                               True)
            permissions.ungrant_access_to_object(ooentry.content_object,
                                                 instance)
    # Remove existing permissions on this user
    permissions.ungrant_access_to_object(instance)
Exemplo n.º 2
0
 def save(self, commit=True):
     account = super(AccountFormGeneral, self).save(commit=False)
     if self.user == account and not self.cleaned_data["is_active"]:
         raise lib_exceptions.PermDeniedException(
             _("You can't disable your own account"))
     if commit:
         if self.cleaned_data.get("password2", "") != "":
             account.set_password(self.cleaned_data["password2"])
         account.save()
         account.role = self.cleaned_data["role"]
     return account
Exemplo n.º 3
0
 def save(self, commit=True):
     account = super(AccountFormGeneral, self).save(commit=False)
     if self.user == account and not self.cleaned_data["is_active"]:
         raise lib_exceptions.PermDeniedException(
             _("You can't disable your own account"))
     if not account.pk:
         account.language = settings.LANGUAGE_CODE
     if commit:
         if self.cleaned_data.get("password2", "") != "":
             account.set_password(self.cleaned_data["password2"])
         account.save()
         account.role = self.cleaned_data["role"]
         if hasattr(account, "mailbox"):
             # Update forward status according to account status
             models.Alias.objects.filter(address=account.email).update(
                 enabled=account.is_active)
     return account