[ckan-changes] [okfn/ckan] 69f278: [bug] Fix to extraneous fields in context for memb...
GitHub
noreply at github.com
Thu May 3 16:33:10 UTC 2012
Branch: refs/heads/feature-2345-action-api-autodocs
Home: https://github.com/okfn/ckan
Commit: 69f2783c55914669e3cfc2456cf37410204bc3bd
https://github.com/okfn/ckan/commit/69f2783c55914669e3cfc2456cf37410204bc3bd
Author: Ross Jones <rossdjones at gmail.com>
Date: 2012-05-03 (Thu, 03 May 2012)
Changed paths:
M ckan/logic/action/create.py
M ckan/logic/action/delete.py
M ckan/logic/action/get.py
M ckan/tests/logic/test_member.py
Log Message:
-----------
[bug] Fix to extraneous fields in context for member api
diff --git a/ckan/logic/action/create.py b/ckan/logic/action/create.py
index 355e690..9ba6a94 100644
--- a/ckan/logic/action/create.py
+++ b/ckan/logic/action/create.py
@@ -11,6 +11,7 @@
import ckan.lib.dictization.model_dictize as model_dictize
import ckan.lib.dictization.model_save as model_save
import ckan.lib.navl.dictization_functions
+import ckan.logic.auth as auth
# FIXME this looks nasty and should be shared better
from ckan.logic.action.update import _update_package_relationship
@@ -196,7 +197,7 @@ def member_create(context, data_dict=None):
user - The name of the current user
data_dict:
- group - The ID of the group to which we want to add a new object
+ id - The ID of the group to which we want to add a new object
object - The ID of the object being added as a member
object_type - The name of the type being added, all lowercase,
e.g. package, or user
@@ -204,7 +205,6 @@ def member_create(context, data_dict=None):
"""
model = context['model']
user = context['user']
- group = context['group']
rev = model.repo.new_revision()
rev.author = user
@@ -213,6 +213,7 @@ def member_create(context, data_dict=None):
else:
rev.message = _(u'REST API: Create member object %s') % data_dict.get("name", "")
+ group = model.Group.get(data_dict.get('id', ''))
obj_id = data_dict['object']
obj_type = data_dict['object_type']
capacity = data_dict['capacity']
diff --git a/ckan/logic/action/delete.py b/ckan/logic/action/delete.py
index c806a51..4dd5c70 100644
--- a/ckan/logic/action/delete.py
+++ b/ckan/logic/action/delete.py
@@ -90,16 +90,15 @@ def member_delete(context, data_dict=None):
user - The name of the current user
data_dict:
- group - The ID of the group to which we want to remove object
+ id - The ID of the group from which we want to remove object
object - The ID of the object being removed as a member
object_type - The name of the type being removed, all lowercase,
e.g. package, or user
"""
model = context['model']
user = context['user']
- group = context['group']
- group_id = data_dict['group']
+ group = model.Group.get(data_dict.get('id'))
obj_id = data_dict['object']
obj_type = data_dict['object_type']
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
index 4b6051b..e16f8c7 100644
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -187,16 +187,15 @@ def member_list(context, data_dict=None):
user - The name of the current user
data_dict:
- group - The ID of the group to which we want to list members
+ id - The ID of the group to which we want to list members
object_type - The optional name of the type being added, all lowercase,
e.g. package, or user
capacity - The optional capacity of objects that we want to retrieve
"""
model = context['model']
user = context['user']
- group = context['group']
- group_id = data_dict['group']
+ group = model.Group.get(data_dict.get('id',''))
obj_type = data_dict.get('object_type', None)
capacity = data_dict.get('capacity', None)
diff --git a/ckan/tests/logic/test_member.py b/ckan/tests/logic/test_member.py
index 04af59d..3d6294e 100644
--- a/ckan/tests/logic/test_member.py
+++ b/ckan/tests/logic/test_member.py
@@ -21,14 +21,12 @@ def teardown_class(cls):
model.repo.rebuild_db()
def _build_context( self, obj, obj_type, capacity='public'):
- grp = model.Group.by_name(self.groupname)
ctx = { 'model': model,
'session': model.Session,
- 'user':self.username,
- 'group': grp,
+ 'user':self.username
}
dd = {
- 'group': grp,
+ 'id': self.groupname,
'object': obj,
'object_type': obj_type,
'capacity': capacity }
================================================================
Commit: 09e5889f705645ada04a7f5c87ceee48b93e1d70
https://github.com/okfn/ckan/commit/09e5889f705645ada04a7f5c87ceee48b93e1d70
Author: Sean Hammond <seanhammond at lavabit.com>
Date: 2012-05-03 (Thu, 03 May 2012)
Changed paths:
M ckan/logic/action/get.py
Log Message:
-----------
[#2345] More work on action/get.py docstrings
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
index e16f8c7..a9e9817 100644
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -42,12 +42,22 @@ def _package_list_with_resources(context, package_revision_list):
return package_list
def site_read(context,data_dict=None):
+ '''Return True.
+
+ :returns: True
+ :rtype: boolean
+
+ '''
check_access('site_read',context,data_dict)
return True
def package_list(context, data_dict):
- '''Lists packages by name or id'''
+ '''Return a list of the names of the site's packages (datasets).
+ :returns: the names of the site's packages (datasets)
+ :rtype: list of strings
+
+ '''
model = context["model"]
user = context["user"]
api = context.get("api_version", 1)
@@ -63,6 +73,16 @@ def package_list(context, data_dict):
return [getattr(p, ref_package_by) for p in packages]
def current_package_list_with_resources(context, data_dict):
+ '''Return a list of the site's datasets (packages) and their resources.
+
+ The returned list of datasets is sorted most-recently-modified first.
+
+ :param limit: limit the number of datasets returned (optional)
+ :type limit: int
+ :returns: the site's datasets
+ :rtype: list of dictionaries
+
+ '''
model = context["model"]
user = context["user"]
if data_dict.has_key('limit'):
@@ -90,7 +110,12 @@ def current_package_list_with_resources(context, data_dict):
return _package_list_with_resources(context, pack_rev)
def revision_list(context, data_dict):
+ '''Return a list of the IDs of the site's revisions.
+ :returns: the IDs of the site's revisions
+ :rtype: list of revision ID strings
+
+ '''
model = context['model']
check_access('revision_list', context, data_dict)
@@ -99,6 +124,14 @@ def revision_list(context, data_dict):
return [rev.id for rev in revs]
def package_revision_list(context, data_dict):
+ '''Return a list of a dataset (package)'s revisions.
+
+ :param id: the id or name of the dataset
+ :type id: string
+ :returns: the dataset's revisions
+ :rtype: list of dictionaries
+
+ '''
model = context["model"]
id = data_dict["id"]
pkg = model.Package.get(id)
@@ -116,16 +149,14 @@ def package_revision_list(context, data_dict):
def related_show(context, data_dict=None):
- """
- Shows a single related item
+ '''Return a single related item.
- context:
- model - The CKAN model module
- user - The name of the current user
+ :param id: the id of the related item to show
+ :type id: string
+ :returns: the related item
+ :rtype: dictionary
- data_dict:
- id - The ID of the related item we want to show
- """
+ '''
model = context['model']
id = data_dict['id']
@@ -145,20 +176,16 @@ def related_show(context, data_dict=None):
def related_list(context, data_dict=None):
- """
- List the related items for a specific package which should be
- mentioned in the data_dict
+ '''Return the related items for a dataset.
- context:
- model - The CKAN model module
- user - The name of the current user
- session - The current DB session
+ Either the id or the dataset parameter must be given.
- data_dict:
- id - The ID of the dataset to which we want to list related items
- or
- dataset - The dataset (package) model
- """
+ :param id: id or name of the dataset (optional)
+ :param dataset: dataset dictionary of the dataset (optional)
+ :returns: the dataset's related items
+ :rtype: list of related item dictionaries
+
+ '''
model = context['model']
session = context['session']
dataset = data_dict.get('dataset', None)
@@ -224,8 +251,16 @@ def type_lookup(name):
for m in q.all() ]
def group_list(context, data_dict):
- '''Returns a list of groups'''
+ '''Return a list of the names of the site's groups.
+
+ :param order_by: what field to sort the list by, must be 'name' or
+ 'packages' (optional, default: 'name')
+ :type order_by: string
+
+ :returns: the names of the site's groups
+ :rtype: list of strings
+ '''
model = context['model']
user = context['user']
api = context.get('api_version')
@@ -258,11 +293,14 @@ def group_list(context, data_dict):
return group_list
def group_list_authz(context, data_dict):
- '''
- Returns a list of groups which the user is allowed to edit
+ '''Return the list of groups that the user is authorized to edit.
+
+ :param available_only: remove the existing groups in the package
+ (optional, default: False)
+ :type available_only: boolean
+ :returns: the names of groups that the user is authorized to edit
+ :rtype: list of strings
- If 'available_only' is specified, the existing groups in the package are
- removed.
'''
model = context['model']
user = context['user']
================================================================
Compare: https://github.com/okfn/ckan/compare/898f31d...09e5889
More information about the ckan-changes
mailing list