allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [4/5] allura git commit: [#6057] ticket:788 Remove unnecessary ForgeLink app admin controller
Date Fri, 05 Jun 2015 13:18:57 GMT
[#6057] ticket:788 Remove unnecessary ForgeLink app admin controller


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

Branch: refs/heads/ib/6057
Commit: 39703d67abe8bdce90128a06a283f98ac94e88a5
Parents: ec8289e
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Jun 5 09:09:58 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Fri Jun 5 09:47:54 2015 +0000

----------------------------------------------------------------------
 ForgeLink/forgelink/link_main.py                | 33 +--------
 .../forgelink/templates/app_admin_options.html  | 77 --------------------
 .../forgelink/tests/functional/test_root.py     | 44 -----------
 3 files changed, 4 insertions(+), 150 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/39703d67/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index cd43d3f..b50c22e 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -15,20 +15,20 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-#-*- python -*-
+# -*- python -*-
 import logging
 import json
 
 # Non-stdlib imports
-from tg import expose, redirect, flash, jsonify
+from tg import expose, jsonify
 from pylons import tmpl_context as c
 from pylons import request
 from formencode import validators as fev
 
 # Pyforge-specific imports
-from allura.app import Application, ConfigOption, SitemapEntry, DefaultAdminController
+from allura.app import Application, ConfigOption, SitemapEntry
 from allura.lib import helpers as h
-from allura.lib.security import require_access, has_access
+from allura.lib.security import require_access
 from allura.lib.utils import permanent_redirect
 from allura import model as M
 from allura.controllers import BaseController
@@ -69,7 +69,6 @@ class ForgeLinkApp(Application):
     def __init__(self, project, config):
         Application.__init__(self, project, config)
         self.root = RootController()
-        self.admin = LinkAdminController(self)
         self.api_root = RootRestController(self)
 
     @property
@@ -126,30 +125,6 @@ class RootController(BaseController):
         return dict()
 
 
-class LinkAdminController(DefaultAdminController):
-
-    @expose()
-    def index(self, **kw):
-        flash('External link URL updated.')
-        redirect(c.project.url() + 'admin/tools')
-
-    @expose('jinja:forgelink:templates/app_admin_options.html')
-    def options(self):
-        return dict(
-            app=self.app,
-            allow_config=has_access(self.app, 'configure')())
-
-    @expose('json:')
-    def set_url(self, **kw):
-        validator = fev.URL(not_empty=True, add_http=True)
-        try:
-            url = validator.to_python(kw.get('url'))
-        except fev.Invalid as e:
-            return {'status': 'error', 'errors': {'url': e.msg}}
-        self.app.config.options['url'] = url
-        return {'status': 'ok'}
-
-
 class RootRestController(BaseController, AppRestControllerMixin):
 
     def __init__(self, app):

http://git-wip-us.apache.org/repos/asf/allura/blob/39703d67/ForgeLink/forgelink/templates/app_admin_options.html
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/templates/app_admin_options.html b/ForgeLink/forgelink/templates/app_admin_options.html
deleted file mode 100644
index a62dfa7..0000000
--- a/ForgeLink/forgelink/templates/app_admin_options.html
+++ /dev/null
@@ -1,77 +0,0 @@
-{#-
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
--#}
-<!DOCTYPE html>
-{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
-<form id="set-url-form" method="post" action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_url">
-  <label for="url" class="grid-4">url</label>
-  <div class="grid-9">
-    {% if not allow_config %}
-      {{app.config.options.get('url', '')}}
-    {% else %}
-      <input id="url" name="url" value="{{app.config.options.get('url', '')}}">
-    {% endif %}
-  </div>
-  <div class="grid-4">&nbsp;</div><div id='url-error' class='grid-9'></div>
-  {% if allow_config %}
-    <div class="grid-13">&nbsp;</div>
-    <hr>
-    <div class="grid-13">&nbsp;</div>
-    <div class="grid-13">
-      <input type="submit" value="Save" id="save" />
-      <a href="#" class="close">Cancel</a>
-    </div>
-  {% endif %}
-  {{lib.csrf_token()}}
-</form>
-
-<script type="text/javascript">
-$(function() {
-  $('#save').on('click', function(e) {
-    e.preventDefault();
-    var form = $('#set-url-form');
-    var button = $(this);
-    var input = form.find('input[name="url"]')
-    var url_error = $('#url-error');
-    var url = input.val();
-    var csrf = $.cookie('_session_id');
-    button.prop('disabled', true);
-    input.prop('disabled', true);
-    url_error.text('');
-    $.post(
-      form.attr('action'),
-      {'_session_id': csrf, 'url': url},
-      function(data) {
-        if (data['status'] == 'ok') {
-          location.reload();
-        } else {
-          url_error.text(data['errors']['url']);
-        }
-        button.prop('disabled', false);
-        input.prop('disabled', false);
-      });
-  });
-});
-</script>
-
-<style type="text/css">
-#url-error {
-  margin-left: 15px;
-  color: #f33;
-}
-</style>

http://git-wip-us.apache.org/repos/asf/allura/blob/39703d67/ForgeLink/forgelink/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/functional/test_root.py b/ForgeLink/forgelink/tests/functional/test_root.py
index e4fc656..021b91f 100644
--- a/ForgeLink/forgelink/tests/functional/test_root.py
+++ b/ForgeLink/forgelink/tests/functional/test_root.py
@@ -61,47 +61,3 @@ class TestRootController(TestController):
         response = self.app.get('/link/help')
         # HACK: support for remote redirects is limited in follow()
         assert 'http://www.google.de/search?q=help' in response
-
-    @td.with_link
-    def test_set_url_validation(self):
-        r = self.app.post('/p/test/admin/link/set_url', {})
-        expected = {'status': 'error',
-                    'errors': {'url': u'Please enter a value'}}
-        assert_equal(r.json, expected)
-
-        r = self.app.post('/p/test/admin/link/set_url', {'url': ''})
-        expected = {'status': 'error',
-                    'errors': {'url': u'Please enter a value'}}
-        assert_equal(r.json, expected)
-
-        r = self.app.post('/p/test/admin/link/set_url', {'url': 'bad url'})
-        expected = {'status': 'error',
-                    'errors': {'url': u'That is not a valid URL'}}
-        assert_equal(r.json, expected)
-
-        p = M.Project.query.get(shortname='test')
-        link = p.app_instance('link')
-        assert_equal(link.config.options.get('url'), None)
-
-    @td.with_link
-    def test_set_url(self):
-        data = {'url': 'http://example.com'}  # http
-        r = self.app.post('/p/test/admin/link/set_url', data)
-        assert_equal(r.json, {'status': 'ok'})
-        p = M.Project.query.get(shortname='test')
-        link = p.app_instance('link')
-        assert_equal(link.config.options.get('url'), 'http://example.com')
-
-        data = {'url': 'https://google.com'}  # https
-        r = self.app.post('/p/test/admin/link/set_url', data)
-        assert_equal(r.json, {'status': 'ok'})
-        p = M.Project.query.get(shortname='test')
-        link = p.app_instance('link')
-        assert_equal(link.config.options.get('url'), 'https://google.com')
-
-        data = {'url': 'lmgtfy.com'}  # http is added if not provided
-        r = self.app.post('/p/test/admin/link/set_url', data)
-        assert_equal(r.json, {'status': 'ok'})
-        p = M.Project.query.get(shortname='test')
-        link = p.app_instance('link')
-        assert_equal(link.config.options.get('url'), 'http://lmgtfy.com')


Mime
View raw message