X
X

Login

Login if you already have an account

LOGIN

Register

Create a new account. join us!

REGISTER

Support

Need some help? Check out our forum.

FORUM
April 3, 2014 kevin nickels

User Groups

Android
The NoServer framework provides an efficient way for FFUser objects to be grouped and offers powerful methods to manage those groups at runtime. Groups can be used to manage groups of users, such as subscribers, friends and administrators. To represent groups of users, FatFractal provides a special objecttype called FFUserGroup.

FFUserGroups play a fundamental role in FatFractal’s permissions model. Groups contain users: each FFUserGroup has a users member, which contains references to FFUser objects. At the same time, users own groups: each FFUser object has a member called groups, which contains references to FFUserGroup objects. The groups in the groups member are not groups to which the user belongs, but groups which the user owns. The groups owned by a user may be used in conjunction with permissions.

FFUserGroup objects are generally stored in the /FFUserGroup collection (no other type of object may be stored there.) Although you may technically store FFUserGroup objects as parts of other collections, it is the FFUserGroup objects in the /FFUserGroup collection which are used in the FatFractal permissions model.

The following shows how to create and manage groups.

Create a new Group

You can create a new FFUserGroup object to which FFUsers can be added as members of that group or which you might add to the groups member of a particular FFUser object. It is fine to create a FFUserGroup object where the users member is empty.

When you create an FFUserGroup, you give it a name. This name is used when referring to a group using permissions TODO .

Example

In the following example code, we create a new FFUserGroup called “friends”.

FatFractal ff = FatFractal.getMain();
try {
FFUserGroup friends = new FFUserGroup(ff);
friends.setGroupName("friends");
ff.createObjAtUri(friends, "/FFUserGroup");
} catch (FFException e) {
e.printStackTrace();
}

Add Ownership of a Group to a User

Adding an FFUserGroup to the groups member of an FFUser is the way for users to own groups. The Platform lets you set up object access policies (OAPs) for each of that FFUser’s groups. For example, a user’s friends group might have different permissions for some objects than a user’s family group. OAPs and their associated permissions are enforced by the backend automatically and can radically simplify managing access to data, simply by adding FFUsers to an FFUserGroup, deleting FFUsers from an FFUserGroup or changing that group’s OAP, either as a default or at runtime. See Permissions.

Example

In the following code examples, an FFUserGroup named “friends” is added to the user currently logged in.

FatFractal ff = FatFractal.getMain();
FFUser loggedInUser = ff.getLoggedInUser();
FFUserGroup friends = ...;
try {
loggedInUser.addGroup(friends);
} catch (FFException e) {
// handle the error
}

Remove Ownership of a Group from a User

Naturally, you may also want to remove a group from a user. In the following example code, an FFUserGroup named “friends” is removed from an FFUser called loggedInUser:

[tab title="Java (Android)"]
FatFractal ff = FatFractal.getMain();
FFUser loggedInUser = ff.getLoggedInUser();
try {
FFUserGroup friends = loggedInUser.groupWithName("friends");
loggedInUser.removeGroup(friends);
} catch (FFException e) {
// handle the error
}

Add a User to a Group

FFUserGroup objects are automatically created with a member called users of backend datatype GRABBAG. To add FFUser objects to an FFUserGroup’s users grab bag, use the following methods. In the following example code, we will first retrieve an FFUserGroup named “friends” from an FFUser called loggedInUser. Then, we’ll add another FFUser called userToBeAdded to the FFUserGroup.

FatFractal ff = FatFractal.getMain();
FFUser loggedInUser = ff.getLoggedInUser();
FFUser userToBeAdded = ...;
try {
FFUserGroup friends = loggedInUser.groupWithName("friends");
friends.addUser(userToBeAdded);
} catch (FFException e) {
// handle the error
}

Remove a User from a Group

Removing a user from a group is very similar to adding a user to a group. In the following example code, an FFUser called userToBeRemoved is removed from an FFUserGroup named “friends”.

FatFractal ff = FatFractal.getMain();
FFUser loggedInUser = ff.getLoggedInUser();
FFUser userToBeRemoved = ...;
try {
FFUserGroup friends = loggedInUser.groupWithName("friends");
friends.removeUser(userToBeRemoved);
} catch (FFException e) {
// handle error
}

There is a great deal of additional functionality which can be applied to users and groups. In particular, the use of back references allows you to very easily find the groups to which a user belongs. Grab bags and back references are covered in detail in Data Modeling.

Contact