Skip to main content

Introduction

A collection in R2R is a logical grouping of users and documents that allows for efficient access control and organization. Collections enable you to manage permissions and access to documents at a group level, rather than individually. R2R provides robust document collection management, allowing developers to implement efficient access control and organization of users and documents. This cookbook will guide you through the collection capabilities in R2R. For user authentication, please refer to the User Auth Cookbook.
Collection permissioning in R2R is still under development and as a result the is likely to API continue evolving in future releases.
A diagram showing user and collection management across r2r

Basic Usage

Collections currently follow a flat hierarchy wherein superusers are responsible for management operations. This functionality will expand as development on R2R continues.

Creating a Collection

Let’s start by creating a new collection:

Getting Collection details

To retrieve details about a specific collection:

Updating a Collection

You can update a collection’s name or description:

Listing Collections

To get a list of all collections:

User Management in Collections

Adding a User to a Collection

To add a user to a collection, you need both the user’s ID and the collections’s ID:

Removing a User from a Collections

Similarly, to remove a user from a collection:

Listing Users in a Collection

To get a list of all users in a specific collection:

Getting Collections for a User

To get all collections that a user is a member of:

Document Management in Collections

Assigning a Document to a Collection

To assign a document to a collection:

Removing a Document from a Collection

To remove a document from a collection:

Listing Documents in a Collection

To get a list of all documents in a specific collection:

Getting Collections for a Document

To get all collections that a document is assigned to:

Advanced Collection Management

Collection Overview

To get an overview of collection, including user and document counts:

Deleting a Collection

To delete a collection:

Pagination and Filtering

Many of the collection-related methods support pagination and filtering. Here are some examples:

Security Considerations

When implementing collection permissions, consider the following security best practices:
  1. Least Privilege Principle: Assign the minimum necessary permissions to users and collections.
  2. Regular Audits: Periodically review collection memberships and document assignments.
  3. Access Control: Ensure that only authorized users (e.g., admins) can perform collection management operations.
  4. Logging and Monitoring: Implement comprehensive logging for all collection-related actions.

Customizing Collection Permissions

While R2R’s current collection system follows a flat hierarchy, you can build more complex permission structures on top of it:
  1. Custom Roles: Implement application-level roles within collections (e.g., collection admin, editor, viewer).
  2. Hierarchical Collections: Create a hierarchy by establishing parent-child relationships between collections in your application logic.
  3. Permission Inheritance: Implement rules for permission inheritance based on collection memberships.

Troubleshooting

Here are some common issues and their solutions:
  1. Unable to Create/Modify Collections: Ensure the user has superuser privileges.
  2. User Not Seeing Collection Content: Verify that the user is correctly added to the collection and that documents are properly assigned.
  3. Performance Issues with Large Collections: Use pagination when retrieving users or documents in large collections.

Conclusion

R2R’s collection permissioning system provides a foundation for implementing sophisticated access control in your applications. As the feature set evolves, more advanced capabilities will become available. Stay tuned to the R2R documentation for updates and new features related to collection permissions. For user authentication and individual user management, refer to the User Auth Cookbook. For more advanced use cases or custom implementations, consult the R2R documentation or reach out to the community for support.