Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Feb 8, 2012
2 parents ed6ddf0 + fe6829e commit f9fc4f1
Show file tree
Hide file tree
Showing 29 changed files with 111 additions and 53 deletions.
14 changes: 13 additions & 1 deletion ckan/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def __before__(self, action, **params):
i18n.handle_request(request, c)

def _identify_user(self):
'''
Identifies the user using two methods:
a) If he has logged into the web interface then repoze.who will
set REMOTE_USER.
b) For API calls he may set a header with his API key.
If the user is identified then:
c.user = user name (unicode)
c.author = user name
otherwise:
c.user = None
c.author = user\'s IP address (unicode)
'''
# see if it was proxied first
c.remote_addr = request.environ.get('HTTP_X_FORWARDED_FOR', '')
if not c.remote_addr:
Expand All @@ -98,7 +110,7 @@ def _identify_user(self):
c.user = c.user.decode('utf8')
c.userobj = model.User.by_name(c.user)
if c.userobj is None:
# This occurs when you are logged in with openid, clean db
# This occurs when you are logged in, clean db
# and then restart i.e. only really for testers. There is no
# user object, so even though repoze thinks you are logged in
# and your cookie has ckan_display_name, we need to force user
Expand Down
12 changes: 8 additions & 4 deletions ckan/lib/dictization/model_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,14 @@ def package_dict_save(pkg_dict, context):
package_tag_list_save(pkg_dict.get("tags", []), pkg, context)
package_membership_list_save(pkg_dict.get("groups", []), pkg, context)

subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(subjects, pkg, 'relationships_as_object', context)
# relationships are not considered 'part' of the package, so only
# process this if the key is provided
if 'relationships_as_subject' in pkg_dict:
subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
if 'relationships_as_object' in pkg_dict:
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(objects, pkg, 'relationships_as_object', context)

extras = package_extras_save(pkg_dict.get("extras", []), pkg, context)

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_message_hash(value):
# avoid getting config value at module scope since config may
# not be read in yet
secret = config['beaker.session.secret']
return hmac.new(secret, value, hashlib.sha1).hexdigest()
return hmac.new(secret, value.encode('utf8'), hashlib.sha1).hexdigest()

def get_redirect():
'''Checks the return_to value against the hash, and if it
Expand Down
17 changes: 11 additions & 6 deletions ckan/logic/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import datetime
from itertools import count
import re
from pylons.i18n import _, ungettext, N_, gettext
from ckan.lib.navl.dictization_functions import Invalid, Missing, missing, unflatten
from ckan.authz import Authorizer
Expand Down Expand Up @@ -268,13 +269,17 @@ def tag_string_convert(key, data, errors, context):
'''Takes a list of tags that is a comma-separated string (in data[key])
and parses tag names. These are added to the data dict, enumerated. They
are also validated.'''
tag_string = data[key]

tags = [tag.strip() \
for tag in tag_string.split(',') \
if tag.strip()]
if isinstance(data[key], basestring):
tags = [tag.strip() \
for tag in data[key].split(',') \
if tag.strip()]
else:
tags = data[key]

current_index = max( [int(k[1]) for k in data.keys() if len(k) == 3 and k[0] == 'tags'] + [-1] )

for num, tag in enumerate(tags):
for num, tag in zip(count(current_index+1), tags):
data[('tags', num, 'name')] = tag

for tag in tags:
Expand Down
14 changes: 7 additions & 7 deletions ckan/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1527,30 +1527,30 @@ body.authz form button {
/* = Activity Streams = */
/* ==================== */

.activity-stream-activity {
.activity-stream .activity {
padding-bottom:1em;

}
.activity-stream-activity a {
.activity-stream .activity a {
font-weight:bold;

}
.activity-stream-activity .actor {
.activity-stream .activity .actor {

}
.activity-stream-activity .verb {
.activity-stream .activity .verb {
background-color:PapayaWhip;
padding:.25em;
margin:.25em;

}
.activity-stream-activity .object {
.activity-stream .activity .object {

}
.activity-stream-activity .target {
.activity-stream .activity .target {

}
.activity-stream-activity .date {
.activity-stream .activity .date {
color:#999;

}
6 changes: 3 additions & 3 deletions ckan/templates/_util.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@
</tr>
</table>

<div py:def="activity_stream_activity(actor, verb, object=None, target=None)"
class="activity-stream-activity">
<div py:def="activity_div(actor, verb, object=None, target=None)"
class="activity">
<span class="actor">
${actor}
</span>
Expand All @@ -474,7 +474,7 @@
</py:otherwise>
</py:choose>
<span class="date">
${h.render_datetime(activity.timestamp, '%B %d %Y')}
${h.render_datetime(activity.timestamp)}
</span>
</div>

Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/added_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object="the tag "+h.tag_link(detail.data.tag),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object="the group "+h.group_link(activity.data.group),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_package.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object="the dataset "+h.dataset_link(activity.data.package),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_package_extra.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='changed',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object='the resource '+h.resource_link(detail.data.resource,
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated their profile.',
activity=activity
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/activity_streams/deleted_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object="the group "+h.group_link(activity.data.group),
object="the group "+activity.data.group.name,
activity=activity
)}
</html>
4 changes: 2 additions & 2 deletions ckan/templates/activity_streams/deleted_package.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object="the dataset "+h.dataset_link(activity.data.package),
object="the dataset "+h.dataset_display_name(activity.data.package),
activity=activity)}
</html>
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/deleted_package_extra.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
5 changes: 2 additions & 3 deletions ckan/templates/activity_streams/deleted_resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object='the resource '+h.resource_link(detail.data.resource,
activity.data.package.id),
object='the resource '+h.resource_display_name(detail.data.resource),
target='from the dataset '+h.dataset_link(activity.data.package),
activity=activity
)}
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='created',
object="the group "+h.group_link(activity.data.group),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_package.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='created',
object="the dataset "+h.dataset_link(activity.data.package),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_package_extra.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object='the resource '+h.resource_link(detail.data.resource,
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='signed up.',
activity=activity
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/removed_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='removed',
object="the tag "+h.tag_link(detail.data.tag),
Expand Down
4 changes: 3 additions & 1 deletion ckan/templates/user/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ <h2>Datasets</h2>
</div>
<div class="changes span-12 last">
<h2>Public Activity</h2>
${c.user_activity_stream}
<div class="activity-stream">
${c.user_activity_stream}
</div>
</div>
</div>
</div>
Expand Down
7 changes: 0 additions & 7 deletions ckan/tests/functional/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ def _ref_group(cls, group):
assert cls.ref_group_by in ['id', 'name']
return getattr(group, cls.ref_group_by)

@classmethod
def _list_package_refs(cls, packages):
return [getattr(p, cls.ref_package_by) for p in packages]

@classmethod
def _list_group_refs(cls, groups):
return [getattr(p, cls.ref_group_by) for p in groups]

class Api1TestCase(Api1and2TestCase):

Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ def test_activity(self):
# By now we've created >15 activities, but only the latest 15 should
# appear on the page.
result = self.app.get(offset, status=200)
assert result.body.count('<div class="activity-stream-activity">') \
assert result.body.count('<div class="activity">') \
== 15
27 changes: 27 additions & 0 deletions ckan/tests/functional/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,33 @@ def test_edit_indexerror(self):
plugins.unload('synchronous_search')
SolrSettings.init(solr_url)

def test_edit_pkg_with_relationships(self):
# 1786
try:
# add a relationship to a package
pkg = model.Package.by_name(self.editpkg_name)
anna = model.Package.by_name(u'annakarenina')
model.repo.new_revision()
pkg.add_relationship(u'depends_on', anna)
model.repo.commit_and_remove()

# check relationship before the test
rels = model.Package.by_name(self.editpkg_name).get_relationships()
assert_equal(str(rels), '[<*PackageRelationship editpkgtest depends_on annakarenina>]')

# edit the package
self.offset = url_for(controller='package', action='edit', id=self.editpkg_name)
self.res = self.app.get(self.offset)
fv = self.res.forms['dataset-edit']
fv['title'] = u'New Title'
res = fv.submit('save')

# check relationship still exists
rels = model.Package.by_name(self.editpkg_name).get_relationships()
assert_equal(str(rels), '[<*PackageRelationship editpkgtest depends_on annakarenina>]')

finally:
self._reset_data()

class TestNew(TestPackageForm):
pkg_names = []
Expand Down
16 changes: 16 additions & 0 deletions ckan/tests/lib/test_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from nose.tools import assert_equals

from ckan.lib.hash import get_message_hash, get_redirect

class TestHash:
@classmethod
def setup_class(cls):
global secret
secret = '42' # so that these tests are repeatable

def test_get_message_hash(self):
assert_equals(len(get_message_hash(u'/tag/country-uk')), len('6f58ff51b42e6b2d2e700abd1a14c9699e115c61'))

def test_get_message_hash_unicode(self):
assert_equals(len(get_message_hash(u'/tag/biocombust\xedveis')), len('d748fa890eb6a964cd317e6ff62905fad645b43d'))

2 changes: 1 addition & 1 deletion doc/apiv3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ license_id "cc-by" ID of the licens
extras []
tags ["government-spending"] List of tags associated with this dataset.
groups ["spending", "country-uk"] List of groups this dataset is a member of.
relationships_as_subject [] List of relationships (edit this only using relationship specific command). The 'type' of the relationship is described in terms of this package being the subject and the related package being the object.
relationships_as_subject [] List of relationships. The 'type' of the relationship is described in terms of this package being the subject and the related package being the object.
state active May be ``deleted`` or other custom states like ``pending``.
revision_id "f645243a-7334-44e2-b87c-64231700a9a6" (Read-only) ID of the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships).
revision_timestamp "2010-12-21T15:26:17.345502" (Read-only) Time and date when the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships). ISO format. UTC timezone assumed.
Expand Down

0 comments on commit f9fc4f1

Please sign in to comment.