10
10
11
11
"""Routes for general pages provided by Invenio-App-RDM."""
12
12
13
- from flask import Blueprint , current_app , flash , render_template , request
13
+ from flask import Blueprint , current_app , flash , g , render_template , request
14
14
from flask_login import current_user
15
15
from flask_menu import current_menu
16
+ from invenio_administration .permissions import administration_permission
16
17
from invenio_db import db
17
18
from invenio_i18n import get_locale
18
19
from invenio_i18n import lazy_gettext as _
@@ -29,6 +30,20 @@ def create_url_rule(rule, default_view_func):
29
30
return {"rule" : rule , "view_func" : default_view_func }
30
31
31
32
33
+ def _can_manage_community ():
34
+ """Function used to check if a user has permissions to manage a community."""
35
+ return administration_permission .can () and request .url_rule .rule .startswith (
36
+ "/communities/"
37
+ )
38
+
39
+
40
+ def _can_manage_record ():
41
+ """Function used to check if a user has permissions to manage a record."""
42
+ return administration_permission .can () and request .url_rule .rule .startswith (
43
+ "/records/"
44
+ )
45
+
46
+
32
47
#
33
48
# Registration
34
49
#
@@ -75,6 +90,34 @@ def init_menu():
75
90
order = 1 ,
76
91
)
77
92
93
+ current_menu .submenu ("cog.record" ).register (
94
+ "administration.Records" ,
95
+ _ ("Manage record" ),
96
+ order = 1 ,
97
+ endpoint_arguments_constructor = lambda : {
98
+ "q" : f"id:{ request .view_args .get ('pid_value' )} "
99
+ },
100
+ visible_when = _can_manage_record ,
101
+ )
102
+
103
+ current_menu .submenu ("cog.user" ).register (
104
+ "administration.users" ,
105
+ _ ("Manage user" ),
106
+ order = 2 ,
107
+ endpoint_arguments_constructor = lambda : {"q" : f"id:{ current_user .id } " },
108
+ visible_when = _can_manage_record ,
109
+ )
110
+
111
+ current_menu .submenu ("cog.community" ).register (
112
+ "administration.communities" ,
113
+ _ ("Manage community" ),
114
+ order = 3 ,
115
+ endpoint_arguments_constructor = lambda : {
116
+ "q" : f"slug:{ request .view_args .get ('pid_value' )} "
117
+ },
118
+ visible_when = _can_manage_community ,
119
+ )
120
+
78
121
return blueprint
79
122
80
123
0 commit comments