special.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(widget=YesNoSwitch, initial=False, required=False)
  8. form.base_fields['can_use_acp'] = forms.BooleanField(widget=YesNoSwitch, initial=False, required=False)
  9. form.layout.append((_("Special Access"),
  10. (
  11. ('can_use_mcp', {'label': _("Can use Moderator Control Panel"), 'help_text': _("Change this permission to yes to grant access to Mod CP for users with this role.")}),
  12. ('can_use_acp', {'label': _("Can use Admin Control Panel"), 'help_text': _("Change this permission to yes to grant admin access for users with this role.")}),
  13. )
  14. ))
  15. class SpecialACL(BaseACL):
  16. def is_admin(self):
  17. return self.acl['can_use_acp']
  18. def can_use_mcp(self):
  19. return self.acl['can_use_mcp']
  20. def build(acl, roles):
  21. acl.special = SpecialACL()
  22. acl.special.acl['can_use_acp'] = False
  23. acl.special.acl['can_use_mcp'] = False
  24. for role in roles:
  25. try:
  26. if role['can_use_acp']:
  27. acl.special.acl['can_use_acp'] = True
  28. if 'can_use_mcp' in role and role['can_use_mcp']:
  29. acl.special.acl['can_use_mcp'] = True
  30. except KeyError:
  31. pass
  32. if acl.special.acl['can_use_acp'] or acl.special.acl['can_use_mcp']:
  33. acl.team = True