From 5bc48f0e449b59230d6a781d6fa4fcf17d502c09 Mon Sep 17 00:00:00 2001 From: Sean Hammond Date: Sat, 28 Apr 2012 19:57:03 +0200 Subject: [PATCH] [#2304] follower_create: Don't let a user follow herself --- ckan/logic/schema.py | 6 ++++-- ckan/logic/validators.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py index fb91cf5df0f..ac577ea7d82 100644 --- a/ckan/logic/schema.py +++ b/ckan/logic/schema.py @@ -39,7 +39,8 @@ activity_type_exists, tag_not_in_vocabulary, follower_id_exists, - follower_object_id_exists) + follower_object_id_exists, + follower_subject_not_same_as_object) from formencode.validators import OneOf import ckan.model @@ -395,7 +396,8 @@ def default_create_follower_schema(): follower_id_exists], 'follower_type': [not_missing, not_empty, unicode], 'object_id': [not_missing, not_empty, unicode, - follower_object_id_exists], + follower_object_id_exists, + follower_subject_not_same_as_object], 'object_type': [not_missing, not_empty, unicode], 'datetime': [ignore] } diff --git a/ckan/logic/validators.py b/ckan/logic/validators.py index 5039512e173..36449029a09 100644 --- a/ckan/logic/validators.py +++ b/ckan/logic/validators.py @@ -516,3 +516,7 @@ def follower_object_id_exists(key, object_dict, errors, context): raise Invalid(_('object_type {type} not recognised').format( type=object_type)) object_dict[(u'object_id',)] = validator(object_id, context) + +def follower_subject_not_same_as_object(key, follower_dict, errors, context): + if follower_dict[('follower_id',)] == follower_dict[('object_id',)]: + raise Invalid(_('An object cannot follow itself'))