Quellcode durchsuchen

Merge branch 'feature/578_add_api_for_workspace/apps' of github.com:tracim/tracim_backend into feature/578_add_api_for_workspace/apps

Guénaël Muller vor 6 Jahren
Ursprung
Commit
a567bb6d65

+ 0 - 267
development.ini.old Datei anzeigen

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

+ 2 - 1
tracim/lib/core/user.py Datei anzeigen

7
 from sqlalchemy.orm import Session
7
 from sqlalchemy.orm import Session
8
 
8
 
9
 from tracim import CFG
9
 from tracim import CFG
10
-from tracim.models.auth import User, Group
10
+from tracim.models.auth import User
11
+from tracim.models.auth import Group
11
 from sqlalchemy.orm.exc import NoResultFound
12
 from sqlalchemy.orm.exc import NoResultFound
12
 from tracim.exceptions import WrongUserPassword, UserDoesNotExist
13
 from tracim.exceptions import WrongUserPassword, UserDoesNotExist
13
 from tracim.exceptions import AuthenticationFailed
14
 from tracim.exceptions import AuthenticationFailed

+ 1 - 1
tracim/lib/utils/authorization.py Datei anzeigen

100
             raise InsufficientUserWorkspaceRole()
100
             raise InsufficientUserWorkspaceRole()
101
 
101
 
102
         return wrapper
102
         return wrapper
103
-    return decorator
103
+    return decorator

+ 3 - 1
tracim/lib/utils/request.py Datei anzeigen

5
 from pyramid.request import Request
5
 from pyramid.request import Request
6
 from sqlalchemy.orm.exc import NoResultFound
6
 from sqlalchemy.orm.exc import NoResultFound
7
 
7
 
8
-from tracim.exceptions import NotAuthentificated, UserDoesNotExist
8
+
9
+from tracim.exceptions import NotAuthentificated
10
+from tracim.exceptions import UserDoesNotExist
9
 from tracim.exceptions import WorkspaceNotFound
11
 from tracim.exceptions import WorkspaceNotFound
10
 from tracim.exceptions import ImmutableAttribute
12
 from tracim.exceptions import ImmutableAttribute
11
 from tracim.lib.core.user import UserApi
13
 from tracim.lib.core.user import UserApi

+ 13 - 9
tracim/models/auth.py Datei anzeigen

91
 class Profile(object):
91
 class Profile(object):
92
     """This model is the "max" group associated to a given user."""
92
     """This model is the "max" group associated to a given user."""
93
 
93
 
94
-    _NAME = [Group.TIM_NOBODY_GROUPNAME,
95
-             Group.TIM_USER_GROUPNAME,
96
-             Group.TIM_MANAGER_GROUPNAME,
97
-             Group.TIM_ADMIN_GROUPNAME]
98
-
99
-    _IDS = [Group.TIM_NOBODY,
100
-            Group.TIM_USER,
101
-            Group.TIM_MANAGER,
102
-            Group.TIM_ADMIN]
94
+    _NAME = [
95
+        Group.TIM_NOBODY_GROUPNAME,
96
+        Group.TIM_USER_GROUPNAME,
97
+        Group.TIM_MANAGER_GROUPNAME,
98
+        Group.TIM_ADMIN_GROUPNAME,
99
+    ]
100
+
101
+    _IDS = [
102
+        Group.TIM_NOBODY,
103
+        Group.TIM_USER,
104
+        Group.TIM_MANAGER,
105
+        Group.TIM_ADMIN,
106
+    ]
103
 
107
 
104
     # TODO - G.M - 18-04-2018 [Cleanup] Drop this
108
     # TODO - G.M - 18-04-2018 [Cleanup] Drop this
105
     # _LABEL = [l_('Nobody'),
109
     # _LABEL = [l_('Nobody'),

+ 2 - 2
tracim/models/context_models.py Datei anzeigen

8
 from tracim.models import User
8
 from tracim.models import User
9
 from tracim.models.auth import Profile
9
 from tracim.models.auth import Profile
10
 from tracim.models.data import Workspace, UserRoleInWorkspace
10
 from tracim.models.data import Workspace, UserRoleInWorkspace
11
-from tracim.models.workspace_menu_entries import default_workspace_menu_entry, \
12
-    WorkspaceMenuEntry
11
+from tracim.models.workspace_menu_entries import default_workspace_menu_entry
12
+from tracim.models.workspace_menu_entries import WorkspaceMenuEntry
13
 
13
 
14
 
14
 
15
 class LoginCredentials(object):
15
 class LoginCredentials(object):

+ 7 - 6
tracim/models/data.py Datei anzeigen

131
     WORKSPACE_MANAGER = 8
131
     WORKSPACE_MANAGER = 8
132
 
132
 
133
     # TODO - G.M - 10-04-2018 - [Cleanup] Drop this
133
     # TODO - G.M - 10-04-2018 - [Cleanup] Drop this
134
-    SLUG = dict()
135
-    SLUG[NOT_APPLICABLE] = 'not_applicable'
136
-    SLUG[READER] = 'reader'
137
-    SLUG[CONTRIBUTOR] = 'contributor'
138
-    SLUG[CONTENT_MANAGER] = 'content_manager'
139
-    SLUG[WORKSPACE_MANAGER] = 'workspace_manager'
134
+    SLUG = {
135
+        NOT_APPLICABLE: 'not_applicable',
136
+        READER: 'reader',
137
+        CONTRIBUTOR: 'contributor',
138
+        CONTENT_MANAGER: 'content_manager',
139
+        WORKSPACE_MANAGER: 'workspace_manager',
140
+    }
140
 
141
 
141
     # LABEL = dict()
142
     # LABEL = dict()
142
     # LABEL[0] = l_('N/A')
143
     # LABEL[0] = l_('N/A')

+ 9 - 6
tracim/views/core_api/user_controller.py Datei anzeigen

11
     from http import client as HTTPStatus
11
     from http import client as HTTPStatus
12
 
12
 
13
 from tracim import hapic, TracimRequest
13
 from tracim import hapic, TracimRequest
14
-from tracim.exceptions import NotAuthentificated, InsufficientUserProfile, \
15
-    UserDoesNotExist
16
-from tracim.lib.core.user import UserApi
14
+
15
+from tracim.exceptions import NotAuthentificated
16
+from tracim.exceptions import InsufficientUserProfile
17
+from tracim.exceptions import UserDoesNotExist
17
 from tracim.lib.core.workspace import WorkspaceApi
18
 from tracim.lib.core.workspace import WorkspaceApi
18
 from tracim.views.controllers import Controller
19
 from tracim.views.controllers import Controller
19
-from tracim.views.core_api.schemas import UserIdPathSchema, \
20
-    WorkspaceDigestSchema
20
+from tracim.views.core_api.schemas import UserIdPathSchema
21
+from tracim.views.core_api.schemas import WorkspaceDigestSchema
21
 
22
 
22
 
23
 
23
 class UserController(Controller):
24
 class UserController(Controller):
39
             session=request.dbsession,
40
             session=request.dbsession,
40
             config=app_config,
41
             config=app_config,
41
         )
42
         )
43
+        
44
+        workspaces = wapi.get_all_for_user(request.candidate_user)
42
         return [
45
         return [
43
             WorkspaceInContext(workspace, request.dbsession, app_config)
46
             WorkspaceInContext(workspace, request.dbsession, app_config)
44
-            for workspace in wapi.get_all_for_user(request.candidate_user)
47
+            for workspace in workspaces
45
         ]
48
         ]
46
 
49
 
47
     def bind(self, configurator: Configurator) -> None:
50
     def bind(self, configurator: Configurator) -> None:

+ 12 - 8
tracim/views/core_api/workspace_controller.py Datei anzeigen

5
 
5
 
6
 from tracim.lib.core.userworkspace import RoleApi
6
 from tracim.lib.core.userworkspace import RoleApi
7
 from tracim.lib.utils.authorization import require_workspace_role
7
 from tracim.lib.utils.authorization import require_workspace_role
8
-from tracim.models.context_models import WorkspaceInContext, \
9
-    UserRoleWorkspaceInContext
8
+from tracim.models.context_models import WorkspaceInContext
9
+from tracim.models.context_models import UserRoleWorkspaceInContext
10
 from tracim.models.data import UserRoleInWorkspace
10
 from tracim.models.data import UserRoleInWorkspace
11
 
11
 
12
 try:  # Python 3.5+
12
 try:  # Python 3.5+
15
     from http import client as HTTPStatus
15
     from http import client as HTTPStatus
16
 
16
 
17
 from tracim import hapic, TracimRequest
17
 from tracim import hapic, TracimRequest
18
-from tracim.exceptions import NotAuthentificated, InsufficientUserProfile, \
19
-    WorkspaceNotFound
18
+from tracim.exceptions import NotAuthentificated
19
+from tracim.exceptions import InsufficientUserProfile
20
+from tracim.exceptions import WorkspaceNotFound
20
 from tracim.lib.core.user import UserApi
21
 from tracim.lib.core.user import UserApi
21
 from tracim.lib.core.workspace import WorkspaceApi
22
 from tracim.lib.core.workspace import WorkspaceApi
22
 from tracim.views.controllers import Controller
23
 from tracim.views.controllers import Controller
23
-from tracim.views.core_api.schemas import WorkspaceSchema, UserSchema, \
24
-    WorkspaceIdPathSchema, WorkspaceMemberSchema
25
-
24
+from tracim.views.core_api.schemas import WorkspaceSchema
25
+from tracim.views.core_api.schemas import UserSchema
26
+from tracim.views.core_api.schemas import WorkspaceIdPathSchema
27
+from tracim.views.core_api.schemas import WorkspaceMemberSchema
26
 
28
 
27
 class WorkspaceController(Controller):
29
 class WorkspaceController(Controller):
28
 
30
 
68
             session=request.dbsession,
70
             session=request.dbsession,
69
             config=app_config,
71
             config=app_config,
70
         )
72
         )
73
+        
74
+        roles = rapi.get_all_for_workspace(request.current_workspace)
71
         return [
75
         return [
72
             rapi.get_user_role_workspace_with_context(user_role)
76
             rapi.get_user_role_workspace_with_context(user_role)
73
-            for user_role in rapi.get_all_for_workspace(request.current_workspace)
77
+            for user_role in roles
74
         ]
78
         ]
75
 
79
 
76
     def bind(self, configurator: Configurator) -> None:
80
     def bind(self, configurator: Configurator) -> None: