Sharing data between users is easy once initial setup is complete (and even that's not so bad!). Sharing of data is only possible on data synchronized to the cloud, and for apps that implements the Aquro user authentication.
Read more about how to configure data synchronization here and read more about user authentication here.
The basic concept of sharing data between users is to set a group property on data items that should be shared and then add users to the group.
This is done via the following tasks:
In this example we will use the Person Data Model and the Persons collection used in the previous articles about working with data. If you haven't yet, we suggest starting here so that we're on the same page!
Adding data items may be done in a few different ways, but we suggests that you use a Visual Coding Script and uses the Data.Col.Add manager to add data to the collection. The process is described in more details in this article.
Please make sure to set a value to the _Group property, as it is this property that defines which group that is the group owner of this data.
A recommendation is to use a GUID as the value on the _Group property, as it will then be unique and would not collide with any other Group names in the Aquro platform.
When working with data in different collections that are related, it might be a good idea to set the _Group property on the different items to the same value for all items that relates to each other.
To exemplify this let's say that we have a situation where we are building an app that contains a data collection with persons and every person may have one or more e-mail addresses. We would like to be able to share a person and then automatically also share the different e-mail addresses connected to this user.
To accomplish this we need to have two different data models. One that contains the person data and one that contains the e-mail address.
They might look like:
Person
If we set the _Group property to the same value on a person item and on a email item we share both the person item and the email item when we are adding a user to the group.
Adding a user to a group is done by using a Visual Coding Script and using the Cloud.Group.Add manager. This manager takes two arguments: Group and Username where Group is the name of the group (as set above) and Username is the username of the user that should be granted access to the group.
Please note that only users who already have access to the group may add other users to the group.
When a user adds a data item with a _Group property to a group that doesn't already exists the group will automatically be created and the user will be given permission to manage the group. Therefore it is very important to keep group name as unique as possible to avoid data conflicts.
When working with shared data by using the _Group property you need to configure the permission with the right setting. For sharing of data to work at all you at least have to give the Group permissions to read objects. Otherwise sharing of data will have no impact. Please read this article for more information setting permissions.