allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [22/35] git commit: [#7657] ticket:651 Use email addresses widget on admin page
Date Wed, 17 Sep 2014 13:34:09 GMT
[#7657] ticket:651 Use email addresses widget on admin page


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/85495514
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/85495514
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/85495514

Branch: refs/heads/je/42cc_7657
Commit: 8549551432f21a89b85f707238d59f947b497bae
Parents: 6adf0ac
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 16 13:47:01 2014 +0300
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Wed Sep 17 16:11:37 2014 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py               | 42 ++++-----
 Allura/allura/controllers/site_admin.py         | 12 ++-
 .../templates/site_admin_user_details.html      | 12 +++
 Allura/allura/templates/update_emails_form.html | 93 ++++++++++----------
 Allura/allura/templates/user_prefs.html         |  5 +-
 5 files changed, 94 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/85495514/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 8d254bb..0e4b4c4 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -430,69 +430,69 @@ class PreferencesController(BaseController):
         c.upload_key_form = F.upload_key_form
         provider = plugin.AuthenticationProvider.get(request)
         menu = provider.account_navigation()
-        return dict(menu=menu)
+        return dict(menu=menu, user=c.user)
 
-    def _update_emails(self, **kw):
+    def _update_emails(self, user, admin=False, **kw):
         addr = kw.pop('addr', None)
         new_addr= kw.pop('new_addr', None)
         primary_addr = kw.pop('primary_addr', None)
         oid = kw.pop('oid', None)
         new_oid = kw.pop('new_oid', None)
         provider = plugin.AuthenticationProvider.get(request)
-        for i, (old_a, data) in enumerate(zip(c.user.email_addresses, addr or [])):
-            obj = c.user.address_object(old_a)
+        for i, (old_a, data) in enumerate(zip(user.email_addresses, addr or [])):
+            obj = user.address_object(old_a)
             if data.get('delete') or not obj:
-                if not kw.get('password') or not provider.validate_password(c.user, kw.get('password')):
+                if not admin and (not kw.get('password') or not provider.validate_password(user,
kw.get('password'))):
                     flash('You must provide your current password to delete an email', 'error')
                     return
-                if primary_addr == c.user.email_addresses[i]:
-                    if select_new_primary_addr(c.user, ignore_emails=primary_addr) is None
\
+                if primary_addr == user.email_addresses[i]:
+                    if select_new_primary_addr(user, ignore_emails=primary_addr) is None
\
                             and asbool(config.get('auth.require_email_addr', False)):
                         flash('You must have at least one verified email address.', 'error')
                         return
                     else:
                         # clear it now, a new one will get set below
-                        c.user.set_pref('email_address', None)
+                        user.set_pref('email_address', None)
                         primary_addr = None
-                h.auditlog_user('Email address deleted: %s', c.user.email_addresses[i])
-                del c.user.email_addresses[i]
+                h.auditlog_user('Email address deleted: %s', user.email_addresses[i])
+                del user.email_addresses[i]
                 if obj:
                     obj.delete()
         if new_addr.get('claim') or new_addr.get('addr'):
-            if not kw.get('password') or not provider.validate_password(c.user, kw.get('password')):
+            if not admin and (not kw.get('password') or not provider.validate_password(user,
kw.get('password'))):
                 flash('You must provide your current password to claim new email', 'error')
                 return
             if M.EmailAddress.query.get(email=new_addr['addr'], confirmed=True) \
-                    or M.EmailAddress.query.get(email=new_addr['addr'], claimed_by_user_id=c.user._id):
+                    or M.EmailAddress.query.get(email=new_addr['addr'], claimed_by_user_id=user._id):
                 flash('Email address already claimed', 'error')
             elif mail_util.isvalid(new_addr['addr']):
-                c.user.email_addresses.append(new_addr['addr'])
+                user.email_addresses.append(new_addr['addr'])
                 em = M.EmailAddress.create(new_addr['addr'])
-                em.claimed_by_user_id = c.user._id
+                em.claimed_by_user_id = user._id
                 em.send_verification_link()
                 h.auditlog_user('New email address: %s', new_addr['addr'])
                 flash('A verification email has been sent.  Please check your email and click
to confirm.')
             else:
                 flash('Email address %s is invalid' % new_addr['addr'], 'error')
-        if not primary_addr and not c.user.get_pref('email_address') and c.user.email_addresses:
-            primary_addr = select_new_primary_addr(c.user)
+        if not primary_addr and not user.get_pref('email_address') and user.email_addresses:
+            primary_addr = select_new_primary_addr(user)
         if primary_addr:
-            if c.user.get_pref('email_address') != primary_addr:
-                if not kw.get('password') or not provider.validate_password(c.user, kw.get('password')):
+            if user.get_pref('email_address') != primary_addr:
+                if not admin and (not kw.get('password') or not provider.validate_password(user,
kw.get('password'))):
                     flash('You must provide your current password to change primary address',
'error')
                     return
                 h.auditlog_user(
                     'Primary email changed: %s => %s',
-                    c.user.get_pref('email_address'),
+                    user.get_pref('email_address'),
                     primary_addr)
-            c.user.set_pref('email_address', primary_addr)
+            user.set_pref('email_address', primary_addr)
 
     @h.vardec
     @expose()
     @require_post()
     def update_emails(self, **kw):
         if asbool(config.get('auth.allow_edit_prefs', True)):
-            self._update_emails(**kw)
+            self._update_emails(c.user, **kw)
         redirect('.')
 
     @h.vardec

http://git-wip-us.apache.org/repos/asf/allura/blob/85495514/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index c0d9bc8..284c511 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -484,7 +484,7 @@ class AdminUserDetailsController(object):
     @require_post()
     def set_status(self, username=None, status=None):
         user = M.User.by_username(username)
-        if not user:
+        if not user or user.is_anonymous():
             raise HTTPNotFound()
         if status == 'enable' and user.disabled:
             AuthenticationProvider.get(request).enable_user(user)
@@ -494,6 +494,16 @@ class AdminUserDetailsController(object):
             flash('User disabled')
         redirect(request.referer)
 
+    @h.vardec
+    @expose()
+    @require_post()
+    def update_emails(self, username, **kw):
+        user = M.User.by_username(username)
+        if not user or user.is_anonymous():
+            raise HTTPNotFound()
+        allura.controllers.auth.PreferencesController()._update_emails(user, admin=True,
**kw)
+        redirect(request.referer)
+
 
 class StatsSiteAdminExtension(SiteAdminExtension):
     controllers = {'stats': StatsController}

http://git-wip-us.apache.org/repos/asf/allura/blob/85495514/Allura/allura/templates/site_admin_user_details.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_user_details.html b/Allura/allura/templates/site_admin_user_details.html
index 8ffe9a5..d7095b7 100644
--- a/Allura/allura/templates/site_admin_user_details.html
+++ b/Allura/allura/templates/site_admin_user_details.html
@@ -49,6 +49,18 @@
     </div>
   {% endblock general_info %}
 
+  {% block emails %}
+    <div class="grid-23">
+      <fieldset>
+        <legend>Emails</legend>
+        <form action="update_emails" method="post">
+          {% include 'allura:templates/update_emails_form.html' %}
+          <input type='hidden' name='username' value='{{ user.username }}'>
+        </form>
+      </fieldset>
+    </div>
+  {% endblock emails %}
+
   {% block session_info %}
     <div class="grid-23">
       <fieldset>

http://git-wip-us.apache.org/repos/asf/allura/blob/85495514/Allura/allura/templates/update_emails_form.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/update_emails_form.html b/Allura/allura/templates/update_emails_form.html
index 20aecce..3ac5502 100644
--- a/Allura/allura/templates/update_emails_form.html
+++ b/Allura/allura/templates/update_emails_form.html
@@ -16,53 +16,52 @@
        specific language governing permissions and limitations
        under the License.
 -#}
-<form action="update_emails" method="post" name="update-email">
-  {% for a in c.user.email_addresses %}
-    <input name="addr-{{loop.index0}}.ord" value="{{loop.index0}}" type="hidden"/>
-  {% endfor %}
-  <table class="grid-22">
-    <tr>
-      <th>Primary?</th>
-      <th>Address</th>
-      <th>Confirmed</th>
-      <th></th>
-    </tr>
-    {% for a in c.user.email_addresses %}
-    <tr>
-      {% set obj = c.user.address_object(a) %}
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+
+{% for a in user.email_addresses %}
+  <input name="addr-{{loop.index0}}.ord" value="{{loop.index0}}" type="hidden"/>
+{% endfor %}
+<table class="grid-22">
+  <tr>
+    <th>Primary?</th>
+    <th>Address</th>
+    <th>Confirmed</th>
+    <th></th>
+  </tr>
+  {% for a in user.email_addresses %}
+  <tr>
+    {% set obj = user.address_object(a) %}
+    {% if obj.confirmed %}
+      <td>{{lib.radio_button('primary_addr', None, a, user.preferences.email_address)}}</td>
+    {% else %}
+      <td> <input type="radio" disabled="disabled"></td>
+    {% endif %}
+    <td>{{a}}</td>
+    {% if obj %}
+    <td>
       {% if obj.confirmed %}
-        <td>{{lib.radio_button('primary_addr', None, a, c.user.preferences.email_address)}}</td>
+        yes
       {% else %}
-        <td> <input type="radio" disabled="disabled"></td>
+        no (<a href="/auth/send_verification_link?a={{a}}">verify</a>)
       {% endif %}
-      <td>{{a}}</td>
-      {% if obj %}
-      <td>
-        {% if obj.confirmed %}
-          yes
-        {% else %}
-          no (<a href="/auth/send_verification_link?a={{a}}">verify</a>)
-        {% endif %}
-      </td>
-      {% else %}
-        <td>Unknown addr obj {{a}}</td>
-      {% endif %}
-      <td>
-        <div class="addr-delete">
-          {{lib.submit_button('Delete', 'addr-%s.delete' % loop.index0)}}
-          {{lib.hidden_field('addr-%s.delete' % loop.index0, '')}}
-        </div>
-      </td>
-    </tr>
-    {% endfor %}
-    <tr>
-      <td colspan="2">{{lib.text_field('new_addr.addr', '')}}</td>
-      <td colspan="2">{{lib.submit_button('Claim New Address', name='new_addr.claim')}}</td>
-    </tr>
-  </table>
-  <div class="grid-22">
-    {{lib.submit_button('Save', name='addr-save')}}
-  </div>
-  {{lib.hidden_field('password', '')}}
-  {{lib.csrf_token()}}
-</form>
+    </td>
+    {% else %}
+      <td>Unknown addr obj {{a}}</td>
+    {% endif %}
+    <td>
+      <div class="addr-delete">
+        {{lib.submit_button('Delete', 'addr-%s.delete' % loop.index0)}}
+        {{lib.hidden_field('addr-%s.delete' % loop.index0, '')}}
+      </div>
+    </td>
+  </tr>
+  {% endfor %}
+  <tr>
+    <td colspan="2">{{lib.text_field('new_addr.addr', '')}}</td>
+    <td colspan="2">{{lib.submit_button('Claim New Address', name='new_addr.claim')}}</td>
+  </tr>
+</table>
+<div class="grid-22">
+  {{lib.submit_button('Save', name='addr-save')}}
+</div>
+{{lib.csrf_token()}}

http://git-wip-us.apache.org/repos/asf/allura/blob/85495514/Allura/allura/templates/user_prefs.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_prefs.html b/Allura/allura/templates/user_prefs.html
index a19ae4e..bc8cf42 100644
--- a/Allura/allura/templates/user_prefs.html
+++ b/Allura/allura/templates/user_prefs.html
@@ -66,7 +66,10 @@
 
         <fieldset>
           <legend>Email addresses</legend>
-          {% include 'allura:templates/update_emails_form.html' %}
+          <form action="update_emails" method="post" name="update-email">
+            {% include 'allura:templates/update_emails_form.html' %}
+            {{lib.hidden_field('password', '')}}
+          </form>
         </fieldset>
 
       <!-- popup -->


Mime
View raw message