class DeleteFile(SuccessMessageMixin, DeleteView):

    model = File
    success_message = _("File was deleted successfully")
    success_url = reverse_lazy('spaces_files:index')

    @file_owner_or_admin_required
    @method_decorator(permission_required_or_403('access_space'))
    def delete(self, request, *args, **kwargs):
        messages.success(request, self.success_message)
        # Note: on object deletion, all other activities are deleted, too.
        # That means the following signal won't show up in the activity stream.
        # Options for making deleted objects appear in the the stream would be
        # a) not really deleting but deactivating them with e.g. a boolean field
        # b) somehow presevering the name of the deleted instance in another
        #    table and replacing all instance references in the stream with
        #    that one.
        actstream_action.send(sender=request.user,
                              verb=_("was deleted"),
                              target=request.SPACE,
                              action_object=self.get_object())
        return super(DeleteFile, self).delete(request, *args, **kwargs)

    # ensure only files of own space can get deleted
    def get_queryset(self):
        qs = super(DeleteFile, self).get_queryset()
        qs = qs.filter(parent__file_manager__space=self.request.SPACE)
        return qs
class SpaceSource(WikiContextMixin, wiki_article.Source, SpaceArticleMixin):
    @method_decorator(get_article(can_read=True, deleted_contents=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpaceSource, self).dispatch(request, article, *args,
                                                 **kwargs)
class SpacePreview(WikiContextMixin, wiki_article.Preview, SpaceArticleMixin):
    template_name = "spaces_wiki/preview_inline.html"

    @method_decorator(get_article(can_read=True, deleted_contents=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpacePreview, self).dispatch(request, article, *args,
                                                  **kwargs)
class SpaceDir(WikiContextMixin, wiki_article.Dir, SpaceArticleMixin):
    @method_decorator(get_article(can_read=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpaceDir, self).dispatch(request, article, *args,
                                              **kwargs)

    def get_queryset(self):
        children = super(SpaceDir, self).get_queryset()
        children = children.filter(
            article__wikiarticle__wiki__space=self.request.SPACE)
        return children
class SpaceCreate(NotificationMixin, WikiContextMixin, wiki_article.Create,
                  SpaceArticleMixin):
    template_name = "spaces_wiki/create.html"
    form_class = SpaceCreateForm
    notification_label = 'spaces_wiki_create'
    notification_send_manually = True

    @method_decorator(get_article(can_write=True, can_create=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpaceCreate, self).dispatch(request, article, *args,
                                                 **kwargs)

    def get_context_data(self, **kwargs):
        context = super(SpaceCreate, self).get_context_data(**kwargs)
        context['create_form'] = self.get_form(SpaceCreateForm)
        return context

    def form_valid(self, form):
        ret = super(SpaceCreate, self).form_valid(form)
        root_redirect = redirect('wiki:get', '')
        if isinstance(ret,
                      HttpResponseRedirect) and root_redirect.url != ret.url:
            # super().form_valid successfully created a new article,
            # now get the new article and create our own WikiArticle instance
            # for proper integration.
            new_article = self.newpath.article
            wiki = SpacesWiki.objects.get(space=self.request.SPACE)
            wiki_article = WikiArticle.objects.create(article=new_article,
                                                      wiki=wiki)
            # create dashboard notification
            actstream_action.send(sender=self.request.user,
                                  verb=_("was created"),
                                  target=self.request.SPACE,
                                  action_object=wiki_article)
            # set title and link for notification mail
            self.notification_object_title = new_article
            self.notification_object_link = new_article.get_absolute_url()
            self.send_notification()

        return ret
class SpaceChangeRevisionView(WikiContextMixin,
                              wiki_article.ChangeRevisionView,
                              SpaceArticleMixin):
    @method_decorator(get_article(can_write=True, not_locked=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpaceChangeRevisionView,
                     self).dispatch(request, *args, **kwargs)

    def get_redirect_url(self, **kwargs):
        if self.urlpath:
            return reverse("spaces_wiki:get",
                           kwargs={'path': self.urlpath.path})
        else:
            return reverse('spaces_wiki:get',
                           kwargs={'article_id': self.article.id})
class SpaceArticleView(WikiContextMixin, wiki_article.ArticleView,
                       SpaceArticleMixin):
    template_name = 'spaces_wiki/view.html'

    @method_decorator(get_article(can_read=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish: method decorator pops 'article_id' and 'path', so we
        # add them back to make muliple decorator calls possible
        # Using django guardian's PermissionRequiredMixin would be nicer,
        # but how to get request.SPACE to check permission against?
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path

        return super(SpaceArticleView, self).dispatch(request, article, *args,
                                                      **kwargs)

    def get_context_data(self, **kwargs):
        kwargs = super(SpaceArticleView, self).get_context_data(**kwargs)
        kwargs['spaced_children_slice'] = self.children_slice
        return kwargs
class DeleteFolder(SuccessMessageMixin, DeleteView):

    model = Folder
    success_message = _("Folder was deleted successfully")
    success_url = reverse_lazy('spaces_files:index')

    @file_owner_or_admin_required
    @method_decorator(permission_required_or_403('access_space'))
    def delete(self, request, *args, **kwargs):
        actstream_action.send(sender=request.user,
                              verb=_("was deleted"),
                              target=request.SPACE,
                              action_object=self.get_object())

        messages.success(request, self.success_message)
        return super(DeleteFolder, self).delete(request, *args, **kwargs)

    # ensure only folders of own space can get deleted
    def get_queryset(self):
        qs = super(DeleteFolder, self).get_queryset()
        qs = qs.filter(file_manager__space=self.request.SPACE)
        return qs
class SpaceEdit(NotificationMixin, WikiContextMixin, wiki_article.Edit,
                SpaceArticleMixin):
    template_name = "spaces_wiki/edit.html"
    notification_label = 'spaces_wiki_modify'

    @method_decorator(get_article(can_write=True, not_locked=True))
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, article, *args, **kwargs):
        # hackish, see SpaceArticleView.dispatch
        kwargs['article_id'] = article.id
        kwargs['path'] = kwargs['urlpath'].path
        return super(SpaceEdit, self).dispatch(request, article, *args,
                                               **kwargs)

    def form_valid(self, form):
        # set title and link for notification mail
        self.notification_object_title = self.article
        self.notification_object_link = self.article.get_absolute_url()
        ret = super(SpaceEdit, self).form_valid(form)
        if isinstance(ret, HttpResponseRedirect):
            # super().form_valid successfully saved the article
            # create dashboard notification
            actstream_action.send(sender=self.request.user,
                                  verb=_("was modified"),
                                  target=self.request.SPACE,
                                  action_object=self.article.wikiarticle)

        return ret

    def get_context_data(self, **kwargs):
        context = super(SpaceEdit, self).get_context_data(**kwargs)
        # most probably the same bug as this:
        # https://github.com/django-wiki/django-wiki/issues/497
        # if bug gets fixed in a proper way, the next line can be removed
        context['edit_form'] = self.get_form(EditForm)
        # set title and link for n12n mails
        context["object_title"] = self.article
        context["object_link"] = self.article.get_absolute_url()
        return context
Beispiel #10
0
class SpacePlugin(wiki_article.Plugin):
    @method_decorator(permission_required_or_403('access_space'))
    def dispatch(self, request, path=None, slug=None, **kwargs):
        return super(SpacePlugin, self).dispatch(request, path, slug, **kwargs)