Skip to content

Commit

Permalink
[1673] Added approval_status field to the Group model
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Jan 30, 2012
1 parent c88c900 commit 3119937
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 0 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -69,7 +69,6 @@ def register_pluggable_behaviour(map):

# Create the mappings and register the fallback behaviour if one is found.
for plugin in PluginImplementations(IDatasetForm):
print 'Processing %r' % plugin
if plugin.is_fallback():
if _default_controller_behaviour is not None:
raise ValueError, "More than one fallback "\
Expand Down
18 changes: 18 additions & 0 deletions ckan/migration/versions/0048_add_group_approval_status.py
@@ -0,0 +1,18 @@
from migrate import *

def upgrade(migrate_engine):
migrate_engine.execute('''
BEGIN;
ALTER TABLE "group"
ADD COLUMN approval_status text;
ALTER TABLE group_revision
ADD COLUMN approval_status text;
update "group" set approval_status = 'approved';
update group_revision set approval_status = 'approved';
COMMIT;
'''
)
7 changes: 7 additions & 0 deletions ckan/model/group.py
Expand Up @@ -32,6 +32,7 @@
Column('type', UnicodeText, nullable=False),
Column('description', UnicodeText),
Column('created', DateTime, default=datetime.datetime.now),
Column('approval_status', UnicodeText, default=u"approved"),
)

vdm.sqlalchemy.make_table_stateful(group_table)
Expand Down Expand Up @@ -89,6 +90,12 @@ def get(cls, reference):
return group
# Todo: Make sure group names can't be changed to look like group IDs?

def set_approval_status(self, status):
assert status in ["approved", "pending", "denied"]
self.approval_status = status
if status == "denied":
pass

def members_of_type(self, object_type):
object_type_string = object_type.__name__.lower()
query = Session.query(object_type).\
Expand Down
13 changes: 8 additions & 5 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -39,12 +39,14 @@ def setup_class(cls):
'name': u'david',
'type': u'group',
'state': u'active',
'title': u"Dave's books"},
'title': u"Dave's books",
"approval_status": u"approved"},
{'description': u'Roger likes these books.',
'name': u'roger',
'type': u'group',
'state': u'active',
'title': u"Roger's books"}],
'title': u"Roger's books",
"approval_status": u"approved"}],
'isopen': True,
'license_id': u'other-open',
'maintainer': None,
Expand Down Expand Up @@ -831,6 +833,7 @@ def test_16_group_dictized(self):

group_dict = {'name': 'help',
'title': 'help',
'approval_status': 'approved',
'extras': [{'key': 'genre', 'value': u'"horror"'},
{'key': 'media', 'value': u'"dvd"'}],
'packages':[{'name': 'annakarenina2'}, {'id': pkg.id, 'capacity': 'in'}],
Expand Down Expand Up @@ -862,7 +865,8 @@ def test_16_group_dictized(self):
'packages': 0,
'state': u'active',
'title': u'simple',
'type': u'publisher'}],
'type': u'publisher',
'approval_status': u'approved'}],
'users': [{'about': u'I love reading Annakarenina. My site: <a href="http://anna.com">anna.com</a>',
'display_name': u'annafan',
'capacity' : 'member',
Expand Down Expand Up @@ -903,13 +907,12 @@ def test_16_group_dictized(self):
'url': u'http://www.annakarenina.com',
'version': u'0.7a'}],
'state': u'active',
'approval_status': u'approved',
'title': u'help',
'type': u'group'}

expected['packages'] = sorted(expected['packages'], key=lambda x: x['name'])

result = self.remove_changable_columns(group_dictized)

result['packages'] = sorted(result['packages'], key=lambda x: x['name'])

assert result == expected, pformat(result)
Expand Down

0 comments on commit 3119937

Please sign in to comment.