Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Feature/yc 1181 #965

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion geocity/apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def clean_permissions(self):

class UserInline(admin.TabularInline):
model = Group.user_set.through
can_delete = True
readonly_fields = ("user",)
can_delete = False
extra = 0
verbose_name = _("Utilisateur membre du groupe")
verbose_name_plural = _("Utilisateurs membres du groupe")
Expand Down
90 changes: 35 additions & 55 deletions geocity/apps/accounts/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,67 +52,47 @@ def get_integrator_permissions():


def get_users_list_for_integrator_admin(user, remove_anonymous=False):
# Integrators can only view users for restricted email domains.
if user.is_superuser:
qs = User.objects.select_related("userprofile")

# Used to remove anonymous users from the list
anonymous_users = []
if remove_anonymous:
for user in qs:
if user.userprofile.is_anonymous:
anonymous_users.append(user.pk)
qs = qs.exclude(pk__in=anonymous_users)

return qs

user_integrator_group = user.groups.get(permit_department__is_integrator_admin=True)

email_domains = [
domain.strip()
for domain in user_integrator_group.permit_department.integrator_email_domains.split(
","
)
]
emails = [
email.strip()
for email in user_integrator_group.permit_department.integrator_emails_exceptions.split(
","
else:
user_integrator_group = user.groups.get(
permit_department__is_integrator_admin=True
)
]

qs = (
User.objects.annotate(
email_domain=Substr("email", StrIndex("email", Value("@")) + 1),
email_domains = [
domain.strip()
for domain in user_integrator_group.permit_department.integrator_email_domains.split(
","
)
]

emails = [
email.strip()
for email in user_integrator_group.permit_department.integrator_emails_exceptions.split(
","
)
]

qs = (
User.objects.annotate(
email_domain=Substr("email", StrIndex("email", Value("@")) + 1),
)
# hide users not belonging to the actual integrator
.filter(
Q(is_superuser=False),
Q(email_domain__in=email_domains) | Q(email__in=emails),
Q(groups__permit_department__integrator=user_integrator_group.pk)
| Q(groups__isnull=True)
| Q(groups__permit_department__is_integrator_admin=True),
).distinct()
)
# hide anynomous user not belonging to the actual integrator
.filter(
Q(is_superuser=False),
Q(email_domain__in=email_domains) | Q(email__in=emails),
Q(groups__permit_department__integrator=user_integrator_group.pk)
| Q(groups__isnull=True)
| Q(groups__permit_department__is_integrator_admin=True),
)
.exclude()
.distinct()
)
integrator_administrative_entities_list = (
models.AdministrativeEntity.objects.associated_to_user(user).values_list(
"pk", flat=True
)
)

# Used to remove anonymous users from the list
# Remove anonymous users if flag at true or user is not a superuser
anonymous_users = []
for user in qs:
if remove_anonymous and user.userprofile.is_anonymous:
anonymous_users.append(user.pk)
elif (
user.userprofile.is_anonymous
and user.userprofile.administrative_entity.pk
not in integrator_administrative_entities_list
):
anonymous_users.append(user.pk)
monodo marked this conversation as resolved.
Show resolved Hide resolved
qs = qs.exclude(pk__in=anonymous_users)
if remove_anonymous or not user.is_superuser:
for qs_user in qs:
if qs_user.userprofile.is_anonymous:
anonymous_users.append(qs_user.pk)
qs = qs.exclude(pk__in=anonymous_users)

return qs
2 changes: 1 addition & 1 deletion geocity/apps/submissions/management/commands/fixturize.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def setup_homepage(self, entities, iterations):
application_description_css = """
<style>
.login_container {
width: 100vw;
width: 70vw;
position: relative;
display: flex;
left: calc(-18vw + 50%);
Expand Down
Loading