def test_20_activity_save(self): # Add a new Activity object to the database by passing a dict to # activity_dict_save() context = {"model": model, "session": model.Session} user = model.User.by_name(u"tester") revision = model.repo.new_revision() sent = {"user_id": user.id, "object_id": user.id, "revision_id": revision.id, "activity_type": "changed user"} activity_dict_save(sent, context) model.Session.commit() # Retrieve the newest Activity object from the database, check that its # attributes match those of the dict we saved. got = ckan.logic.action.get.user_activity_list(context, {"id": user.id})[0] assert got["user_id"] == sent["user_id"] assert got["object_id"] == sent["object_id"] assert got["revision_id"] == sent["revision_id"] assert got["activity_type"] == sent["activity_type"] # The activity object should also have an ID and timestamp. assert got["id"] assert got["timestamp"] # We didn't pass in any data so this should be empty. assert not got["data"]
def test_20_activity_save(self): # Add a new Activity object to the database by passing a dict to # activity_dict_save() context = {"model": model, "session": model.Session} user = model.User.by_name(u'tester') revision = model.repo.new_revision() sent = { 'user_id': user.id, 'object_id': user.id, 'revision_id': revision.id, 'activity_type': 'changed user' } activity_dict_save(sent, context) model.Session.commit() # Retrieve the newest Activity object from the database, check that its # attributes match those of the dict we saved. got = ckan.logic.action.get.user_activity_list(context, {'id': user.id})[0] assert got['user_id'] == sent['user_id'] assert got['object_id'] == sent['object_id'] assert got['revision_id'] == sent['revision_id'] assert got['activity_type'] == sent['activity_type'] # The activity object should also have an ID and timestamp. assert got['id'] assert got['timestamp']
def test_20_activity_save(self): CreateTestData.create() # Add a new Activity object to the database by passing a dict to # activity_dict_save() context = {"model": model, "session": model.Session} user = model.User.by_name(u"tester") sent = { "user_id": user.id, "object_id": user.id, "activity_type": "changed user", } activity_dict_save(sent, context) model.Session.commit() # Retrieve the newest Activity object from the database, check that its # attributes match those of the dict we saved. got = ckan.logic.action.get.user_activity_list(context, {"id": user.id})[0] assert got["user_id"] == sent["user_id"] assert got["object_id"] == sent["object_id"] assert got["activity_type"] == sent["activity_type"] # The activity object should also have an ID and timestamp. assert got["id"] assert got["timestamp"]
def activity_create(context, activity_dict, ignore_auth=False): '''Create a new activity stream activity and return a dictionary representation of it. ''' model = context['model'] user = context['user'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None if not ignore_auth: check_access('activity_create', context, activity_dict) schema = context.get( 'schema') or ckan.logic.schema.default_create_activity_schema() data, errors = validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(activity_dict, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, ignore_auth=False): """Create a new activity stream activity and return a dictionary representation of it. """ model = context["model"] user = context["user"] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, "revision", None): activity_dict["revision_id"] = model.Session.revision.id else: activity_dict["revision_id"] = None if not ignore_auth: check_access("activity_create", context, activity_dict) schema = context.get("schema") or ckan.logic.schema.default_create_activity_schema() data, errors = validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(activity_dict, context) if not context.get("defer_commit"): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, ignore_auth=False): '''Create a new activity stream activity and return a dictionary representation of it. ''' model = context['model'] user = context['user'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None if not ignore_auth: check_access('activity_create', context, activity_dict) schema = context.get('schema') or default_create_activity_schema() data, errors = validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = activity_dict_save(activity_dict, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return activity_dictize(activity, context)
def activity_create(context, activity_dict, **kw): '''Create a new activity stream activity. You must be a sysadmin to create new activities. :param user_id: the name or id of the user who carried out the activity, e.g. ``'seanh'`` :type user_id: string :param object_id: the name or id of the object of the activity, e.g. ``'my_dataset'`` :param activity_type: the type of the activity, this must be an activity type that CKAN knows how to render, e.g. ``'new package'``, ``'changed user'``, ``'deleted group'`` etc. (for a full list see ``activity_renderers`` in ``ckan/logic/action/get.py`` :type activity_type: string :param data: any additional data about the activity :type data: dictionary :returns: the newly created activity :rtype: dictionary ''' # this action had a ignore_auth param which has been removed # removed in 2.2 if 'ignore_auth' in kw: raise Exception('Activity Stream calling parameters have changed ' 'ignore_auth must be passed in the context not as ' 'a param') if not paste.deploy.converters.asbool( config.get('ckan.activity_streams_enabled', 'true')): return model = context['model'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None _check_access('activity_create', context, activity_dict) schema = context.get( 'schema') or ckan.logic.schema.default_create_activity_schema() data, errors = _validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(data, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, **kw): '''Create a new activity stream activity. You must be a sysadmin to create new activities. :param user_id: the name or id of the user who carried out the activity, e.g. ``'seanh'`` :type user_id: string :param object_id: the name or id of the object of the activity, e.g. ``'my_dataset'`` :param activity_type: the type of the activity, this must be an activity type that CKAN knows how to render, e.g. ``'new package'``, ``'changed user'``, ``'deleted group'`` etc. :type activity_type: string :param data: any additional data about the activity :type data: dictionary :returns: the newly created activity :rtype: dictionary ''' _check_access('activity_create', context, activity_dict) # this action had a ignore_auth param which has been removed # removed in 2.2 if 'ignore_auth' in kw: raise Exception('Activity Stream calling parameters have changed ' 'ignore_auth must be passed in the context not as ' 'a param') if not paste.deploy.converters.asbool( config.get('ckan.activity_streams_enabled', 'true')): return model = context['model'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None schema = context.get('schema') or \ ckan.logic.schema.default_create_activity_schema() data, errors = _validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(data, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, **kw): """Create a new activity stream activity. You must be a sysadmin to create new activities. :param user_id: the name or id of the user who carried out the activity, e.g. ``'seanh'`` :type user_id: string :param object_id: the name or id of the object of the activity, e.g. ``'my_dataset'`` :param activity_type: the type of the activity, this must be an activity type that CKAN knows how to render, e.g. ``'new package'``, ``'changed user'``, ``'deleted group'`` etc. (for a full list see ``activity_renderers`` in ``ckan/logic/action/get.py`` :type activity_type: string :param data: any additional data about the activity :type data: dictionary :returns: the newly created activity :rtype: dictionary """ # this action had a ignore_auth param which has been removed # removed in 2.2 if "ignore_auth" in kw: raise Exception( "Activity Stream calling parameters have changed " "ignore_auth must be passed in the context not as " "a param" ) if not paste.deploy.converters.asbool(config.get("ckan.activity_streams_enabled", "true")): return model = context["model"] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, "revision", None): activity_dict["revision_id"] = model.Session.revision.id else: activity_dict["revision_id"] = None _check_access("activity_create", context, activity_dict) schema = context.get("schema") or ckan.logic.schema.default_create_activity_schema() data, errors = _validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(data, context) if not context.get("defer_commit"): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, ignore_auth=False): '''Create a new activity stream activity. You must be a sysadmin to create new activities. :param user_id: the name or id of the user who carried out the activity, e.g. ``'seanh'`` :type user_id: string :param object_id: the name or id of the object of the activity, e.g. ``'my_dataset'`` :param activity_type: the type of the activity, this must be an activity type that CKAN knows how to render, e.g. ``'new package'``, ``'changed user'``, ``'deleted group'`` etc. (for a full list see ``activity_renderers`` in ``ckan/logic/action/get.py`` :type activity_type: string :param data: any additional data about the activity :type data: dictionary :returns: the newly created activity :rtype: dictionary ''' if not paste.deploy.converters.asbool( config.get('ckan.activity_streams_enabled', 'true')): return model = context['model'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None if not ignore_auth: _check_access('activity_create', context, activity_dict) schema = context.get('schema') or ckan.logic.schema.default_create_activity_schema() data, errors = _validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(data, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)
def activity_create(context, activity_dict, ignore_auth=False): '''Create a new activity stream activity. You must be a sysadmin to create new activities. :param user_id: the name or id of the user who carried out the activity, e.g. ``'seanh'`` :type user_id: string :param object_id: the name or id of the object of the activity, e.g. ``'my_dataset'`` :param activity_type: the type of the activity, this must be an activity type that CKAN knows how to render, e.g. ``'new package'``, ``'changed user'``, ``'deleted group'`` etc. (for a full list see ``activity_renderers`` in ``ckan/logic/action/get.py`` :type activity_type: string :param data: any additional data about the activity :type data: dictionary :returns: the newly created activity :rtype: dictionary ''' model = context['model'] # Any revision_id that the caller attempts to pass in the activity_dict is # ignored and overwritten here. if getattr(model.Session, 'revision', None): activity_dict['revision_id'] = model.Session.revision.id else: activity_dict['revision_id'] = None if not ignore_auth: _check_access('activity_create', context, activity_dict) schema = context.get( 'schema') or ckan.logic.schema.default_create_activity_schema() data, errors = _validate(activity_dict, schema, context) if errors: raise ValidationError(errors) activity = model_save.activity_dict_save(activity_dict, context) if not context.get('defer_commit'): model.repo.commit() log.debug("Created '%s' activity" % activity.activity_type) return model_dictize.activity_dictize(activity, context)