Browse Source

bugfix on user profil definition

Damien ACCORSI 10 years ago
parent
commit
73d1c0b1dc

+ 0 - 10
.hgignore View File

@@ -1,10 +0,0 @@
1
-# use glob syntax.
2
-syntax: glob
3
-
4
-*.elc
5
-*.pyc
6
-*~
7
-
8
-tg2env/
9
-pboard/data
10
-

+ 1 - 0
doc/database/tracim-migrate-to-first-stable-release.sql View File

@@ -201,7 +201,7 @@ CREATE OR REPLACE RULE pod_insert_new_node AS
201 201
   VALUES (nextval('pod_nodes__node_id__sequence'::regclass), new.parent_id, new.node_order, new.node_type, new.created_at, new.updated_at, new.data_label, new.data_content, new.data_datetime, new.node_status, new.data_reminder_datetime, new.data_file_name, new.data_file_content, new.data_file_mime_type, new.parent_tree_path, new.node_depth, new.owner_id, nextval('pod_nodes_version_id_sequence'::regclass), new.is_shared, new.is_public, new.public_url_key, new.workspace_id, new.is_deleted, new.is_archived, new.properties, new.last_action)
202 202
   RETURNING pod_nodes_history.node_id, pod_nodes_history.parent_id, pod_nodes_history.node_order, pod_nodes_history.node_type, pod_nodes_history.created_at, pod_nodes_history.updated_at, pod_nodes_history.data_label, pod_nodes_history.data_content, pod_nodes_history.data_datetime, pod_nodes_history.node_status, pod_nodes_history.data_reminder_datetime, pod_nodes_history.data_file_name, pod_nodes_history.data_file_content, pod_nodes_history.data_file_mime_type, pod_nodes_history.parent_tree_path, pod_nodes_history.node_depth, pod_nodes_history.owner_id, pod_nodes_history.is_shared, pod_nodes_history.is_public, pod_nodes_history.public_url_key, pod_nodes_history.workspace_id, pod_nodes_history.is_deleted, pod_nodes_history.is_archived, pod_nodes_history.properties, pod_nodes_history.last_action;
203 203
 
204
+DROP TRIGGER pod_update_node_tg ON pod_nodes;
204 205
 CREATE TRIGGER pod_update_node_tg
205 206
   INSTEAD OF UPDATE
206 207
   ON pod_nodes

+ 27 - 12
tracim/tracim/controllers/admin/user.py View File

@@ -20,6 +20,7 @@ from formencode.validators import FieldsMatch
20 20
 from tracim.controllers import TIMRestController
21 21
 from tracim.lib import CST
22 22
 from tracim.lib import helpers as h
23
+from tracim.lib.base import logger
23 24
 from tracim.lib.user import UserApi
24 25
 from tracim.lib.group import GroupApi
25 26
 from tracim.lib.user import UserStaticApi
@@ -36,7 +37,17 @@ class UserProfileAdminRestController(TIMRestController):
36 37
     """
37 38
     allow_only = predicates.in_any_group(Group.TIM_ADMIN_GROUPNAME)
38 39
 
39
-    allowed_profiles = ['tracim-user', 'tracim-manager', 'tracim-admin']
40
+    _ALLOWED_PROFILE_USER = 'tracim-profile-user'
41
+    _ALLOWED_PROFILE_MANAGER = 'tracim-profile-manager'
42
+    _ALLOWED_PROFILE_ADMIN = 'tracim-profile-admin'
43
+
44
+    @property
45
+    def allowed_profiles(self):
46
+        return [
47
+        UserProfileAdminRestController._ALLOWED_PROFILE_USER,
48
+        UserProfileAdminRestController._ALLOWED_PROFILE_MANAGER,
49
+        UserProfileAdminRestController._ALLOWED_PROFILE_ADMIN
50
+    ]
40 51
 
41 52
     def _before(self, *args, **kw):
42 53
         """
@@ -86,7 +97,7 @@ class UserProfileAdminRestController(TIMRestController):
86 97
 
87 98
         flash_message = _('User updated.') # this is the default value ; should never appear
88 99
 
89
-        if new_profile=='tracim-user':
100
+        if new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_USER:
90 101
             if pod_user_group not in user.groups:
91 102
                 user.groups.append(pod_user_group)
92 103
 
@@ -102,7 +113,7 @@ class UserProfileAdminRestController(TIMRestController):
102 113
 
103 114
             flash_message = _('User {} is now a basic user').format(user.get_display_name())
104 115
 
105
-        elif new_profile=='tracim-manager':
116
+        elif new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_MANAGER:
106 117
             if pod_user_group not in user.groups:
107 118
                 user.groups.append(pod_user_group)
108 119
             if pod_manager_group not in user.groups:
@@ -116,7 +127,7 @@ class UserProfileAdminRestController(TIMRestController):
116 127
             flash_message = _('User {} can now workspaces').format(user.get_display_name())
117 128
 
118 129
 
119
-        elif new_profile=='tracim-admin':
130
+        elif new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_ADMIN:
120 131
             if pod_user_group not in user.groups:
121 132
                 user.groups.append(pod_user_group)
122 133
             if pod_manager_group not in user.groups:
@@ -126,8 +137,12 @@ class UserProfileAdminRestController(TIMRestController):
126 137
 
127 138
             flash_message = _('User {} is now an administrator').format(user.get_display_name())
128 139
 
129
-        DBSession.flush()
140
+        else:
141
+            logger.error(self, 'Trying to change user {} profile with unexpected profile {}'.format(user.user_id, new_profile))
142
+            tg.flash(_('Unknown profile'), CST.STATUS_ERROR)
143
+            tg.redirect(redirect_url)
130 144
 
145
+        DBSession.flush()
131 146
         tg.flash(flash_message, CST.STATUS_OK)
132 147
         tg.redirect(redirect_url)
133 148
 
@@ -231,15 +246,15 @@ class UserRestController(TIMRestController):
231 246
 
232 247
     @tg.require(predicates.in_group(Group.TIM_MANAGER_GROUPNAME))
233 248
     @tg.expose()
234
-    def post(self, name, email, password, is_pod_manager='off', is_pod_admin='off'):
235
-        is_pod_manager = h.on_off_to_boolean(is_pod_manager)
236
-        is_pod_admin = h.on_off_to_boolean(is_pod_admin)
249
+    def post(self, name, email, password, is_tracim_manager='off', is_pod_admin='off'):
250
+        is_tracim_manager = h.on_off_to_boolean(is_tracim_manager)
251
+        is_tracim_admin = h.on_off_to_boolean(is_pod_admin)
237 252
         current_user = tmpl_context.current_user
238 253
         current_user = User()
239 254
         if current_user.profile.id < Group.TIM_ADMIN:
240 255
             # A manager can't give large rights
241
-            is_pod_manager = False
242
-            is_pod_admin = False
256
+            is_tracim_manager = False
257
+            is_tracim_admin = False
243 258
 
244 259
 
245 260
         api = UserApi(current_user)
@@ -258,9 +273,9 @@ class UserRestController(TIMRestController):
258 273
         # Now add the user to related groups
259 274
         group_api = GroupApi(current_user)
260 275
         user.groups.append(group_api.get_one(Group.TIM_USER))
261
-        if is_pod_manager:
276
+        if is_tracim_manager:
262 277
             user.groups.append(group_api.get_one(Group.TIM_MANAGER))
263
-            if is_pod_admin:
278
+            if is_tracim_admin:
264 279
                 user.groups.append(group_api.get_one(Group.TIM_ADMIN))
265 280
 
266 281
         api.save(user)

+ 1 - 1
tracim/tracim/controllers/user.py View File

@@ -96,7 +96,7 @@ class UserRestController(TIMRestController):
96 96
         pass
97 97
 
98 98
     @tg.expose()
99
-    def post(self, name, email, password, is_pod_manager='off', is_pod_admin='off'):
99
+    def post(self, name, email, password, is_tracim_manager='off', is_pod_admin='off'):
100 100
         pass
101 101
 
102 102
     @tg.expose('tracim.templates.user_get_me')

+ 1 - 0
tracim/tracim/templates/user_edit.mak View File

@@ -1,4 +1,5 @@
1 1
 <%namespace name="TIM" file="tracim.templates.pod"/>
2
+<%namespace name="FORMS" file="tracim.templates.user_workspace_forms"/>
2 3
 
3 4
 <%def name="title()"></%def>
4 5
 

+ 12 - 12
tracim/tracim/templates/user_get_all.mak View File

@@ -39,12 +39,12 @@
39 39
                                     </div>
40 40
                                     <div class="checkbox">
41 41
                                       <label>
42
-                                        <input type="checkbox" class="checkbox" name="is_pod_manager" id="is-pod-manager"> ${_('This user can create workspaces')}
42
+                                        <input type="checkbox" class="checkbox" name="is_tracim_manager" id="is-tracim-manager"> ${_('This user can create workspaces')}
43 43
                                       </label>
44 44
                                     </div>
45 45
                                     <div class="checkbox disabled">
46 46
                                       <label>
47
-                                        <input type="checkbox" class="checkbox" disabled name="is_pod_admin" id="is-pod-admin"> ${_('This user is an administrator')}
47
+                                        <input type="checkbox" class="checkbox" disabled name="is_tracim_admin" id="is-tracim-admin"> ${_('This user is an administrator')}
48 48
                                       </label>
49 49
                                     </div>
50 50
                                         
@@ -53,16 +53,16 @@
53 53
                                     </span>
54 54
                                     <script>
55 55
                                         $(document).ready(function() {
56
-                                            $('#is-pod-manager').change(function() {
57
-                                                if($('#is-pod-manager').prop('checked')==true) {
56
+                                            $('#is-tracim-manager').change(function() {
57
+                                                if($('#is-tracim-manager').prop('checked')==true) {
58 58
                                                     console.log('now manager is checked');
59
-                                                    $('#is-pod-admin').removeAttr('disabled');
60
-                                                    $('#is-pod-admin').parent().parent().removeClass('disabled');
59
+                                                    $('#is-tracim-admin').removeAttr('disabled');
60
+                                                    $('#is-tracim-admin').parent().parent().removeClass('disabled');
61 61
                                                 } else {
62 62
                                                     console.log('now manager is unchecked');
63
-                                                    $('#is-pod-admin').prop('checked', false);
64
-                                                    $('#is-pod-admin').attr('disabled', 'disabled');
65
-                                                    $('#is-pod-admin').parent().parent().addClass('disabled');
63
+                                                    $('#is-tracim-admin').prop('checked', false);
64
+                                                    $('#is-tracim-admin').attr('disabled', 'disabled');
65
+                                                    $('#is-tracim-admin').parent().parent().addClass('disabled');
66 66
                                                 }
67 67
                                             });
68 68
                                         });
@@ -103,12 +103,12 @@
103 103
                                         <td><a href="mailto:${user.email}">${user.email}</a></td>
104 104
                                         <td>
105 105
                                             <% icon = ('emblems/emblem-unreadable', 'emblems/emblem-checked')[user.profile.id>=2] %>
106
-                                            <% linked_profile = ('pod-manager', 'pod-user')[user.profile.id>=2] %>
106
+                                            <% linked_profile = ('tracim-profile-manager', 'tracim-profile-user')[user.profile.id>=2] %>
107 107
                                             <a href="${tg.url('/admin/users/{}/profile/switch?new_role={}'.format(user.id, linked_profile))}">${TIM.ICO(16, icon)}</a>
108 108
                                         </td>
109 109
                                         <td>
110 110
                                             <% icon = ('emblems/emblem-unreadable', 'emblems/emblem-checked')[user.profile.id>=3] %>
111
-                                            <% linked_profile = ('pod-admin', 'pod-manager')[user.profile.id>=3] %>
111
+                                            <% linked_profile = ('tracim-profile-admin', 'tracim-profile-manager')[user.profile.id>=3] %>
112 112
                                             <a href="${tg.url('/admin/users/{}/profile/switch?new_role={}'.format(user.id, linked_profile))}">${TIM.ICO(16, icon)}</a>
113 113
                                         </td>
114 114
                                     % else:
@@ -121,7 +121,7 @@
121 121
                                         </td>
122 122
                                         <td>
123 123
                                             <% icon = ('emblems/emblem-unreadable-disabled', 'emblems/emblem-checked-disabled')[user.profile.id>=3] %>
124
-                                            <% linked_profile = ('pod-admin', 'pod-manager')[user.profile.id>=3] %>
124
+                                            <% linked_profile = ('tracim-profile-admin', 'tracim-profile-manager')[user.profile.id>=3] %>
125 125
                                             ${TIM.ICO(16, icon)}
126 126
                                         </td>
127 127
                                     % endif