-
Notifications
You must be signed in to change notification settings - Fork 147
/
user_moderation.py
173 lines (154 loc) · 5.22 KB
/
user_moderation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023-2024 CERN.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Invenio administration view module for user moderation."""
from functools import partial
from flask import current_app
from invenio_administration.views.base import (
AdminResourceDetailView,
AdminResourceListView,
)
from invenio_requests.customizations.user_moderation import UserModerationRequest
from invenio_search_ui.searchconfig import search_app_config
class UserModerationListView(AdminResourceListView):
"""User moderation admin search view."""
api_endpoint = "/requests"
extension_name = "invenio-requests"
name = "moderation"
resource_config = "requests_resource"
request_headers = {"Accept": "application/vnd.inveniordm.v1+json"}
title = "Moderation"
menu_label = "Moderation"
category = "Moderation"
pid_path = "id"
icon = "users"
template = "invenio_app_rdm/administration/user_moderation.html"
order = 1
display_search = True
display_delete = False
display_create = False
display_edit = False
item_field_list = {
# custom display of the values - only declared to create columns
"expanded.topic.user": {
"text": "User",
"order": 2,
"width": 4,
},
# custom display of the values - only declared to create columns
"expanded.topic.user.profile.email": {
"text": "Email",
"order": 3,
"width": 2,
},
# custom display of the values - only declared to create columns
"domain": {
"text": "Email domain",
"order": 4,
"width": 2,
},
# custom display of the values - only declared to create columns
"activity": {
"text": "Activity",
"order": 5,
"width": 4,
},
"status": {
"text": "Status",
"order": 6,
"width": 2,
},
}
actions = {
"accept": {
"text": "Approve",
"payload_schema": None,
"order": 1,
},
"decline": {
"text": "Block",
"payload_schema": None,
"order": 2,
},
}
search_config_name = "REQUESTS_USER_MODERATION_SEARCH"
search_facets_config_name = "REQUESTS_USER_MODERATION_FACETS"
search_sort_config_name = "REQUESTS_USER_MODERATION_SORT_OPTIONS"
@property
def request_type(self):
"""Request type property."""
request_type = self.resource.service.request_type_registry.lookup(
"user-moderation"
)
return request_type
@classmethod
def get_service_schema(cls):
"""Get marshmallow schema of the assigned service."""
request_type = cls.resource.service.request_type_registry.lookup(
"user-moderation"
)
# handle dynamic schema class declaration for requests
schema_cls = request_type.marshmallow_schema()
schema = schema_cls()
return schema
@staticmethod
def disabled():
"""Disable the view on demand."""
return False
def init_search_config(self):
"""Build search view config."""
return partial(
search_app_config,
config_name=self.get_search_app_name(),
available_facets=current_app.config.get(self.search_facets_config_name),
sort_options=current_app.config[self.search_sort_config_name],
endpoint=self.get_api_endpoint(),
headers=self.get_search_request_headers(),
initial_filters=[["is_open", "true"]],
hidden_params=[
["expand", "1"],
["type", UserModerationRequest.type_id],
],
page=1,
size=15,
)
class UserModerationRequestDetailView(AdminResourceDetailView):
"""Admin community detail view."""
url = "/moderation/<pid_value>"
extension_name = "invenio-requests"
api_endpoint = "/requests"
name = "user-moderation-details"
resource_config = "requests_resource"
title = "User moderation"
display_delete = False
display_edit = False
list_view_name = "communities"
pid_path = "id"
request_headers = {"Accept": "application/json"}
template = "invenio_app_rdm/administration/user_moderation_details.html"
@classmethod
def get_service_schema(cls):
"""Get marshmallow schema of the assigned service."""
request_type = cls.resource.service.request_type_registry.lookup(
"user-moderation"
)
# handle dynamic schema class declaration for requests
schema_cls = request_type.marshmallow_schema()
schema = schema_cls()
return schema
item_field_list = {
"id": {
"text": "ID",
"order": 1,
},
"topic.user": {
"text": "User",
"order": 3,
}, # TODO we should resolve the user. But this is fetched from the API.
# TODO can we dereference somehow?
"created": {"text": "Created", "order": 2},
"is_open": {"text": "Open", "order": 4},
}