Dwarves
Memo
Type ESC to close search bar

Design file-sharing system - Part 2: Permission & Password

In this section, I will discuss how I handle the logic and design the data model for the following features: setting permissions, sharing files for public access, and setting a password for a file. Refer to the diagram below to understand how permissions work in this system.

Permissions

Functional requirements

Data model

MainPermission Table Each asset has one and only one record in this table, it contains general permission details for the asset. Public Role field: Showing the role of guest user when accessing the file

Child Role field: Show the permission workspace members and only have value

Is Inherit field: true if the permission for this asset is inherit from the parent

SubPermission An asset can have many records in this table, showing role for a specific email Role field: Show the permission for an invitee or project members in this record

Logic

Permission Hierarchy

Permissions are checked in this order:

Permission record rules:

Sharing file

Functional requirement:

Key Components

publicRole in Permission Table

Password Protection Feature

Functional requirement

The password protection feature allows users to set a password on their assets to restrict access. If an asset has a password, any user attempting to access the file must provide the correct password.

Key Components

passwordHash in Permission Table

Workflow

To make it easy to understand, I will show the workflow for getting file details. This process also applies to other features like updating and setting permissions.

The idea is that the user will get an asset-file-token by using GET /assets/:id/login. Then, add it to the header for authorization when calling GET /assets/:id to get detailed info.

Conclusion

In conclusion, this system implements a robust and flexible permissions model for file management. It covers essential features such as upload, manage, setting permissions, public file sharing, and password protection. The design allows for granular control over access levels, inheritance of permissions, and secure sharing options. This comprehensive approach ensures that users can effectively manage their files while maintaining appropriate levels of security and collaboration within the workspace.

Back to Part 1: Directory Structure