This article outlines how to restrict access to Items and Activities based on a combination of users, Tags, and status values.
The filter.restricted
object of item_list
and activity_list
allows you to filter out the list of Items and Activities you would want your users to access in your application. You can filter Items and Activities based on the users who have created the Items and Activities, Tags attached to them or the status of the Item.
Filtering based on users
You can restrict the list of Items in the item_list
and Activities in the activity_list
to only those Items and Activities created by users specified in the array of user.ids
. To do this, you will use the filter.restricted.created_by
initialization options. A maximum of 50 user.id
values can be specified in the string array. The user.id
identifies the user used to create the signed request to initialize Author API and create the Item or Activity.
{ "config": { "item_list": { "filter": { "restricted": { "created_by": [ "ABC123456789", "DEF987654321" ] } } } } }
Using the filter.restricted.current_user
initialization flag, you can restrict the list of Items in the item_list
and Activities in the activity_list
for the authors to only the Items and Activities created by them. This flag overrides the created_by
option and will not display any Items or Activities created by any other author.
{ "config": { "item_list": { "filter": { "restricted": { "current_user": true } } } } }
Filtering Items based on status
Using the filter.restricted.status
initialization option, you can restrict the list of Items in the item_list
to only those Items whose status is set to the any of the value specified in the string array. Valid status for Items are published
, unpublished
, and archived
.
{ "config": { "item_list": { "filter": { "restricted": { "status": [ "unpublished" ] } } } } }
Filtering based on Tags
If a Tag filter is specified and a user should be allowed to create Items or Activities, Tags matching that filter will need to be set on Item creation (using the setItemTags
public method) for the Item to be visible in the item_list
and on Activity creation (using the setActivityTags
public method) for the Activity to be visible in the activity_list
.
See the article on advanced tag search for examples of Tag formats.
filter.restricted.tags.all
Using the filter.restricted.tags.all
initialization option, you can restrict the list of Items in the item_list
and Activities in the activity_list
for the authors to only those Items and Activities which have all the Tags specified in the object array. The object array is an array of Tag objects in the TagsV2
object format. You can specify the type
and name
properties for each Tag object, or just the type
property in which case the name
value would be ignored. You can also specify an array of name
properties for the specified type
in the TagsV1
format which makes it more convenient to specify multiple Tags of the same type.
filter.restricted.tags.either
Using the filter.restricted.tags.either
initialization option, you can restrict the list of Items in the item_list
and Activities in the activity_list
for the authors to only those Items and Activities which have at least one Tag matching the Tags specified in the object array. The object array is an array of Tag objects in the TagsV2
object format. You can also specify an array of name
properties for the specified type
in the TagsV1
format for the item_list
which makes it more convenient to specify multiple Tags of the same type.
filter.restricted.tags.none
Using the filter.restricted.tags.none
initialization option, you can restrict the list of Items in the item_list
and Activities in the activity_list
for the authors to only those Items and Activities which do not have any Tags matching the Tags specified in the object array. The object array is an array of Tag objects in the TagsV2
object format.
Note: For performance reasons, none
Tags are only allowed if the all
or either
Tags filters are specified as well. If those are not specified, the none
Tags filter will be ignored.
{ "config": { "item_list": { "filter": { "restricted": { "tags": { "all": [ { "type": "subject", "name": [ "english" ] } ], "either": [ { "type": "course", "name": [ "Common Core", "Texas" ] } ] } } } } } }