special.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.utils.translation import ugettext_lazy as _
  2. import floppyforms as forms
  3. from misago.acl.builder import BaseACL
  4. from misago.forms import YesNoSwitch
  5. def make_form(request, role, form):
  6. if not role.special and request.user.is_god():
  7. form.base_fields['can_use_mcp'] = forms.BooleanField(label=_("Can use Moderator Control Panel"),
  8. help_text=_("Change this permission to yes to grant access to Mod CP for users with this role."),
  9. widget=YesNoSwitch, initial=False, required=False)
  10. form.base_fields['can_use_acp'] = forms.BooleanField(label=_("Can use Admin Control Panel"),
  11. help_text=_("Change this permission to yes to grant admin access for users with this role."),
  12. widget=YesNoSwitch, initial=False, required=False)
  13. form.fieldsets.append((
  14. _("Special Access"),
  15. ('can_use_mcp', 'can_use_acp')
  16. ))
  17. class SpecialACL(BaseACL):
  18. def is_admin(self):
  19. return self.acl['can_use_acp']
  20. def can_use_mcp(self):
  21. return self.acl['can_use_mcp']
  22. def build(acl, roles):
  23. acl.special = SpecialACL()
  24. acl.special.acl['can_use_acp'] = False
  25. acl.special.acl['can_use_mcp'] = False
  26. for role in roles:
  27. try:
  28. if role['can_use_acp']:
  29. acl.special.acl['can_use_acp'] = True
  30. if 'can_use_mcp' in role and role['can_use_mcp']:
  31. acl.special.acl['can_use_mcp'] = True
  32. except KeyError:
  33. pass
  34. if acl.special.acl['can_use_acp'] or acl.special.acl['can_use_mcp']:
  35. acl.team = True