Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
884855c1
Commit
884855c1
authored
Dec 07, 2018
by
Sli
Committed by
Skia
Dec 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
forum and core: remove CanViewSearchMixin and use specialized view instead
parent
1de77f2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
29 deletions
+13
-29
core/views/__init__.py
core/views/__init__.py
+0
-23
forum/models.py
forum/models.py
+3
-3
forum/views.py
forum/views.py
+10
-3
No files found.
core/views/__init__.py
View file @
884855c1
...
...
@@ -201,29 +201,6 @@ class CanViewMixin(View):
return
super
(
CanViewMixin
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
class
CanViewSearchMixin
(
View
):
"""
This view removes all forbidden content from a SearchQuerySet
"""
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
queryset
=
self
.
get_queryset
()
excluded
=
[
o
.
object
.
id
for
o
in
queryset
if
not
can_view
(
o
.
object
,
request
.
user
)
]
self
.
_queryset
=
queryset
def
get_qs
(
self2
):
q
=
self2
.
_queryset
.
exclude
(
id__in
=
excluded
)
resp
=
[
r
.
object
for
r
in
q
]
return
resp
self
.
get_queryset
=
types
.
MethodType
(
get_qs
,
self
)
return
super
(
CanViewSearchMixin
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
class
FormerSubscriberMixin
(
View
):
"""
This view check if the user was at least an old subscriber
...
...
forum/models.py
View file @
884855c1
...
...
@@ -331,9 +331,9 @@ class ForumMessage(models.Model):
return
user
.
can_edit
(
self
.
topic
.
forum
)
def
can_be_viewed_by
(
self
,
user
):
return
not
self
.
_deleted
and
self
.
topic
.
can_be_viewed_by
(
user
)
# Useful in search engine
# No need to check the real rights since it's already done by the Topic view
# and it impacts performances too much
return
not
self
.
_deleted
def
can_be_moderated_by
(
self
,
user
):
return
self
.
topic
.
forum
.
is_owned_by
(
user
)
or
user
.
id
==
self
.
author
.
id
...
...
forum/views.py
View file @
884855c1
...
...
@@ -42,19 +42,26 @@ from core.views import (
CanEditMixin
,
CanEditPropMixin
,
CanCreateMixin
,
C
an
V
iew
SearchMixin
,
c
an
_v
iew
,
)
from
core.views.forms
import
MarkdownInput
from
forum.models
import
Forum
,
ForumMessage
,
ForumTopic
,
ForumMessageMeta
from
haystack.query
import
SearchQuerySet
class
ForumSearchView
(
CanViewSearchMixin
,
ListView
):
class
ForumSearchView
(
ListView
):
template_name
=
"forum/search.jinja"
def
get_queryset
(
self
):
query
=
self
.
request
.
GET
.
get
(
"query"
,
""
)
return
SearchQuerySet
().
models
(
ForumMessage
).
autocomplete
(
auto
=
query
)
queryset
=
SearchQuerySet
().
models
(
ForumMessage
).
autocomplete
(
auto
=
query
)
excluded
=
[
o
.
object
.
id
for
o
in
queryset
if
not
can_view
(
o
.
object
.
topic
,
self
.
request
.
user
)
]
queryset
.
exclude
(
id__in
=
excluded
)
return
[
r
.
object
for
r
in
queryset
]
class
ForumMainView
(
ListView
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment