Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 1117-start-new-tes…
Browse files Browse the repository at this point in the history
…t-suite
  • Loading branch information
Sean Hammond committed Oct 1, 2013
2 parents 5ca99ee + 8ba03bb commit 708da6f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Expand Up @@ -93,7 +93,7 @@ Deprecated and removed:
one. Please update your config files if using it. (#226)

Known issues:
* Under certain authorization setups the forntend for the groups functionality
* Under certain authorization setups the frontend for the groups functionality
may not work as expected (See #1176 #1175).


Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/create.py
Expand Up @@ -1141,7 +1141,7 @@ def _group_or_org_member_create(context, data_dict, is_org=False):
role = data_dict.get('role')
group_id = data_dict.get('id')
group = model.Group.get(group_id)
result = session.query(model.User).filter_by(name=username).first()
result = model.User.get(username)
if result:
user_id = result.id
else:
Expand Down
32 changes: 17 additions & 15 deletions ckan/templates/header.html
Expand Up @@ -2,10 +2,11 @@
{% block header_account %}
<header class="account-masthead">
<div class="container">
{% if c.userobj %}
<div class="account avatar authed" data-module="me" data-me="{{ c.userobj.id }}">
<ul class="unstyled">
{% block header_account_logged %}
{% block header_account_container_content %}
{% if c.userobj %}
<div class="account avatar authed" data-module="me" data-me="{{ c.userobj.id }}">
<ul class="unstyled">
{% block header_account_logged %}
{% if c.userobj.sysadmin %}
<li>
<a href="{{ h.url_for(controller='admin', action='index') }}" title="{{ _('Sysadmin settings') }}">
Expand Down Expand Up @@ -41,19 +42,20 @@
</a>
</li>
{% endblock %}
{% endblock %}
</ul>
</div>
{% else %}
<nav class="account not-authed">
<ul class="unstyled">
{% block header_account_notlogged %}
{% endblock %}
</ul>
</div>
{% else %}
<nav class="account not-authed">
<ul class="unstyled">
{% block header_account_notlogged %}
<li>{% link_for _('Log in'), controller='user', action='login' %}</li>
<li>{% link_for _('Register'), controller='user', action='register', class_='sub' %}</li>
{% endblock %}
</ul>
</nav>
{% endif %}
{% endblock %}
</ul>
</nav>
{% endif %}
{% endblock %}
</div>
</header>
{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion ckan/templates/organization/member_new.html
Expand Up @@ -38,7 +38,6 @@ <h1 class="page-heading">
</div>
</form>
{% endblock %}
</div>
{% endblock %}

{% block secondary_content %}
Expand Down
12 changes: 7 additions & 5 deletions ckan/templates/snippets/organization.html
Expand Up @@ -20,11 +20,13 @@
<h2 class="module-heading"><i class="icon-building"></i> {{ _('Organization') }}</h2>
{% endif %}
<section class="module-content">
<div class="image">
<a href="{{ url }}">
<img src="{{ organization.image_url or h.url_for_static('/base/images/placeholder-organization.png') }}" width="200" alt="{{ organization.name }}" />
</a>
</div>
{% block image %}
<div class="image">
<a href="{{ url }}">
<img src="{{ organization.image_url or h.url_for_static('/base/images/placeholder-organization.png') }}" width="200" alt="{{ organization.name }}" />
</a>
</div>
{% endblock %}
<h1 class="heading">{{ organization.title or organization.name }}</h1>
{% if organization.description %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/user/login.html
Expand Up @@ -29,7 +29,7 @@ <h2 class="module-heading">{{ _('Need an Account?') }}</h2>
</section>

<section class="module module-narrow module-shallow">
<h2 class="module-heading">{{ _('Forgotten your details?') }}</h2>
<h2 class="module-heading">{{ _('Forgotten your password?') }}</h2>
<div class="module-content">
<p>{% trans %}No problem, use our password recovery form to reset it.{% endtrans %}</p>
<p class="action">
Expand Down
49 changes: 49 additions & 0 deletions ckan/tests/logic/test_action.py
Expand Up @@ -1672,3 +1672,52 @@ def test_01_delete_resource(self):
res_dict = json.loads(res.body)
assert res_dict['success'] is True
assert len(res_dict['result']['resources']) == resource_count - 1


class TestMember(WsgiAppCase):

sysadmin = None

group = None

def setup(self):
username = 'sysadmin'
groupname = 'test group'
organization_name = 'test organization'
CreateTestData.create_user('sysadmin', **{ 'sysadmin': True })
CreateTestData.create_groups([{ 'name': groupname },
{ 'name': organization_name,
'type': 'organization'}])
self.sysadmin = model.User.get(username)
self.group = model.Group.get(groupname)

def teardown(self):
model.repo.rebuild_db()

def test_group_member_create_works_user_id_and_group_id(self):
self._assert_we_can_add_user_to_group(self.sysadmin.id, self.group.id)

def test_group_member_create_works_with_user_id_and_group_name(self):
self._assert_we_can_add_user_to_group(self.sysadmin.id, self.group.name)

def test_group_member_create_works_with_user_name_and_group_name(self):
self._assert_we_can_add_user_to_group(self.sysadmin.name, self.group.name)

def _assert_we_can_add_user_to_group(self, user_id, group_id):
user = model.User.get(user_id)
group = model.Group.get(group_id)
url = '/api/action/group_member_create'
role = 'member'
postparams = '%s=1' % json.dumps({
'id': group_id,
'username': user_id,
'role': role})

res = self.app.post(url, params=postparams,
extra_environ={'Authorization': str(user.apikey)})

res = json.loads(res.body)
groups = user.get_groups(group.type, role)
group_ids = [g.id for g in groups]
assert res['success'] is True, res
assert group.id in group_ids, (group, user_groups)

0 comments on commit 708da6f

Please sign in to comment.