Skip to content

Commit

Permalink
Create permission_matrix.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 18, 2024
1 parent b472c6a commit 882da43
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/permission_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json

class PermissionMatrix:
def __init__(self):
self.permissions = {
'admin': ['create_user', 'delete_user', 'edit_user'],
'moderator': ['edit_user'],
'user': ['view_profile']
}

def has_permission(self, user_role, permission):
return permission in self.permissions.get(user_role, [])

def add_permission(self, user_role, permission):
if user_role not in self.permissions:
self.permissions[user_role] = []
self.permissions[user_role].append(permission)

def remove_permission(self, user_role, permission):
if user_role in self.permissions and permission in self.permissions[user_role]:
self.permissions[user_role].remove(permission)

def save_permissions(self, file_path):
with open(file_path, 'w') as file:
json.dump(self.permissions, file)

def load_permissions(self, file_path):
with open(file_path, 'r') as file:
self.permissions = json.load(file)

0 comments on commit 882da43

Please sign in to comment.