mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Refactor a bit right handling
This commit is contained in:
parent
18f856af24
commit
c3fb581f97
@ -17,17 +17,26 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
u = User(username='root', last_name="", first_name="Bibou",
|
||||
root = User(username='root', last_name="", first_name="Bibou",
|
||||
email="ae.info@utbm.fr",
|
||||
date_of_birth="1942-06-12",
|
||||
is_superuser=True, is_staff=True)
|
||||
u.set_password("plop")
|
||||
u.save()
|
||||
root.set_password("plop")
|
||||
root.save()
|
||||
for g in settings.AE_GROUPS.values():
|
||||
Group(id=g['id'], name=g['name']).save()
|
||||
ae = Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
|
||||
address=settings.AE_MAIN_CLUB['address'])
|
||||
ae.save()
|
||||
p = Page(name='Index')
|
||||
p.set_lock(root)
|
||||
p.save()
|
||||
p.view_groups=[settings.AE_GROUPS['public']['id']]
|
||||
p.set_lock(root)
|
||||
p.save()
|
||||
PageRev(page=p, title="Wiki index", author=root, content="""
|
||||
Welcome to the wiki page!
|
||||
""").save()
|
||||
|
||||
# Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment
|
||||
if not options['prod']:
|
||||
@ -53,14 +62,12 @@ class Command(BaseCommand):
|
||||
r.save()
|
||||
# Adding syntax help page
|
||||
p = Page(name='Aide_sur_la_syntaxe')
|
||||
p.set_lock(s)
|
||||
p.save()
|
||||
PageRev(page=p, title="Aide sur la syntaxe", author=s, content="""
|
||||
Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
""").save()
|
||||
# Adding README
|
||||
p = Page(name='README')
|
||||
p.set_lock(s)
|
||||
p.save()
|
||||
p.view_groups=[settings.AE_GROUPS['public']['id']]
|
||||
p.set_lock(s)
|
||||
|
@ -98,6 +98,18 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
|
||||
def is_in_group(self, group_name):
|
||||
"""If the user is in the group passed in argument (as string)"""
|
||||
if group_name == settings.AE_GROUPS['public']['name']:
|
||||
return True
|
||||
if group_name == settings.AE_GROUPS['members']['name']: # We check the subscription if asked
|
||||
try:
|
||||
from subscription import Subscriber
|
||||
s = Subscriber.objects.filter(pk=self.pk).first()
|
||||
if s is not None and s.is_subscribed():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return self.groups.filter(name=group_name).exists()
|
||||
|
||||
def get_profile(self):
|
||||
@ -159,7 +171,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
"""
|
||||
if not hasattr(obj, "owner_group"):
|
||||
return False
|
||||
if (self.is_superuser or self.groups.filter(name=obj.owner_group.name).exists() or
|
||||
if (self.is_superuser or self.is_in_group(obj.owner_group.name) or
|
||||
self.has_perm(obj.__class__.__module__.split('.')[0]+".change_prop_"+obj.__class__.__name__.lower()) or
|
||||
self.groups.filter(id=settings.AE_GROUPS['root']['id']).exists()):
|
||||
return True
|
||||
@ -175,7 +187,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
return True
|
||||
if hasattr(obj, "edit_groups"):
|
||||
for g in obj.edit_groups.all():
|
||||
if self.groups.filter(name=g.name).exists():
|
||||
if self.is_in_group(g.name):
|
||||
return True
|
||||
if isinstance(obj, User) and obj == self:
|
||||
return True
|
||||
@ -193,7 +205,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
return True
|
||||
if hasattr(obj, "view_groups"):
|
||||
for g in obj.view_groups.all():
|
||||
if self.groups.filter(name=g.name).exists():
|
||||
if self.is_in_group(g.name):
|
||||
return True
|
||||
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
|
||||
return True
|
||||
|
@ -25,7 +25,7 @@
|
||||
<ul>
|
||||
<li><a href="{{ url('core:user_profile', user_id=user.id) }}">Profile</a></li>
|
||||
<li><a href="{{ url('core:user_list') }}">Users</a></li>
|
||||
<li><a href="{{ url('core:page_list') }}">Pages</a></li>
|
||||
<li><a href="{{ url('core:page', page_name="Index") }}">Pages</a></li>
|
||||
<li><a href="{{ url('club:club_list') }}">Clubs</a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
@ -12,10 +12,10 @@
|
||||
{% if request.user.id == profile.id %}
|
||||
<li><a href="{{ url('core:user_tools') }}">Tools</a></li>
|
||||
{% endif %}
|
||||
{% if user.has_perms('core.change_user') or user.id == profile.id %}
|
||||
{% if can_edit(profile, request.user) or user.id == profile.id %}
|
||||
<li><a href="{{ url('core:user_edit', user_id=profile.id) }}">Edit</a></li>
|
||||
{% endif %}
|
||||
{% if user.has_perms('core.change_prop_user') %}
|
||||
{% if can_edit_prop(profile, request.user) %}
|
||||
<li><a href="{{ url('core:user_prop', user_id=profile.id) }}">Props</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
@ -72,6 +72,7 @@ class CanViewMixin(View):
|
||||
"""
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(CanViewMixin, self).dispatch(request, *arg, **kwargs)
|
||||
print("GUYGUYGUYGUYGUY")
|
||||
if hasattr(self, 'object'):
|
||||
obj = self.object
|
||||
elif hasattr(self, 'object_list'):
|
||||
|
Loading…
Reference in New Issue
Block a user