Relationship between a User and a Group
A user can be associated with a group by two types of relationships: user relationship and owner relationship. A user and a group are related to each other with two-way links.
When a group member is added or removed or a user or a group is deleted, Kii Cloud automatically updates those two-way links.
Member
A member is a user who joins a group. A group member can access the group data (i.e., KiiObjects in the group-scope bucket) by default.
Owner
An owner is a user who owns a group. The user who creates a group will become the initial owner. The owner can add and remove group members (For more information, see Group Access Control).
A group owner is also a member of the group.
You can change the group owner through the REST API. When the new owner is specified, they automatically become a group member.
Relationship between a User and a Group
An owner and a member are expressed as two-way relationships between a user and a group.
The KiiUser
and KiiGroup
classes of the Kii Cloud SDK have methods that return a relationship between a user and a group. The methods of the KiiUser
class point to KiiGroup
objects and vice versa as shown in the figure below.
The figure also shows the multiplicity of instances in each method in the UML notation. That is, "0..*" means 0 or more and "0..1" means 0 or 1. Each instance can be related to 0 or more instances except that a group can be related only to 0 or 1 owner.
Getting a Group List for a Member
The
memberOfGroups(_:)
method of theKiiUser
class gets a list ofKiiGroups
that aKiiUser
object is a member of. If theKiiUser
object does not belong to any group, an empty list is returned.Getting a Group List for an Owner
The
ownerOfGroups(_:)
method of theKiiUser
class gets a list ofKiiGroups
that aKiiUser
object is the owner of. The returnedKiiGroups
are always included in the result of thememberOfGroups(_:)
method because the owner is also a member of their group. If theKiiUser
object does not own any group, an empty list is returned.Getting a Member List of a Group
The
getMemberList(_:)
method of theKiiGroup
class gets a list ofKiiUsers
that are members of theKiiGroup
object. This method works in the opposite way of thememberOfGroups(_:)
method of theKiiUser
class.-
The
getOwnerWith(_:)
method of theKiiGroup
class gets aKiiUser
that is the owner of theKiiGroup
object. OneKiiUser
is returned because a group cannot have multiple owners. This method works in the opposite way of theownerOfGroups(_:)
method of theKiiUser
class.
When a group owner who is the sole member of their group is deleted, the group has no member. In this case, the getMemberList(_:)
method returns an empty list and the getOwnerWith(_:)
method returns a nil value. For more information, see Considerations in deleting users.
Example of manipulating user-group relationships
See the figure below for the results of the following three actions.
Alice creates the Sales Div. group. Relationships created from this action are indicated by the red arrows.
Alice adds Bob to the Sales Div. group. Relationships created from this action are indicated by the blue arrows.
Bob creates the Tennis Club group. Relationships created from this action are indicated by the green arrows.
The figure indicates that all the relationships between the users and the groups are symmetrical.
However, the methods for listing users and groups return a different number of objects. For example, the memberOfGroups(_:)
method of Bob returns Sales Div. and Tennis Club while the getMemberList(_:)
method of Tennis Club returns only Bob. Also, the getMemberList(_:)
method of Sales Div. returns Bob and Alice.
When you implement your mobile app, be careful about the type of objects, KiiUsers
or KiiGroups
, in your listing operation.
Retrieving a group for its member or owner
You can retrieve group data by using the group listing feature of the KiiUser
class in addition to the methods of using the group URI or ID.
You can get groups that are related to the logged-in user or a specific user by getting a list of KiiGroups
with the memberOfGroups(_:)
method of the target user. Then, you can perform desired actions through accessing KiiObjects in the group scope and getting a list of group members.
You need to implement logic to distinguish retrieved groups in your mobile app. The group listing feature just gets KiiGroups
that are related to the target KiiUser
and it is not possible to know the role of each KiiGroup
in the list. Suppose your mobile app has a bulletin board feature and a group chat feature. You could not distinguish KiiGroups
in the group list for the bulletin board and the group chat. In order to use those groups separately by purpose, you would need to develop your mobile app accordingly.