mirror of
https://github.com/ae-utbm/sith.git
synced 2025-09-13 11:35:44 +00:00
Compare commits
4 Commits
galaxy
...
club-edit-
Author | SHA1 | Date | |
---|---|---|---|
|
25cd877160 | ||
|
b767079c5a | ||
|
37961e437b | ||
|
b97a1a2e56 |
@@ -34,12 +34,10 @@ def migrate_meta_groups(apps: StateApps, schema_editor):
|
||||
clubs = list(Club.objects.all())
|
||||
for club in clubs:
|
||||
club.board_group = meta_groups.get_or_create(
|
||||
name=club.unix_name + settings.SITH_BOARD_SUFFIX,
|
||||
defaults={"is_meta": True},
|
||||
name=f"{club.unix_name}-bureau", defaults={"is_meta": True}
|
||||
)[0]
|
||||
club.members_group = meta_groups.get_or_create(
|
||||
name=club.unix_name + settings.SITH_MEMBER_SUFFIX,
|
||||
defaults={"is_meta": True},
|
||||
name=f"{club.unix_name}-membres", defaults={"is_meta": True}
|
||||
)[0]
|
||||
club.save()
|
||||
club.refresh_from_db()
|
||||
|
@@ -560,7 +560,7 @@ class User(AbstractUser):
|
||||
"""Determine if the object is owned by the user."""
|
||||
if hasattr(obj, "is_owned_by") and obj.is_owned_by(self):
|
||||
return True
|
||||
if hasattr(obj, "owner_group") and self.is_in_group(pk=obj.owner_group.id):
|
||||
if hasattr(obj, "owner_group") and self.is_in_group(pk=obj.owner_group_id):
|
||||
return True
|
||||
return self.is_root
|
||||
|
||||
@@ -569,9 +569,15 @@ class User(AbstractUser):
|
||||
if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self):
|
||||
return True
|
||||
if hasattr(obj, "edit_groups"):
|
||||
for pk in obj.edit_groups.values_list("pk", flat=True):
|
||||
if self.is_in_group(pk=pk):
|
||||
return True
|
||||
if (
|
||||
hasattr(obj, "_prefetched_objects_cache")
|
||||
and "edit_groups" in obj._prefetched_objects_cache
|
||||
):
|
||||
pks = [g.id for g in obj.edit_groups.all()]
|
||||
else:
|
||||
pks = list(obj.edit_groups.values_list("id", flat=True))
|
||||
if any(self.is_in_group(pk=pk) for pk in pks):
|
||||
return True
|
||||
if isinstance(obj, User) and obj == self:
|
||||
return True
|
||||
return self.is_owner(obj)
|
||||
@@ -581,9 +587,18 @@ class User(AbstractUser):
|
||||
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
|
||||
return True
|
||||
if hasattr(obj, "view_groups"):
|
||||
for pk in obj.view_groups.values_list("pk", flat=True):
|
||||
if self.is_in_group(pk=pk):
|
||||
return True
|
||||
# if "view_groups" has already been prefetched, use
|
||||
# the prefetch cache, else fetch only the ids, to make
|
||||
# the query lighter.
|
||||
if (
|
||||
hasattr(obj, "_prefetched_objects_cache")
|
||||
and "view_groups" in obj._prefetched_objects_cache
|
||||
):
|
||||
pks = [g.id for g in obj.view_groups.all()]
|
||||
else:
|
||||
pks = list(obj.view_groups.values_list("id", flat=True))
|
||||
if any(self.is_in_group(pk=pk) for pk in pks):
|
||||
return True
|
||||
return self.can_edit(obj)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
@@ -1384,9 +1399,9 @@ class Page(models.Model):
|
||||
|
||||
@cached_property
|
||||
def is_club_page(self):
|
||||
club_root_page = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first()
|
||||
return club_root_page is not None and (
|
||||
self == club_root_page or club_root_page in self.get_parent_list()
|
||||
return (
|
||||
self.name == settings.SITH_CLUB_ROOT_PAGE
|
||||
or settings.SITH_CLUB_ROOT_PAGE in [p.name for p in self.get_parent_list()]
|
||||
)
|
||||
|
||||
@cached_property
|
||||
|
@@ -5,16 +5,12 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if page_list %}
|
||||
<h3>{% trans %}Page list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for p in page_list %}
|
||||
<li><a href="{{ p.get_absolute_url() }}">{{ p.get_display_name() }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no page in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
<h3>{% trans %}Page list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for p in page_list %}
|
||||
<li><a href="{{ p.get_absolute_url() }}">{{ p.display_name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@@ -12,7 +12,10 @@
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.db.models import F, OuterRef, Subquery
|
||||
from django.db.models.functions import Coalesce
|
||||
|
||||
# This file contains all the views that concern the page model
|
||||
from django.forms.models import modelform_factory
|
||||
@@ -43,6 +46,20 @@ class CanEditPagePropMixin(CanEditPropMixin):
|
||||
class PageListView(CanViewMixin, ListView):
|
||||
model = Page
|
||||
template_name = "core/page_list.jinja"
|
||||
queryset = (
|
||||
Page.objects.annotate(
|
||||
display_name=Coalesce(
|
||||
Subquery(
|
||||
PageRev.objects.filter(page=OuterRef("id"))
|
||||
.order_by("-date")
|
||||
.values("title")[:1]
|
||||
),
|
||||
F("name"),
|
||||
)
|
||||
)
|
||||
.prefetch_related("view_groups")
|
||||
.select_related("parent")
|
||||
)
|
||||
|
||||
|
||||
class PageView(CanViewMixin, DetailView):
|
||||
|
@@ -535,13 +535,6 @@ class Counter(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def __getattribute__(self, name: str):
|
||||
if name == "edit_groups":
|
||||
return Group.objects.filter(
|
||||
name=self.club.unix_name + settings.SITH_BOARD_SUFFIX
|
||||
).all()
|
||||
return object.__getattribute__(self, name)
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
if self.type == "EBOUTIC":
|
||||
return reverse("eboutic:main")
|
||||
|
@@ -405,9 +405,6 @@ SITH_FORUM_PAGE_LENGTH = 30
|
||||
SITH_SAS_ROOT_DIR_ID = env.int("SITH_SAS_ROOT_DIR_ID", default=4)
|
||||
SITH_SAS_IMAGES_PER_PAGE = 60
|
||||
|
||||
SITH_BOARD_SUFFIX = "-bureau"
|
||||
SITH_MEMBER_SUFFIX = "-membres"
|
||||
|
||||
SITH_PROFILE_DEPARTMENTS = [
|
||||
("TC", _("TC")),
|
||||
("IMSI", _("IMSI")),
|
||||
|
Reference in New Issue
Block a user