Show More
@@ -212,6 +212,10 b' def make_map(config):' | |||
|
212 | 212 | #EXTRAS USER ROUTES |
|
213 | 213 | m.connect("user_perm", "/users_perm/{id}", |
|
214 | 214 | action="update_perm", conditions=dict(method=["PUT"])) |
|
215 | m.connect("user_emails", "/users_emails/{id}", | |
|
216 | action="add_email", conditions=dict(method=["PUT"])) | |
|
217 | m.connect("user_emails_delete", "/users_emails/{id}", | |
|
218 | action="delete_email", conditions=dict(method=["DELETE"])) | |
|
215 | 219 | |
|
216 | 220 | #ADMIN USERS REST ROUTES |
|
217 | 221 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
@@ -38,7 +38,7 b' from rhodecode.lib import helpers as h' | |||
|
38 | 38 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
|
39 | 39 | from rhodecode.lib.base import BaseController, render |
|
40 | 40 | |
|
41 | from rhodecode.model.db import User, Permission | |
|
41 | from rhodecode.model.db import User, Permission, UserEmailMap | |
|
42 | 42 | from rhodecode.model.forms import UserForm |
|
43 | 43 | from rhodecode.model.user import UserModel |
|
44 | 44 | from rhodecode.model.meta import Session |
@@ -171,7 +171,8 b' class UsersController(BaseController):' | |||
|
171 | 171 | c.user.permissions = {} |
|
172 | 172 | c.granted_permissions = UserModel().fill_perms(c.user)\ |
|
173 | 173 | .permissions['global'] |
|
174 | ||
|
174 | c.user_email_map = UserEmailMap.query()\ | |
|
175 | .filter(UserEmailMap.user == c.user).all() | |
|
175 | 176 | defaults = c.user.get_dict() |
|
176 | 177 | perm = Permission.get_by_key('hg.create.repository') |
|
177 | 178 | defaults.update({'create_repo_perm': UserModel().has_perm(id, perm)}) |
@@ -209,3 +210,30 b' class UsersController(BaseController):' | |||
|
209 | 210 | category='success') |
|
210 | 211 | Session.commit() |
|
211 | 212 | return redirect(url('edit_user', id=id)) |
|
213 | ||
|
214 | def add_email(self, id): | |
|
215 | """PUT /user_emails/id: Update an existing item""" | |
|
216 | # url('user_emails', id=ID, method='put') | |
|
217 | ||
|
218 | #TODO: validation and form !!! | |
|
219 | email = request.POST.get('new_email') | |
|
220 | user_model = UserModel() | |
|
221 | ||
|
222 | try: | |
|
223 | user_model.add_extra_email(id, email) | |
|
224 | Session.commit() | |
|
225 | h.flash(_("Added email %s to user" % email), category='success') | |
|
226 | except Exception: | |
|
227 | log.error(traceback.format_exc()) | |
|
228 | h.flash(_('An error occurred during email saving'), | |
|
229 | category='error') | |
|
230 | return redirect(url('edit_user', id=id)) | |
|
231 | ||
|
232 | def delete_email(self, id): | |
|
233 | """DELETE /user_emails_delete/id: Delete an existing item""" | |
|
234 | # url('user_emails_delete', id=ID, method='delete') | |
|
235 | user_model = UserModel() | |
|
236 | user_model.delete_extra_email(id, request.POST.get('del_email')) | |
|
237 | Session.commit() | |
|
238 | h.flash(_("Removed email from user"), category='success') | |
|
239 | return redirect(url('edit_user', id=id)) |
@@ -36,7 +36,7 b' from rhodecode.model import BaseModel' | |||
|
36 | 36 | from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ |
|
37 | 37 | UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \ |
|
38 | 38 | Notification, RepoGroup, UserRepoGroupToPerm, UsersGroup,\ |
|
39 | UsersGroupRepoGroupToPerm | |
|
39 | UsersGroupRepoGroupToPerm, UserEmailMap | |
|
40 | 40 | from rhodecode.lib.exceptions import DefaultUserException, \ |
|
41 | 41 | UserOwnsReposException |
|
42 | 42 | |
@@ -587,3 +587,29 b' class UserModel(BaseModel):' | |||
|
587 | 587 | .scalar() |
|
588 | 588 | if obj: |
|
589 | 589 | self.sa.delete(obj) |
|
590 | ||
|
591 | def add_extra_email(self, user, email): | |
|
592 | """ | |
|
593 | Adds email address to UserEmailMap | |
|
594 | ||
|
595 | :param user: | |
|
596 | :param email: | |
|
597 | """ | |
|
598 | user = self.__get_user(user) | |
|
599 | obj = UserEmailMap() | |
|
600 | obj.user = user | |
|
601 | obj.email = email | |
|
602 | self.sa.add(obj) | |
|
603 | return obj | |
|
604 | ||
|
605 | def delete_extra_email(self, user, email_id): | |
|
606 | """ | |
|
607 | Removes email address from UserEmailMap | |
|
608 | ||
|
609 | :param user: | |
|
610 | :param email_id: | |
|
611 | """ | |
|
612 | user = self.__get_user(user) | |
|
613 | obj = UserEmailMap.query().get(email_id) | |
|
614 | if obj: | |
|
615 | self.sa.delete(obj) No newline at end of file |
@@ -3712,6 +3712,21 b' div#legend_container table td,div#legend' | |||
|
3712 | 3712 | padding:0px 0px 0px 10px; |
|
3713 | 3713 | } |
|
3714 | 3714 | |
|
3715 | .emails_wrap{ | |
|
3716 | padding: 0px 20px; | |
|
3717 | } | |
|
3718 | ||
|
3719 | .emails_wrap .email_entry{ | |
|
3720 | height: 30px; | |
|
3721 | padding:0px 0px 0px 10px; | |
|
3722 | } | |
|
3723 | .emails_wrap .email_entry .email{ | |
|
3724 | float: left | |
|
3725 | } | |
|
3726 | .emails_wrap .email_entry .email_action{ | |
|
3727 | float: left | |
|
3728 | } | |
|
3729 | ||
|
3715 | 3730 | /*README STYLE*/ |
|
3716 | 3731 | |
|
3717 | 3732 | div.readme { |
@@ -158,4 +158,48 b'' | |||
|
158 | 158 | </div> |
|
159 | 159 | ${h.end_form()} |
|
160 | 160 | </div> |
|
161 | <div class="box box-right"> | |
|
162 | <!-- box / title --> | |
|
163 | <div class="title"> | |
|
164 | <h5>${_('Email addresses')}</h5> | |
|
165 | </div> | |
|
166 | ||
|
167 | <div class="emails_wrap"> | |
|
168 | <table class="noborder"> | |
|
169 | %for em in c.user_email_map: | |
|
170 | <tr> | |
|
171 | <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(em.user.email,16)}"/> </div></td> | |
|
172 | <td><div class="email">${em.email}</div></td> | |
|
173 | <td> | |
|
174 | ${h.form(url('user_emails_delete', id=c.user.user_id),method='delete')} | |
|
175 | ${h.hidden('del_email',em.email_id)} | |
|
176 | ${h.submit('remove_',_('delete'),id="remove_email_%s" % em.email_id, | |
|
177 | class_="delete_icon action_button", onclick="return confirm('"+_('Confirm to delete this email: %s') % em.email+"');")} | |
|
178 | ${h.end_form()} | |
|
179 | </td> | |
|
180 | </tr> | |
|
181 | %endfor | |
|
182 | </table> | |
|
183 | </div> | |
|
184 | ||
|
185 | ${h.form(url('user_emails', id=c.user.user_id),method='put')} | |
|
186 | <div class="form"> | |
|
187 | <!-- fields --> | |
|
188 | <div class="fields"> | |
|
189 | <div class="field"> | |
|
190 | <div class="label"> | |
|
191 | <label for="email">${_('New email address')}:</label> | |
|
192 | </div> | |
|
193 | <div class="input"> | |
|
194 | ${h.text('new_email', class_='medium')} | |
|
195 | </div> | |
|
196 | </div> | |
|
197 | <div class="buttons"> | |
|
198 | ${h.submit('save',_('Add'),class_="ui-button")} | |
|
199 | ${h.reset('reset',_('Reset'),class_="ui-button")} | |
|
200 | </div> | |
|
201 | </div> | |
|
202 | </div> | |
|
203 | ${h.end_form()} | |
|
204 | </div> | |
|
161 | 205 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now