##// END OF EJS Templates
#56 added ajax removal of users groups,...
marcink -
r1015:65129c33 beta
parent child Browse files
Show More
@@ -0,0 +1,95 b''
1 <table id="permissions_manage">
2 <tr>
3 <td>${_('none')}</td>
4 <td>${_('read')}</td>
5 <td>${_('write')}</td>
6 <td>${_('admin')}</td>
7 <td>${_('member')}</td>
8 <td></td>
9 </tr>
10 ## USERS
11 <script type="text/javascript">
12 function ajaxActionUser(user_id,field_id){
13 var sUrl = "${h.url('delete_repo_user',repo_name=c.repo_name)}";
14 var callback = { success:function(o){
15 var tr = YUD.get(String(field_id));
16 tr.parentNode.removeChild(tr);},
17 failure:function(o){
18 alert("${_('Failed to remove user')}");},};
19 var postData = '_method=delete&user_id='+user_id;
20 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
21 </script>
22 %for r2p in c.repo_info.repo_to_perm:
23 %if r2p.user.username =='default' and c.repo_info.private:
24 <tr>
25 <td colspan="4">
26 <span class="private_repo_msg">
27 ${_('private repository')}
28 </span>
29 </td>
30 <td class="private_repo_msg"><img style="vertical-align:bottom" src="/images/icons/user.png"/>${r2p.user.username}</td>
31 </tr>
32 %else:
33 <tr id="id${id(r2p.user.username)}">
34 <td>${h.radio('u_perm_%s' % r2p.user.username,'repository.none')}</td>
35 <td>${h.radio('u_perm_%s' % r2p.user.username,'repository.read')}</td>
36 <td>${h.radio('u_perm_%s' % r2p.user.username,'repository.write')}</td>
37 <td>${h.radio('u_perm_%s' % r2p.user.username,'repository.admin')}</td>
38 <td style="white-space: nowrap;"><img style="vertical-align:bottom" src="/images/icons/user.png"/>${r2p.user.username}</td>
39 <td>
40 %if r2p.user.username !='default':
41 <span class="delete_icon action_button" onclick="ajaxActionUser(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
42 </span>
43 %endif
44 </td>
45 </tr>
46 %endif
47 %endfor
48
49 ## USERS GROUPS
50 <script type="text/javascript">
51 function ajaxActionUsersGroup(users_group_id,field_id){
52 var sUrl = "${h.url('delete_repo_users_group',repo_name=c.repo_name)}";
53 var callback = { success:function(o){
54 var tr = YUD.get(String(field_id));
55 tr.parentNode.removeChild(tr);},
56 failure:function(o){
57 alert("${_('Failed to remove users group')}");},};
58 var postData = '_method=delete&users_group_id='+users_group_id;
59 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
60 </script>
61 %for g2p in c.repo_info.users_group_to_perm:
62 <tr id="id${id(g2p.users_group.users_group_name)}">
63 <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'repository.none')}</td>
64 <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'repository.read')}</td>
65 <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'repository.write')}</td>
66 <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'repository.admin')}</td>
67 <td><img style="vertical-align:bottom" src="/images/icons/group.png"/>${g2p.users_group.users_group_name}</td>
68 <td>
69 <span class="delete_icon action_button" onclick="ajaxActionUsersGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')">
70 </span>
71 </td>
72 </tr>
73 %endfor
74 <tr id="add_perm_input">
75 <td>${h.radio('perm_new_member','repository.none')}</td>
76 <td>${h.radio('perm_new_member','repository.read')}</td>
77 <td>${h.radio('perm_new_member','repository.write')}</td>
78 <td>${h.radio('perm_new_member','repository.admin')}</td>
79 <td class='ac'>
80 <div class="perm_ac" id="perm_ac">
81 ${h.text('perm_new_member_name',class_='yui-ac-input')}
82 ${h.hidden('perm_new_member_type')}
83 <div id="perm_container"></div>
84 </div>
85 </td>
86 <td></td>
87 </tr>
88 <tr>
89 <td colspan="6">
90 <span id="add_perm" class="add_icon" style="cursor: pointer;">
91 ${_('Add another member')}
92 </span>
93 </td>
94 </tr>
95 </table> No newline at end of file
@@ -73,6 +73,11 b' def make_map(config):'
73 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}",
73 m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}",
74 action="delete_perm_user", conditions=dict(method=["DELETE"],
74 action="delete_perm_user", conditions=dict(method=["DELETE"],
75 function=check_repo))
75 function=check_repo))
76 #ajax delete repo perm users_group
77 m.connect('delete_repo_users_group', "/repos_delete_users_group/{repo_name:.*}",
78 action="delete_perm_users_group", conditions=dict(method=["DELETE"],
79 function=check_repo))
80
76 #settings actions
81 #settings actions
77 m.connect('repo_stats', "/repos_stats/{repo_name:.*}",
82 m.connect('repo_stats', "/repos_stats/{repo_name:.*}",
78 action="repo_stats", conditions=dict(method=["DELETE"],
83 action="repo_stats", conditions=dict(method=["DELETE"],
@@ -215,8 +215,8 b' class ReposController(BaseController):'
215
215
216 @HasPermissionAllDecorator('hg.admin')
216 @HasPermissionAllDecorator('hg.admin')
217 def delete_perm_user(self, repo_name):
217 def delete_perm_user(self, repo_name):
218 """
218 """DELETE an existing repository permission user
219 DELETE an existing repository permission user
219
220 :param repo_name:
220 :param repo_name:
221 """
221 """
222
222
@@ -229,9 +229,24 b' class ReposController(BaseController):'
229 raise HTTPInternalServerError()
229 raise HTTPInternalServerError()
230
230
231 @HasPermissionAllDecorator('hg.admin')
231 @HasPermissionAllDecorator('hg.admin')
232 def repo_stats(self, repo_name):
232 def delete_perm_users_group(self, repo_name):
233 """DELETE an existing repository permission users group
234
235 :param repo_name:
233 """
236 """
234 DELETE an existing repository statistics
237 try:
238 repo_model = RepoModel()
239 repo_model.delete_perm_users_group(request.POST, repo_name)
240 except Exception, e:
241 h.flash(_('An error occurred during deletion of repository'
242 ' users groups'),
243 category='error')
244 raise HTTPInternalServerError()
245
246 @HasPermissionAllDecorator('hg.admin')
247 def repo_stats(self, repo_name):
248 """DELETE an existing repository statistics
249
235 :param repo_name:
250 :param repo_name:
236 """
251 """
237
252
@@ -245,8 +260,8 b' class ReposController(BaseController):'
245
260
246 @HasPermissionAllDecorator('hg.admin')
261 @HasPermissionAllDecorator('hg.admin')
247 def repo_cache(self, repo_name):
262 def repo_cache(self, repo_name):
248 """
263 """INVALIDATE existing repository cache
249 INVALIDATE existing repository cache
264
250 :param repo_name:
265 :param repo_name:
251 """
266 """
252
267
@@ -267,8 +282,9 b' class ReposController(BaseController):'
267 """GET /repos/repo_name/edit: Form to edit an existing item"""
282 """GET /repos/repo_name/edit: Form to edit an existing item"""
268 # url('edit_repo', repo_name=ID)
283 # url('edit_repo', repo_name=ID)
269 repo_model = RepoModel()
284 repo_model = RepoModel()
285 c.repo_info = repo_model.get_by_repo_name(repo_name)
286
270 r = ScmModel().get(repo_name)
287 r = ScmModel().get(repo_name)
271 c.repo_info = repo_model.get_by_repo_name(repo_name)
272
288
273 if c.repo_info is None:
289 if c.repo_info is None:
274 h.flash(_('%s repository is not mapped to db perhaps'
290 h.flash(_('%s repository is not mapped to db perhaps'
@@ -293,7 +309,12 b' class ReposController(BaseController):'
293 c.stats_percentage = '%.2f' % ((float((last_rev)) /
309 c.stats_percentage = '%.2f' % ((float((last_rev)) /
294 c.repo_last_rev) * 100)
310 c.repo_last_rev) * 100)
295
311
312 c.users_array = repo_model.get_users_js()
313 c.users_groups_array = repo_model.get_users_groups_js()
314
296 defaults = c.repo_info.get_dict()
315 defaults = c.repo_info.get_dict()
316
317 #fill owner
297 if c.repo_info.user:
318 if c.repo_info.user:
298 defaults.update({'user':c.repo_info.user.username})
319 defaults.update({'user':c.repo_info.user.username})
299 else:
320 else:
@@ -301,11 +322,15 b' class ReposController(BaseController):'
301 .filter(User.admin == True).first().username
322 .filter(User.admin == True).first().username
302 defaults.update({'user':replacement_user})
323 defaults.update({'user':replacement_user})
303
324
304 c.users_array = repo_model.get_users_js()
305 c.users_groups_array = repo_model.get_users_groups_js()
306
325
326 #fill repository users
307 for p in c.repo_info.repo_to_perm:
327 for p in c.repo_info.repo_to_perm:
308 defaults.update({'perm_%s' % p.user.username:
328 defaults.update({'u_perm_%s' % p.user.username:
329 p.permission.permission_name})
330
331 #fill repository groups
332 for p in c.repo_info.users_group_to_perm:
333 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
309 p.permission.permission_name})
334 p.permission.permission_name})
310
335
311 return htmlfill.render(
336 return htmlfill.render(
@@ -41,6 +41,7 b' from rhodecode.lib.base import BaseContr'
41 from rhodecode.lib.utils import invalidate_cache, action_logger
41 from rhodecode.lib.utils import invalidate_cache, action_logger
42 from rhodecode.model.forms import RepoSettingsForm, RepoForkForm
42 from rhodecode.model.forms import RepoSettingsForm, RepoForkForm
43 from rhodecode.model.repo import RepoModel
43 from rhodecode.model.repo import RepoModel
44 from rhodecode.model.db import User
44
45
45 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
46
47
@@ -62,12 +63,28 b' class SettingsController(BaseController)'
62 category='error')
63 category='error')
63
64
64 return redirect(url('home'))
65 return redirect(url('home'))
65 defaults = c.repo_info.get_dict()
66
66 defaults.update({'user':c.repo_info.user.username})
67 c.users_array = repo_model.get_users_js()
67 c.users_array = repo_model.get_users_js()
68 c.users_groups_array = repo_model.get_users_groups_js()
68
69
70 defaults = c.repo_info.get_dict()
71
72 #fill owner
73 if c.repo_info.user:
74 defaults.update({'user':c.repo_info.user.username})
75 else:
76 replacement_user = self.sa.query(User)\
77 .filter(User.admin == True).first().username
78 defaults.update({'user':replacement_user})
79
80 #fill repository users
69 for p in c.repo_info.repo_to_perm:
81 for p in c.repo_info.repo_to_perm:
70 defaults.update({'perm_%s' % p.user.username:
82 defaults.update({'u_perm_%s' % p.user.username:
83 p.permission.permission_name})
84
85 #fill repository groups
86 for p in c.repo_info.users_group_to_perm:
87 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
71 p.permission.permission_name})
88 p.permission.permission_name})
72
89
73 return htmlfill.render(
90 return htmlfill.render(
@@ -202,6 +202,7 b' class Repository(Base, BaseModel):'
202 fork = relationship('Repository', remote_side=repo_id)
202 fork = relationship('Repository', remote_side=repo_id)
203 group = relationship('Group')
203 group = relationship('Group')
204 repo_to_perm = relationship('RepoToPerm', cascade='all')
204 repo_to_perm = relationship('RepoToPerm', cascade='all')
205 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
205 stats = relationship('Statistics', cascade='all', uselist=False)
206 stats = relationship('Statistics', cascade='all', uselist=False)
206
207
207 repo_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
208 repo_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
@@ -246,24 +246,25 b' class ValidPerms(formencode.validators.F'
246 perms_new = []
246 perms_new = []
247 #build a list of permission to update and new permission to create
247 #build a list of permission to update and new permission to create
248 for k, v in value.items():
248 for k, v in value.items():
249 if k.startswith('perm_'):
249 #means new added member to permissions
250 if k.startswith('perm_new_member'):
250 if k.startswith('perm_new_member'):
251 #means new added member to permissions
251 new_perm = value.get('perm_new_member', False)
252 new_perm = value.get('perm_new_member', False)
252 new_member = value.get('perm_new_member_name', False)
253 new_member = value.get('perm_new_member_name', False)
253 new_type = value.get('perm_new_member_type')
254 new_type = value.get('perm_new_member_type')
255
254
256 if new_member and new_perm:
255 if new_member and new_perm:
257 if (new_member, new_perm, new_type) not in perms_new:
256 if (new_member, new_perm, new_type) not in perms_new:
258 perms_new.append((new_member, new_perm, new_type))
257 perms_new.append((new_member, new_perm, new_type))
259 else:
258 elif k.startswith('u_perm_') or k.startswith('g_perm_'):
260 usr = k[5:]
259 member = k[7:]
261 t = 'user'
260 t = {'u':'user',
262 if usr == 'default':
261 'g':'users_group'}[k[0]]
263 if value['private']:
262 if member == 'default':
264 #set none for default when updating to private repo
263 if value['private']:
265 v = 'repository.none'
264 #set none for default when updating to private repo
266 perms_update.append((usr, v, t))
265 v = 'repository.none'
266 perms_update.append((member, v, t))
267
267 value['perms_updates'] = perms_update
268 value['perms_updates'] = perms_update
268 value['perms_new'] = perms_new
269 value['perms_new'] = perms_new
269
270
@@ -352,8 +353,10 b' class AttrLoginValidator(formencode.vali'
352 def to_python(self, value, state):
353 def to_python(self, value, state):
353
354
354 if not value or not isinstance(value, (str, unicode)):
355 if not value or not isinstance(value, (str, unicode)):
355 raise formencode.Invalid(_("The LDAP Login attribute of the CN must be specified "
356 raise formencode.Invalid(_("The LDAP Login attribute of the CN "
356 "- this is the name of the attribute that is equivalent to 'username'"),
357 "must be specified - this is the name "
358 "of the attribute that is equivalent "
359 "to 'username'"),
357 value, state)
360 value, state)
358
361
359 return value
362 return value
@@ -255,6 +255,19 b' class RepoModel(BaseModel):'
255 self.sa.rollback()
255 self.sa.rollback()
256 raise
256 raise
257
257
258 def delete_perm_users_group(self, form_data, repo_name):
259 try:
260 self.sa.query(UsersGroupToPerm)\
261 .filter(UsersGroupToPerm.repository \
262 == self.get_by_repo_name(repo_name))\
263 .filter(UsersGroupToPerm.users_group_id \
264 == form_data['users_group_id']).delete()
265 self.sa.commit()
266 except:
267 log.error(traceback.format_exc())
268 self.sa.rollback()
269 raise
270
258 def delete_stats(self, repo_name):
271 def delete_stats(self, repo_name):
259 try:
272 try:
260 self.sa.query(Statistics)\
273 self.sa.query(Statistics)\
@@ -93,76 +93,8 b''
93 <label for="input">${_('Permissions')}:</label>
93 <label for="input">${_('Permissions')}:</label>
94 </div>
94 </div>
95 <div class="input">
95 <div class="input">
96 <table id="permissions_manage">
96 <%include file="repo_edit_perms.html"/>
97 <tr>
97 </div>
98 <td>${_('none')}</td>
99 <td>${_('read')}</td>
100 <td>${_('write')}</td>
101 <td>${_('admin')}</td>
102 <td>${_('member')}</td>
103 <td></td>
104 </tr>
105
106 %for r2p in c.repo_info.repo_to_perm:
107 %if r2p.user.username =='default' and c.repo_info.private:
108 <tr>
109 <td colspan="4">
110 <span class="private_repo_msg">
111 ${_('private repository')}
112 </span>
113 </td>
114 <td class="private_repo_msg">${r2p.user.username}</td>
115 </tr>
116 %else:
117 <tr id="id${id(r2p.user.username)}">
118 <td>${h.radio('perm_%s' % r2p.user.username,'repository.none')}</td>
119 <td>${h.radio('perm_%s' % r2p.user.username,'repository.read')}</td>
120 <td>${h.radio('perm_%s' % r2p.user.username,'repository.write')}</td>
121 <td>${h.radio('perm_%s' % r2p.user.username,'repository.admin')}</td>
122 <td>${r2p.user.username}</td>
123 <td>
124 %if r2p.user.username !='default':
125 <span class="delete_icon action_button" onclick="ajaxAction(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
126 <script type="text/javascript">
127 function ajaxAction(user_id,field_id){
128 var sUrl = "${h.url('delete_repo_user',repo_name=c.repo_name)}";
129 var callback = { success:function(o){
130 var tr = YAHOO.util.Dom.get(String(field_id));
131 tr.parentNode.removeChild(tr);},failure:function(o){
132 alert("${_('Failed to remove user')}");},};
133 var postData = '_method=delete&user_id='+user_id;
134 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
135 </script>
136 </span>
137 %endif
138 </td>
139 </tr>
140 %endif
141 %endfor
142
143 <tr id="add_perm_input">
144 <td>${h.radio('perm_new_member','repository.none')}</td>
145 <td>${h.radio('perm_new_member','repository.read')}</td>
146 <td>${h.radio('perm_new_member','repository.write')}</td>
147 <td>${h.radio('perm_new_member','repository.admin')}</td>
148 <td class='ac'>
149 <div class="perm_ac" id="perm_ac">
150 ${h.text('perm_new_member_name',class_='yui-ac-input')}
151 ${h.hidden('perm_new_member_type')}
152 <div id="perm_container"></div>
153 </div>
154 </td>
155 <td></td>
156 </tr>
157 <tr>
158 <td colspan="6">
159 <span id="add_perm" class="add_icon" style="cursor: pointer;">
160 ${_('Add another member')}
161 </span>
162 </td>
163 </tr>
164 </table>
165 </div>
166
98
167 <div class="buttons">
99 <div class="buttons">
168 ${h.submit('save','Save',class_="ui-button")}
100 ${h.submit('save','Save',class_="ui-button")}
@@ -102,7 +102,7 b''
102 <div>
102 <div>
103 <p class="footer-link">${h.link_to(_('Submit a bug'),h.url('bugtracker'))}</p>
103 <p class="footer-link">${h.link_to(_('Submit a bug'),h.url('bugtracker'))}</p>
104 <p class="footer-link">${h.link_to(_('GPL license'),h.url('gpl_license'))}</p>
104 <p class="footer-link">${h.link_to(_('GPL license'),h.url('gpl_license'))}</p>
105 <p>RhodeCode ${c.rhodecode_version} &copy; 2010 by Marcin Kuzminski</p>
105 <p>RhodeCode ${c.rhodecode_version} &copy; 2010-2011 by Marcin Kuzminski</p>
106 </div>
106 </div>
107 </div>
107 </div>
108 <script type="text/javascript">
108 <script type="text/javascript">
@@ -56,76 +56,8 b''
56 <label for="">${_('Permissions')}:</label>
56 <label for="">${_('Permissions')}:</label>
57 </div>
57 </div>
58 <div class="input">
58 <div class="input">
59 <table id="permissions_manage">
59 <%include file="../admin/repos/repo_edit_perms.html"/>
60 <tr>
60 </div>
61 <td>${_('none')}</td>
62 <td>${_('read')}</td>
63 <td>${_('write')}</td>
64 <td>${_('admin')}</td>
65 <td>${_('user')}</td>
66 <td></td>
67 </tr>
68
69 %for r2p in c.repo_info.repo_to_perm:
70 %if r2p.user.username =='default' and c.repo_info.private:
71 <tr>
72 <td colspan="4">
73 <span class="private_repo_msg">
74 ${_('private repository')}
75 </span>
76 </td>
77 <td class="private_repo_msg">${r2p.user.username}</td>
78 </tr>
79 %else:
80 <tr id="id${id(r2p.user.username)}">
81 <td>${h.radio('perm_%s' % r2p.user.username,'repository.none')}</td>
82 <td>${h.radio('perm_%s' % r2p.user.username,'repository.read')}</td>
83 <td>${h.radio('perm_%s' % r2p.user.username,'repository.write')}</td>
84 <td>${h.radio('perm_%s' % r2p.user.username,'repository.admin')}</td>
85 <td>${r2p.user.username}</td>
86 <td>
87 %if r2p.user.username !='default':
88 <span class="delete_icon action_button" onclick="ajaxAction(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
89 <script type="text/javascript">
90 function ajaxAction(user_id,field_id){
91 var sUrl = "${h.url('delete_repo_user',repo_name=c.repo_name)}";
92 var callback = { success:function(o){
93 var tr = YAHOO.util.Dom.get(String(field_id));
94 tr.parentNode.removeChild(tr);},failure:function(o){
95 alert("${_('Failed to remove user')}");},};
96 var postData = '_method=delete&user_id='+user_id;
97 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
98 </script>
99 </span>
100 %endif
101 </td>
102 </tr>
103 %endif
104 %endfor
105
106
107 <tr id="add_perm_input">
108 <td>${h.radio('perm_new_user','repository.none')}</td>
109 <td>${h.radio('perm_new_user','repository.read')}</td>
110 <td>${h.radio('perm_new_user','repository.write')}</td>
111 <td>${h.radio('perm_new_user','repository.admin')}</td>
112 <td class='ac'>
113 <div class="perm_ac" id="perm_ac">
114 ${h.text('perm_new_user_name',class_='yui-ac-input')}
115 <div id="perm_container"></div>
116 </div>
117 </td>
118 <td></td>
119 </tr>
120 <tr>
121 <td colspan="6">
122 <span id="add_perm" class="add_icon" style="cursor: pointer;">
123 ${_('Add another user')}
124 </span>
125 </td>
126 </tr>
127 </table>
128 </div>
129
61
130 <div class="buttons">
62 <div class="buttons">
131 ${h.submit('update','Update',class_="ui-button")}
63 ${h.submit('update','Update',class_="ui-button")}
General Comments 0
You need to be logged in to leave comments. Login now