diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -212,6 +212,10 @@ def make_map(config): #EXTRAS USER ROUTES m.connect("user_perm", "/users_perm/{id}", action="update_perm", conditions=dict(method=["PUT"])) + m.connect("user_emails", "/users_emails/{id}", + action="add_email", conditions=dict(method=["PUT"])) + m.connect("user_emails_delete", "/users_emails/{id}", + action="delete_email", conditions=dict(method=["DELETE"])) #ADMIN USERS REST ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, diff --git a/rhodecode/controllers/admin/users.py b/rhodecode/controllers/admin/users.py --- a/rhodecode/controllers/admin/users.py +++ b/rhodecode/controllers/admin/users.py @@ -38,7 +38,7 @@ from rhodecode.lib import helpers as h from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator from rhodecode.lib.base import BaseController, render -from rhodecode.model.db import User, Permission +from rhodecode.model.db import User, Permission, UserEmailMap from rhodecode.model.forms import UserForm from rhodecode.model.user import UserModel from rhodecode.model.meta import Session @@ -171,7 +171,8 @@ class UsersController(BaseController): c.user.permissions = {} c.granted_permissions = UserModel().fill_perms(c.user)\ .permissions['global'] - + c.user_email_map = UserEmailMap.query()\ + .filter(UserEmailMap.user == c.user).all() defaults = c.user.get_dict() perm = Permission.get_by_key('hg.create.repository') defaults.update({'create_repo_perm': UserModel().has_perm(id, perm)}) @@ -209,3 +210,30 @@ class UsersController(BaseController): category='success') Session.commit() return redirect(url('edit_user', id=id)) + + def add_email(self, id): + """PUT /user_emails/id: Update an existing item""" + # url('user_emails', id=ID, method='put') + + #TODO: validation and form !!! + email = request.POST.get('new_email') + user_model = UserModel() + + try: + user_model.add_extra_email(id, email) + Session.commit() + h.flash(_("Added email %s to user" % email), category='success') + except Exception: + log.error(traceback.format_exc()) + h.flash(_('An error occurred during email saving'), + category='error') + return redirect(url('edit_user', id=id)) + + def delete_email(self, id): + """DELETE /user_emails_delete/id: Delete an existing item""" + # url('user_emails_delete', id=ID, method='delete') + user_model = UserModel() + user_model.delete_extra_email(id, request.POST.get('del_email')) + Session.commit() + h.flash(_("Removed email from user"), category='success') + return redirect(url('edit_user', id=id)) diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -36,7 +36,7 @@ from rhodecode.model import BaseModel from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \ Notification, RepoGroup, UserRepoGroupToPerm, UsersGroup,\ - UsersGroupRepoGroupToPerm + UsersGroupRepoGroupToPerm, UserEmailMap from rhodecode.lib.exceptions import DefaultUserException, \ UserOwnsReposException @@ -587,3 +587,29 @@ class UserModel(BaseModel): .scalar() if obj: self.sa.delete(obj) + + def add_extra_email(self, user, email): + """ + Adds email address to UserEmailMap + + :param user: + :param email: + """ + user = self.__get_user(user) + obj = UserEmailMap() + obj.user = user + obj.email = email + self.sa.add(obj) + return obj + + def delete_extra_email(self, user, email_id): + """ + Removes email address from UserEmailMap + + :param user: + :param email_id: + """ + user = self.__get_user(user) + obj = UserEmailMap.query().get(email_id) + if obj: + self.sa.delete(obj) \ No newline at end of file diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -3712,6 +3712,21 @@ div#legend_container table td,div#legend padding:0px 0px 0px 10px; } +.emails_wrap{ + padding: 0px 20px; +} + +.emails_wrap .email_entry{ + height: 30px; + padding:0px 0px 0px 10px; +} +.emails_wrap .email_entry .email{ + float: left +} +.emails_wrap .email_entry .email_action{ + float: left +} + /*README STYLE*/ div.readme { diff --git a/rhodecode/templates/admin/users/user_edit.html b/rhodecode/templates/admin/users/user_edit.html --- a/rhodecode/templates/admin/users/user_edit.html +++ b/rhodecode/templates/admin/users/user_edit.html @@ -158,4 +158,48 @@ ${h.end_form()} +
${em.email} |
+ + ${h.form(url('user_emails_delete', id=c.user.user_id),method='delete')} + ${h.hidden('del_email',em.email_id)} + ${h.submit('remove_',_('delete'),id="remove_email_%s" % em.email_id, + class_="delete_icon action_button", onclick="return confirm('"+_('Confirm to delete this email: %s') % em.email+"');")} + ${h.end_form()} + | +