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, they have all the permissions.
Sometimes individual permissions can be modified, it is possible for example to give a guest account the permission to also write posts or revoking all permissions from an account would result in having none of the permissions.
First, define an AccountType enum to represent the three account types: Guest, User and Moderator.
Next, define a Permission enum to represent the three permission types: Read, Write, Delete, and two extra ones: All for having all permissions and None for having none of the permissions.
Then implement the (static) Permissions.Default() method to return the default permissions for a specific account type:
Permissions.Default(AccountType.Guest)
// => Permission.ReadImplement the (static) Permissions.Grant() method that grants (adds) a permission:
Permissions.Grant(current: Permission.None, grant: Permission.Read)
// => Permission.ReadImplement the (static) Permissions.Revoke() method that revokes (removes) a permission:
Permissions.Revoke(current: Permission.Read, revoke: Permission.Read)
// => Permission.NoneImplement 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