def user_can_delete_obj(self, user, obj): """ Return a boolean to indicate whether `user` is permitted to 'delete' a specific `self.model` instance. """ try: run_permission_hooks('delete', obj) except PermissionDenied: return False else: return super(WagtailOmniFormPermissionHelper, self).user_can_delete_obj(user, obj)
def omni_form_locked(instance): """ Determines if the omni form is locked and returns a string identifying this :param instance: The form instance :return: string """ try: run_permission_hooks('update', instance) run_permission_hooks('delete', instance) except PermissionDenied: return 'yes' else: return 'no'
def check_action_permitted(self, user): """ Ensures that the user has permission to clone the omni form :param user: Logged in user instance :return: boolean - whether of not the user has permission to edit the instance """ try: run_permission_hooks('clone', self.instance) except PermissionDenied: return False else: return self.permission_helper.user_can_clone_obj( user, self.instance)
def user_can_clone_obj(self, user, obj): """ Checks that the user has permission to clone a form in the system :param user: Logged in user instance :param obj: OmniForm model instance :return: bool - True if the user can create a form instance, otherwise false """ try: run_permission_hooks('clone', obj) except PermissionDenied: return False else: perm_codename = self.get_perm_codename('add') return self.user_has_specific_permission(user, perm_codename)
def check_action_permitted(self, user): """ Ensures that the user has permission to change the related object :param user: Logged in user instance :return: boolean - whether of not the user has permission to edit the instance """ try: run_permission_hooks('delete', self.instance) except PermissionDenied: return False else: return all([ user.has_perm( self._get_model_permission(self.related_object_model_class, 'delete')), self.permission_helper.user_can_edit_obj(user, self.instance) ])
def _omni_form_related(self, form, related_qs, change_action, delete_action): """ Returns a comma delimited list of links for editing and deleting the related form objects :param form: OmniForm model instance :param related_qs: Queryset of related fields or handlers :param change_action: The name of the url change action :param delete_action: The name of the url delete action :return: comma delimited list of field links """ links = [] try: run_permission_hooks('update', form) except PermissionDenied: form_locked = True else: form_locked = False for related in related_qs: edit_url = self.url_helper.get_action_url( change_action, str(form.pk), str(related.pk) ) delete_url = self.url_helper.get_action_url( delete_action, str(form.pk), str(related.pk) ) links.append(render_to_string( 'modeladmin/omniforms/wagtail/includes/related_controls.html', { 'button_text': related, 'edit_url': edit_url, 'delete_url': delete_url, 'form_locked': form_locked } )) return mark_safe(''.join(links))