Bläddra i källkod

Return both slug and id of role + set explicit valid values

Guénaël Muller 6 år sedan
förälder
incheckning
997ee1fc9f

+ 267 - 0
development.ini.old Visa fil

@@ -0,0 +1,267 @@
1
+###
2
+# app configuration
3
+# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
4
+###
5
+[pipeline:main]
6
+pipeline = tracim_web
7
+[app:tracim_web]
8
+use = egg:tracim_backend
9
+
10
+pyramid.reload_templates = true
11
+pyramid.debug_authorization = false
12
+pyramid.debug_notfound = false
13
+pyramid.debug_routematch = false
14
+pyramid.default_locale_name = en
15
+pyramid.includes =
16
+    pyramid_debugtoolbar
17
+
18
+[pipeline:webdav]
19
+pipeline = tracim_webdav
20
+[app:tracim_webdav]
21
+use = egg:tracim_backend#webdav
22
+
23
+[DEFAULT]
24
+sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
25
+
26
+retry.attempts = 3
27
+
28
+# By default, the toolbar only appears for clients from IP addresses
29
+# '127.0.0.1' and '::1'.
30
+# debugtoolbar.hosts = 127.0.0.1 ::1
31
+
32
+###
33
+# TRACIM SPECIFIC CONF
34
+###
35
+
36
+### Global
37
+
38
+cache_dir = %(here)s/data
39
+# preview generator cache directory
40
+preview_cache_dir = /tmp/tracim/preview/
41
+# file depot storage
42
+depot_storage_name = tracim
43
+depot_storage_dir = %(here)s/depot/
44
+
45
+# The following parameters allow to personalize the home page
46
+# They are html ready (you can put html tags they will be interpreted)
47
+website.title = TRACIM
48
+website.title.color = #555
49
+website.home.subtitle = Default login: email: admin@admin.admin (password: admin@admin.admin)
50
+website.home.tag_line = <div class="text-center" style="font-weight: bold;">Collaboration, versionning and traceability</div>
51
+website.home.below_login_form = in case of problem, please contact the administrator.
52
+# Values may be 'all' or 'folders'
53
+website.treeview.content = all
54
+# The following base_url is used for links and icons
55
+# integrated in the email notifcations
56
+website.base_url = http://127.0.0.1:8080
57
+# If config not provided, it will be extracted from website.base_url
58
+website.server_name = 127.0.0.1
59
+
60
+# Specifies if the update of comments and attached files is allowed (by the owner only).
61
+# Examples:
62
+#    600 means 10 minutes (ie 600 seconds)
63
+#   3600 means 1 hour (60x60 seconds)
64
+#
65
+# Allowed values:
66
+#  -1 means that content update is allowed for ever
67
+#   0 means that content update is not allowed
68
+#   x means that content update is allowed for x seconds (with x>0)
69
+content.update.allowed.duration = 3600
70
+
71
+# Auth type (internal or ldap)
72
+auth_type = internal
73
+# If auth_type is ldap, uncomment following ldap_* parameters
74
+# LDAP server address
75
+# ldap_url = ldap://localhost:389
76
+# Base dn to make queries
77
+# ldap_base_dn = dc=directory,dc=fsf,dc=org
78
+# Bind dn to identify the search
79
+# ldap_bind_dn = cn=admin,dc=directory,dc=fsf,dc=org
80
+# The bind password
81
+# ldap_bind_pass = toor
82
+# Attribute name of user record who contain user login (email)
83
+# ldap_ldap_naming_attribute = uid
84
+# Matching between ldap attribute and ldap user field (ldap_attr1=user_field1,ldap_attr2=user_field2,...)
85
+# ldap_user_attributes = mail=email
86
+# TLS usage to communicate with your LDAP server
87
+# ldap_tls = False
88
+# If True, LDAP own tracim group managment (not available for now!)
89
+# ldap_group_enabled = False
90
+# User auth token validity in seconds (used to interfaces like web calendars)
91
+user.auth_token.validity = 604800
92
+
93
+### Mail
94
+
95
+# Reset password through email related configuration.
96
+# These emails will be sent through SMTP
97
+#
98
+resetpassword.email_sender = email@sender.com
99
+resetpassword.smtp_host = smtp.sender
100
+resetpassword.smtp_port = 25
101
+resetpassword.smtp_login = smtp.login
102
+resetpassword.smtp_passwd = smtp.password
103
+
104
+email.notification.activated = False
105
+# email.notification.log_file_path = /tmp/mail-notifications.log
106
+# email notifications can be sent with the user_id added as an identifier
107
+# this way email clients like Thunderbird will be able to distinguish
108
+# notifications generated by a user or another one
109
+email.notification.from.email = noreply+{user_id}@trac.im
110
+email.notification.from.default_label = Tracim Notifications
111
+email.notification.reply_to.email = reply+{content_id}@trac.im
112
+email.notification.references.email = thread+{content_id}@trac.im
113
+email.notification.content_update.template.html = %(here)s/tracim/templates/mail/content_update_body_html.mak
114
+email.notification.content_update.template.text = %(here)s/tracim/templates/mail/content_update_body_text.mak
115
+email.notification.created_account.template.html = %(here)s/tracim/templates/mail/created_account_body_html.mak
116
+email.notification.created_account.template.text = %(here)s/tracim/templates/mail/created_account_body_text.mak
117
+# Note: items between { and } are variable names. Do not remove / rename them
118
+email.notification.content_update.subject = [{website_title}] [{workspace_label}] {content_label} ({content_status_label})
119
+email.notification.created_account.subject = [{website_title}] Created account
120
+# processing_mode may be sync or async
121
+email.notification.processing_mode = sync
122
+email.notification.smtp.server = your_smtp_server
123
+email.notification.smtp.port = 25
124
+email.notification.smtp.user = your_smtp_user
125
+email.notification.smtp.password = your_smtp_password
126
+
127
+## Email sending configuration
128
+# processing_mode may be sync or async,
129
+# with async, please configure redis below
130
+email.processing_mode = sync
131
+# email.async.redis.host = localhost
132
+# email.async.redis.port = 6379
133
+# email.async.redis.db = 0
134
+
135
+# Email reply configuration
136
+email.reply.activated = False
137
+email.reply.imap.server = your_imap_server
138
+email.reply.imap.port = 993
139
+email.reply.imap.user = your_imap_user
140
+email.reply.imap.password = your_imap_password
141
+email.reply.imap.folder = INBOX
142
+email.reply.imap.use_ssl = true
143
+email.reply.imap.use_idle = true
144
+# Re-new connection each 10 minutes
145
+email.reply.connection.max_lifetime = 600
146
+# Token for communication between mail fetcher and tracim controller
147
+email.reply.token = mysecuretoken
148
+# Delay in seconds between each check
149
+email.reply.check.heartbeat = 60
150
+email.reply.use_html_parsing = true
151
+email.reply.use_txt_parsing = true
152
+# Lockfile path is required for email_reply feature,
153
+# it's just an empty file use to prevent concurrent access to imap unseen mail
154
+email.reply.lockfile_path = %(here)s/email_fetcher.lock
155
+
156
+### Radical (CalDav server) configuration
157
+
158
+# radicale.server.host = 0.0.0.0
159
+# radicale.server.port = 5232
160
+# radicale.server.ssl = false
161
+radicale.server.filesystem.folder = %(here)s/radicale/collections/
162
+# radicale.server.allow_origin = *
163
+# radicale.server.realm_message = Tracim Calendar - Password Required
164
+## url can be extended like http://127.0.0.1:5232/calendar
165
+## in this case, you have to create your own proxy behind this url.
166
+## and update following parameters
167
+# radicale.client.base_url.host = http://127.0.0.1:5232
168
+# radicale.client.base_url.prefix = /
169
+
170
+### WSGIDAV
171
+
172
+wsgidav.config_path = %(here)s/wsgidav.conf
173
+## url can be extended like 127.0.0.1/webdav
174
+## in this case, you have to create your own proxy behind this url.
175
+## Do not set http:// prefix.
176
+# wsgidav.client.base_url = 127.0.0.1:<WSGIDAV_PORT>
177
+
178
+###
179
+# wsgi server configuration
180
+###
181
+
182
+[server:main]
183
+use = egg:waitress#main
184
+listen = localhost:6543
185
+
186
+[alembic]
187
+# path to migration scripts
188
+script_location = tracim/migration
189
+
190
+# template used to generate migration files
191
+# file_template = %%(rev)s_%%(slug)s
192
+
193
+# timezone to use when rendering the date
194
+# within the migration file as well as the filename.
195
+# string value is passed to dateutil.tz.gettz()
196
+# leave blank for localtime
197
+# timezone =
198
+
199
+# max length of characters to apply to the
200
+# "slug" field
201
+#truncate_slug_length = 40
202
+
203
+# set to 'true' to run the environment during
204
+# the 'revision' command, regardless of autogenerate
205
+# revision_environment = false
206
+
207
+# set to 'true' to allow .pyc and .pyo files without
208
+# a source .py file to be detected as revisions in the
209
+# versions/ directory
210
+# sourceless = false
211
+
212
+# version location specification; this defaults
213
+# to migrate/versions.  When using multiple version
214
+# directories, initial revisions must be specified with --version-path
215
+# version_locations = %(here)s/bar %(here)s/bat migrate/versions
216
+
217
+# the output encoding used when revision files
218
+# are written from script.py.mako
219
+# output_encoding = utf-8
220
+
221
+sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
222
+
223
+###
224
+# logging configuration
225
+# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
226
+###
227
+
228
+[loggers]
229
+keys = root, tracim, sqlalchemy, alembic
230
+
231
+[handlers]
232
+keys = console
233
+
234
+[formatters]
235
+keys = generic
236
+
237
+[logger_root]
238
+level = INFO
239
+handlers = console
240
+
241
+[logger_tracim]
242
+level = DEBUG
243
+handlers =
244
+qualname = tracim
245
+
246
+[logger_sqlalchemy]
247
+level = INFO
248
+handlers =
249
+qualname = sqlalchemy.engine
250
+# "level = INFO" logs SQL queries.
251
+# "level = DEBUG" logs SQL queries and results.
252
+# "level = WARN" logs neither.  (Recommended for production systems.)
253
+
254
+[logger_alembic]
255
+level = INFO
256
+handlers =
257
+qualname = alembic
258
+
259
+[handler_console]
260
+class = StreamHandler
261
+args = (sys.stderr,)
262
+level = NOTSET
263
+formatter = generic
264
+
265
+[formatter_generic]
266
+format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
267
+datefmt = %H:%M:%S

+ 8 - 1
tracim/models/context_models.py Visa fil

@@ -171,7 +171,14 @@ class UserRoleWorkspaceInContext(object):
171 171
     # TODO - G.M - 23-05-2018 - Check the API spec for this this !
172 172
 
173 173
     @property
174
-    def slug(self) -> str:
174
+    def role_id(self) -> int:
175
+        """
176
+        role as int id, each value refer to a different role.
177
+        """
178
+        return self.user_role.role
179
+
180
+    @property
181
+    def role_slug(self) -> str:
175 182
         """
176 183
         simple name of the role of the user.
177 184
         can be anything from UserRoleInWorkspace SLUG, like

+ 15 - 1
tracim/models/data.py Visa fil

@@ -137,6 +137,7 @@ class UserRoleInWorkspace(DeclarativeBase):
137 137
     SLUG[CONTRIBUTOR] = 'contributor'
138 138
     SLUG[CONTENT_MANAGER] = 'content_manager'
139 139
     SLUG[WORKSPACE_MANAGER] = 'workspace_manager'
140
+
140 141
     # LABEL = dict()
141 142
     # LABEL[0] = l_('N/A')
142 143
     # LABEL[1] = l_('Reader')
@@ -171,7 +172,10 @@ class UserRoleInWorkspace(DeclarativeBase):
171 172
     #     return UserRoleInWorkspace.LABEL[self.role]
172 173
 
173 174
     @classmethod
174
-    def get_all_role_values(self):
175
+    def get_all_role_values(cls) -> typing.List[int]:
176
+        """
177
+        Return all valid role value
178
+        """
175 179
         return [
176 180
             UserRoleInWorkspace.READER,
177 181
             UserRoleInWorkspace.CONTRIBUTOR,
@@ -179,6 +183,16 @@ class UserRoleInWorkspace(DeclarativeBase):
179 183
             UserRoleInWorkspace.WORKSPACE_MANAGER
180 184
         ]
181 185
 
186
+    @classmethod
187
+    def get_all_role_slug(cls) -> typing.List[str]:
188
+        """
189
+        Return all valid role slug
190
+        """
191
+        # INFO - G.M - 25-05-2018 - Be carefull, as long as this method
192
+        # and get_all_role_values are both used for API, this method should
193
+        # return item in the same order as get_all_role_values
194
+        return [cls.SLUG[value] for value in cls.get_all_role_values()]
195
+
182 196
 
183 197
 class RoleType(object):
184 198
     def __init__(self, role_id):

+ 2 - 1
tracim/tests/functional/test_workspaces.py Visa fil

@@ -155,7 +155,8 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
155 155
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
156 156
         assert len(res) == 2
157 157
         user_role = res[0]
158
-        assert user_role['slug'] == 'workspace_manager'
158
+        assert user_role['role_slug'] == 'workspace_manager'
159
+        assert user_role['role_id'] == 8
159 160
         assert user_role['user_id'] == 1
160 161
         assert user_role['workspace_id'] == 1
161 162
         assert user_role['user']['display_name'] == 'Global manager'

+ 4 - 1
tracim/views/core_api/schemas.py Visa fil

@@ -1,8 +1,10 @@
1 1
 # coding=utf-8
2 2
 import marshmallow
3 3
 from marshmallow import post_load
4
+from marshmallow.validate import OneOf
4 5
 
5 6
 from tracim.models.context_models import LoginCredentials
7
+from tracim.models.data import UserRoleInWorkspace
6 8
 
7 9
 
8 10
 class ProfileSchema(marshmallow.Schema):
@@ -87,7 +89,8 @@ class WorkspaceDigestSchema(marshmallow.Schema):
87 89
 
88 90
 
89 91
 class WorkspaceMemberSchema(marshmallow.Schema):
90
-    slug = marshmallow.fields.String()
92
+    role_id = marshmallow.fields.Int(validate=OneOf(UserRoleInWorkspace.get_all_role_values()))  # nopep8
93
+    role_slug = marshmallow.fields.String(validate=OneOf(UserRoleInWorkspace.get_all_role_slug()))  # nopep8
91 94
     user_id = marshmallow.fields.Int()
92 95
     workspace_id = marshmallow.fields.Int()
93 96
     user = marshmallow.fields.Nested(