Beispiel #1
0
 def log_role_revoked(self, permission):
     structure_role_revoked.send(
         sender=self.__class__,
         structure=self,
         user=permission.user,
         role=permission.role,
     )
Beispiel #2
0
    def remove_memberships(self, memberships):
        for membership in memberships.iterator():
            role = membership.group.projectrole
            structure_role_revoked.send(
                sender=Project,
                structure=self,
                user=membership.user,
                role=role.role_type,
            )

            membership.delete()
Beispiel #3
0
    def remove_user(self, user, role_type=None):
        UserGroup = get_user_model().groups.through

        with transaction.atomic():
            memberships = UserGroup.objects.filter(
                group__customerrole__customer=self,
                user=user,
            )

            if role_type is not None:
                memberships = memberships.filter(
                    group__customerrole__role_type=role_type)

            for membership in memberships.iterator():
                role = membership.group.customerrole

                structure_role_revoked.send(
                    sender=Customer,
                    structure=self,
                    user=membership.user,
                    role=role.role_type,
                )

                membership.delete()

                role_name = role.get_role_type_display().lower()
                event_logger.info(
                    'User %s has lost role of %s in customer %s.',
                    user.username,
                    role_name,
                    self.name,
                    extra={
                        'customer': self,
                        'affected_user': user,
                        'event_type': 'role_revoked',
                        'structure_type': 'customer',
                        'role_name': role_name,
                    },
                )
Beispiel #4
0
    def remove_user(self, user, role_type=None):
        UserGroup = get_user_model().groups.through

        with transaction.atomic():
            memberships = UserGroup.objects.filter(
                group__projectgrouprole__project_group=self,
                user=user,
            )

            if role_type is not None:
                memberships = memberships.filter(group__projectgrouprole__role_type=role_type)

            for membership in memberships.iterator():
                role = membership.group.projectgrouprole
                structure_role_revoked.send(
                    sender=ProjectGroup,
                    structure=self,
                    user=membership.user,
                    role=role.role_type,
                )

                membership.delete()