Skip to content

Commit

Permalink
[#2304] follower_create: Don't let a user follow herself
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Apr 28, 2012
1 parent faef628 commit 5bc48f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ckan/logic/schema.py
Expand Up @@ -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

Expand Down Expand Up @@ -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]
}
Expand Down
4 changes: 4 additions & 0 deletions ckan/logic/validators.py
Expand Up @@ -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'))

0 comments on commit 5bc48f0

Please sign in to comment.