You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/02/24 16:16:56 UTC
[1/5] git commit: [#7014] Added trove category controller to site
admin via new extension point
Repository: incubator-allura
Updated Branches:
refs/heads/master fc1c466ab -> ab5f24b8d
[#7014] Added trove category controller to site admin via new extension point
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ab5f24b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ab5f24b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ab5f24b8
Branch: refs/heads/master
Commit: ab5f24b8dc85855fd5565d524338eecf693c47e6
Parents: 2fdefbf
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Feb 20 23:12:22 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000
----------------------------------------------------------------------
Allura/allura/controllers/trovecategories.py | 18 ++++++++++++++----
Allura/allura/templates/user_skills.html | 2 +-
.../allura/tests/functional/test_trovecategory.py | 2 +-
Allura/setup.py | 1 +
4 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab5f24b8/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index ceba651..959713d 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -19,6 +19,7 @@ from tg import expose, flash, redirect, validate, config
from pylons import tmpl_context as c
from string import digits, lowercase
from webob.exc import HTTPForbidden
+from pylons import app_globals as g
from allura import model as M
from allura.controllers import BaseController
@@ -26,6 +27,8 @@ from allura.lib import helpers as h
from allura.lib.decorators import require_post
from allura.lib.security import require_authenticated, require_access
from allura.lib.widgets import forms
+from allura.lib.plugin import SiteAdminExtension
+from allura.app import SitemapEntry
class F(object):
@@ -41,16 +44,15 @@ class TroveCategoryController(BaseController):
return TroveCategoryController(category=cat), remainder
def _check_security(self):
- enable_editing = config.get('trovecategories.enableediting', 'false')
- if enable_editing == 'false':
- raise HTTPForbidden()
-
require_authenticated()
+ enable_editing = config.get('trovecategories.enableediting', 'false')
if enable_editing == 'admin':
with h.push_context(config.get('site_admin_project', 'allura'),
neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
require_access(c.project, 'admin')
+ elif enable_editing != 'true':
+ raise HTTPForbidden()
def __init__(self, category=None):
self.category = category
@@ -212,3 +214,11 @@ class TroveCategoryController(BaseController):
flash('Category removed.')
redirect(redirecturl)
+
+
+class TroveCategorySiteAdminExtension(SiteAdminExtension):
+ def update_sidebar_menu(self, links):
+ enable_editing = config.get('trovecategories.enableediting', 'false')
+ if enable_editing in ('admin', 'true'):
+ links.append(SitemapEntry('Troves', '/categories',
+ ui_icon=g.icons['admin']))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab5f24b8/Allura/allura/templates/user_skills.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_skills.html b/Allura/allura/templates/user_skills.html
index 0838a97..cc5d02b 100644
--- a/Allura/allura/templates/user_skills.html
+++ b/Allura/allura/templates/user_skills.html
@@ -99,7 +99,7 @@
<h3>Other possible actions</h3>
<div class="grid-20" style="margin-bottom:10px;"/>
<ul>
- {%if tg.config.get('trovecategories.enableediting', 'false')!='false'%}
+ {% if tg.config.get('trovecategories.enableediting', 'false') == 'true' %}
{% if selected_skill %}
<li>
<a href="/categories/{{selected_skill.shortname}}">
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab5f24b8/Allura/allura/tests/functional/test_trovecategory.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_trovecategory.py b/Allura/allura/tests/functional/test_trovecategory.py
index 2f0bd54..c9a8cc3 100644
--- a/Allura/allura/tests/functional/test_trovecategory.py
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -38,7 +38,7 @@ class TestTroveCategory(TestController):
deleted_category_id = post_event.call_args[0][1]
assert_true(isinstance(deleted_category_id, ObjectId))
assert_equals(deleted_category_id, category_id)
- assert_equals(post_event.call_args[0][0], 'trove_category_deleted')
+ assert_equals(post_event.call_args[0][0], 'trove_category_deleted')
def test_enableediting_setting(self):
def check_access(username=None, status=None):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab5f24b8/Allura/setup.py
----------------------------------------------------------------------
diff --git a/Allura/setup.py b/Allura/setup.py
index 7d2d924..1d04828 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -125,6 +125,7 @@ setup(
[allura.site_admin]
stats = allura.controllers.site_admin:StatsSiteAdminExtension
+ troves = allura.controllers.trovecategories:TroveCategorySiteAdminExtension
[allura.user_profile.sections]
personal-data = allura.ext.user_profile.user_main:PersonalDataSection
[3/5] git commit: [#7014] ticket:524 Restored the link to edit
trovecategories
Posted by jo...@apache.org.
[#7014] ticket:524 Restored the link to edit trovecategories
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5bc9daf0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5bc9daf0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5bc9daf0
Branch: refs/heads/master
Commit: 5bc9daf03324a56ddf15c9dc66fef92e1a6d8535
Parents: fc1c466
Author: Ferens Dmitriy <fe...@gmail.com>
Authored: Mon Jan 27 18:40:47 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000
----------------------------------------------------------------------
Allura/allura/templates/user_skills.html | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5bc9daf0/Allura/allura/templates/user_skills.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_skills.html b/Allura/allura/templates/user_skills.html
index fbc1945..25b7aa5 100644
--- a/Allura/allura/templates/user_skills.html
+++ b/Allura/allura/templates/user_skills.html
@@ -95,5 +95,24 @@
{{g.theme.add_user_skill.display(selected_skill=selected_skill.trove_cat_id,
action=selected_skill.shortname + "/save_skill")}}
{% endif %}
+
+ <h3>Other possible actions</h3>
+ <div class="grid-20" style="margin-bottom:10px;"/>
+ <ul>
+ {%if tg.config.get('trovecategories.enableediting', 'false')=='true'%}
+ {% if selected_skill %}
+ <li>
+ <a href="/categories/{{selected_skill.shortname}}">
+ Create a new category in this list
+ </a>
+ if you want to add a more specific kind of skill which is not included here.
+ </li>
+ {% endif %}
+ {%endif%}
+ <li>
+ <a href="/auth/prefs">Go to you profile</a> to set the remaining personal preferences.
+ </li>
+ </ul>
+ </div>
</div>
{% endblock %}
[2/5] git commit: [#7014] ticket:524 Added 'admin' value to
trovecategories.enableediting setting.
Posted by jo...@apache.org.
[#7014] ticket:524 Added 'admin' value to trovecategories.enableediting setting.
This option allows site admins only to edit trove categories.
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/6ca710e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6ca710e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6ca710e7
Branch: refs/heads/master
Commit: 6ca710e7dd558d334c7f8aae6e6adf19274a8ddd
Parents: e0d5dd6
Author: Ferens Dmitriy <fe...@gmail.com>
Authored: Wed Jan 29 14:53:03 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000
----------------------------------------------------------------------
Allura/allura/controllers/root.py | 2 +-
Allura/allura/controllers/trovecategories.py | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ca710e7/Allura/allura/controllers/root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index d43afa4..01420e8 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -70,7 +70,7 @@ class RootController(WsgiDispatchController):
nf = NewForgeController()
search = SearchController()
rest = RestController()
- if config.get('trovecategories.enableediting', 'false') == 'true':
+ if config.get('trovecategories.enableediting', 'false') != 'false':
categories = TroveCategoryController()
def __init__(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6ca710e7/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index 6c57f33..22b161f 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -15,13 +15,15 @@
# specific language governing permissions and limitations
# under the License.
-from tg import expose, flash, redirect, validate
+from tg import expose, flash, redirect, validate, config
+from pylons import tmpl_context as c
from string import digits, lowercase
-from allura.lib.security import require_authenticated
from allura import model as M
-from allura.lib.decorators import require_post
from allura.controllers import BaseController
+from allura.lib import helpers as h
+from allura.lib.decorators import require_post
+from allura.lib.security import require_authenticated, require_access
from allura.lib.widgets import forms
@@ -37,6 +39,12 @@ class TroveCategoryController(BaseController):
cat = M.TroveCategory.query.get(shortname=catshortname)
return TroveCategoryController(category=cat), remainder
+ def _check_security(self):
+ if config.get('trovecategories.enableediting', 'false') == 'admin':
+ with h.push_context(config.get('site_admin_project', 'allura'),
+ neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
+ require_access(c.project, 'admin')
+
def __init__(self, category=None):
self.category = category
super(TroveCategoryController, self).__init__()
[5/5] git commit: [#7014] ticket:524 Added create/update/delete
events for TroveCollection model
Posted by jo...@apache.org.
[#7014] ticket:524 Added create/update/delete events for TroveCollection model
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/e0d5dd62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/e0d5dd62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/e0d5dd62
Branch: refs/heads/master
Commit: e0d5dd623b53de5fa06b01e1ead3f397357e47f1
Parents: 5bc9daf
Author: Ferens Dmitriy <fe...@gmail.com>
Authored: Tue Jan 28 16:11:10 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000
----------------------------------------------------------------------
Allura/allura/model/project.py | 13 +++++++++++++
Allura/docs/extending.rst | 3 +++
2 files changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e0d5dd62/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 452652c..e5902b8 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -89,11 +89,24 @@ class ProjectCategory(MappedClass):
return self.query.find(dict(parent_id=self._id)).all()
+class TroveCategoryMapperExtension(MapperExtension):
+
+ def after_insert(self, obj, state, sess):
+ g.post_event('trove_category_created', obj._id)
+
+ def after_update(self, obj, state, sess):
+ g.post_event('trove_category_updated', obj._id)
+
+ def after_delete(self, obj, state, sess):
+ g.post_event('trove_category_deleted', obj._id)
+
+
class TroveCategory(MappedClass):
class __mongometa__:
session = main_orm_session
name = 'trove_category'
+ extensions = [TroveCategoryMapperExtension]
indexes = ['trove_cat_id', 'trove_parent_id', 'shortname', 'fullpath']
_id = FieldProperty(S.ObjectId)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e0d5dd62/Allura/docs/extending.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/extending.rst b/Allura/docs/extending.rst
index 1e7cef7..5a0170f 100644
--- a/Allura/docs/extending.rst
+++ b/Allura/docs/extending.rst
@@ -66,6 +66,9 @@ The events that allura publishes are:
* repo_cloned
* repo_refreshed
* repo_clone_task_failed
+* trove_category_created
+* trove_category_updated
+* trove_category_deleted
Markdown Macros
[4/5] git commit: [#7014] ticket:524 Added additional tests for
TroveCategories
Posted by jo...@apache.org.
[#7014] ticket:524 Added additional tests for TroveCategories
Added functional tests for TroveCategoryController.
Added tests for created/updated/deleted events TroveCategory model.
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/2fdefbff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2fdefbff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2fdefbff
Branch: refs/heads/master
Commit: 2fdefbffa8e1e500c800d50357d57f16c277ed0f
Parents: 6ca710e
Author: Ferens Dmitriy <fe...@gmail.com>
Authored: Fri Jan 31 23:32:36 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000
----------------------------------------------------------------------
.../allura/controllers/basetest_project_root.py | 2 +-
Allura/allura/controllers/root.py | 3 +-
Allura/allura/controllers/trovecategories.py | 15 ++---
Allura/allura/templates/user_skills.html | 2 +-
.../tests/functional/test_trovecategory.py | 62 ++++++++++++++++++++
Allura/test.ini | 2 +
6 files changed, 75 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/basetest_project_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index 638d28d..d1ca3f7 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -68,7 +68,7 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
proxy_root = RootController()
self.dispatch = DispatchTest()
self.security = SecurityTests()
- for attr in ('index', 'browse', 'auth', 'nf', 'error'):
+ for attr in ('index', 'browse', 'auth', 'nf', 'error', 'categories'):
setattr(self, attr, getattr(proxy_root, attr))
self.gsearch = proxy_root.search
self.rest = RestController()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index 01420e8..f5848d8 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -70,8 +70,7 @@ class RootController(WsgiDispatchController):
nf = NewForgeController()
search = SearchController()
rest = RestController()
- if config.get('trovecategories.enableediting', 'false') != 'false':
- categories = TroveCategoryController()
+ categories = TroveCategoryController()
def __init__(self):
n_url_prefix = '/%s/' % request.path.split('/')[1]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index 22b161f..ceba651 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -18,6 +18,7 @@
from tg import expose, flash, redirect, validate, config
from pylons import tmpl_context as c
from string import digits, lowercase
+from webob.exc import HTTPForbidden
from allura import model as M
from allura.controllers import BaseController
@@ -40,7 +41,13 @@ class TroveCategoryController(BaseController):
return TroveCategoryController(category=cat), remainder
def _check_security(self):
- if config.get('trovecategories.enableediting', 'false') == 'admin':
+ enable_editing = config.get('trovecategories.enableediting', 'false')
+ if enable_editing == 'false':
+ raise HTTPForbidden()
+
+ require_authenticated()
+
+ if enable_editing == 'admin':
with h.push_context(config.get('site_admin_project', 'allura'),
neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
require_access(c.project, 'admin')
@@ -51,8 +58,6 @@ class TroveCategoryController(BaseController):
@expose('jinja:allura:templates/trovecategories.html')
def index(self, **kw):
- require_authenticated()
-
if self.category:
selected_cat = self.category
l = self.category.subcategories
@@ -74,8 +79,6 @@ class TroveCategoryController(BaseController):
@require_post()
@validate(F.add_category_form, error_handler=index)
def create(self, **kw):
- require_authenticated()
-
name = kw.get('categoryname')
upper_id = int(kw.get('uppercategory_id', 0))
@@ -121,8 +124,6 @@ class TroveCategoryController(BaseController):
@require_post()
@validate(F.remove_category_form, error_handler=index)
def remove(self, **kw):
- require_authenticated()
-
cat = M.TroveCategory.query.get(trove_cat_id=int(kw['categoryid']))
if cat.trove_parent_id:
parent = M.TroveCategory.query.get(
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/templates/user_skills.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_skills.html b/Allura/allura/templates/user_skills.html
index 25b7aa5..0838a97 100644
--- a/Allura/allura/templates/user_skills.html
+++ b/Allura/allura/templates/user_skills.html
@@ -99,7 +99,7 @@
<h3>Other possible actions</h3>
<div class="grid-20" style="margin-bottom:10px;"/>
<ul>
- {%if tg.config.get('trovecategories.enableediting', 'false')=='true'%}
+ {%if tg.config.get('trovecategories.enableediting', 'false')!='false'%}
{% if selected_skill %}
<li>
<a href="/categories/{{selected_skill.shortname}}">
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/tests/functional/test_trovecategory.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_trovecategory.py b/Allura/allura/tests/functional/test_trovecategory.py
new file mode 100644
index 0000000..2f0bd54
--- /dev/null
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -0,0 +1,62 @@
+import mock
+
+from tg import config
+from nose.tools import assert_equals, assert_true
+from ming.orm import session
+from bson.objectid import ObjectId
+
+from allura import model as M
+from allura.lib import helpers as h
+from allura.tests import TestController
+
+
+class TestTroveCategory(TestController):
+
+ @mock.patch('allura.model.project.g.post_event')
+ def test_events(self, post_event):
+ # Create event
+ cfg = {'trovecategories.enableediting': 'true'}
+ with h.push_config(config, **cfg):
+ r = self.app.post('/categories/create/', params=dict(categoryname='test'))
+
+ category_id = post_event.call_args[0][1]
+ assert_true(isinstance(category_id, ObjectId))
+ assert_equals(post_event.call_args[0][0], 'trove_category_created')
+ category = M.TroveCategory.query.get(_id=category_id)
+
+ # Update event
+ category.fullname = 'test2'
+ session(M.TroveCategory).flush()
+ edited_category_id = post_event.call_args[0][1]
+ assert_true(isinstance(edited_category_id, ObjectId))
+ assert_equals(edited_category_id, category_id)
+ assert_equals(post_event.call_args[0][0], 'trove_category_updated')
+
+ # Delete event
+ M.TroveCategory.delete(category)
+ session(M.TroveCategory).flush()
+ deleted_category_id = post_event.call_args[0][1]
+ assert_true(isinstance(deleted_category_id, ObjectId))
+ assert_equals(deleted_category_id, category_id)
+ assert_equals(post_event.call_args[0][0], 'trove_category_deleted')
+
+ def test_enableediting_setting(self):
+ def check_access(username=None, status=None):
+ self.app.get('/categories/', status=status,
+ extra_environ=dict(username=username))
+
+ cfg = {'trovecategories.enableediting': 'true'}
+
+ with h.push_config(config, **cfg):
+ check_access(username='test-user', status=200)
+ check_access(username='root', status=200)
+
+ cfg['trovecategories.enableediting'] = 'false'
+ with h.push_config(config, **cfg):
+ check_access(username='test-user', status=403)
+ check_access(username='root', status=403)
+
+ cfg['trovecategories.enableediting'] = 'admin'
+ with h.push_config(config, **cfg):
+ check_access(username='test-user', status=403)
+ check_access(username='root', status=200)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index b1880b8..a82fbf2 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -56,6 +56,8 @@ ming.main.uri = mim:///allura
ming.project.uri = mim:///project-data
ming.task.uri = mim:///task
+trovecategories.enableediting = true
+
# ActivityStream
activitystream.master = mim://
activitystream.database = activitystream