In this exercise you'll be checking permissions of user accounts on an internet forum. The forum supports three different permissions:
- Read
- Write
- Delete
There are three types of accounts, each with different default permissions:
- Guests: can read posts.
- Users: can read and write posts.
- Moderators: can read, write and delete posts.
Sometimes individual permissions are modified, for example giving a guest account the permission to also write posts.
You have four tasks.
First, define an AccountType
enum to represent the three account types. Next, define a Permission
enum to represent the three permission types and two extra ones: one for having no permissions at all, and for having all permissions.
Then implement the (static) Permissions.Default()
method to return the default permissions for a specific account type:
Permissions.Default(AccountType.Guest)
// => Permission.Read
Implement the (static) Permissions.Grant()
method that grants (adds) a permission:
Permissions.Grant(current: Permission.None, grant: Permission.Read)
// => Permission.Read
Implement the (static) Permissions.Revoke()
method that revokes (removes) a permission:
Permissions.Revoke(current: Permission.Read, grant: Permission.Read)
// => Permission.None
Implement the (static) Permissions.Check()
method that takes the current account's permissions and checks if the account is authorized for a given permission:
Permissions.Check(current: Permission.Write, check: Permission.Read)
// => false