forked from Abhiroop-tales/ACCORD-WWW24Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecuteResolutions.py
116 lines (99 loc) · 4.3 KB
/
executeResolutions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import sys, time, psutil
from extractDriveFiles import getUserID
class ExecuteResolutionThread():
'''Execute a conflict resolution
Attributes:
activityTime: str, datetime
activity: str, full description of activity, format specific to action
action: str, action type of resolution (action that caused conflict)
documentId: str, doc to perform resolution on
actor: str
driveAPIservice: Resource object for user's Drive API Service
'''
def __init__(self, activityTime, activity, documentId, actor, drive_service):
try:
super(ExecuteResolutionThread,self).__init__()
self.activityTime = activityTime
self.activity = activity
self.action = activity.split(':')[0].split('-')[0]
self.documentId = documentId
self.actor = actor
self.driveAPIservice = drive_service
except LookupError as le:
return("Error in the key or index !!\n" + str(le))
except ValueError as ve:
return("Error in Value Entered !!\n" + str(ve))
except TypeError as te:
return("Error in Type matching !!\n" + str(te))
def run(self):
'''Thread main: choose and execute correct resolution'''
val = False
if(self.action == "Permission Change"):
val = self.permissionChangeResolutions()
elif(self.action == "Edit"):
pass
elif(self.action == "Move"):
pass
elif(self.action == "Delete"):
pass
else:
pass
return val
def permissionChangeResolutions(self):
'''Resolve a permissions-related conflict by reverting changes'''
try:
fileID = self.documentId
actionSplit = self.activity.split(':')
action = actionSplit[0].split('-')[0]
toAction = actionSplit[1].split('-')[0]
fromAction = actionSplit[2].split('-')[0]
user = actionSplit[3]
userID = getUserID(self.driveAPIservice, self.documentId, user)
if('none' in fromAction and 'none' not in toAction):
actionType = "Remove Permission"
elif('none' not in fromAction and 'none' in toAction):
actionType = "Add Permission"
else:
actionType = "Update Permission"
if('edit' in fromAction):
old_role = "writer"
elif('comment' in fromAction):
old_role = "commenter"
else:
old_role = "reader"
if('edit' in toAction):
new_role = "writer"
elif('comment' in toAction):
new_role = "commenter"
else:
new_role = "reader"
# Perform permission Change action based on the input arguments
match actionType:
# Add User to the file
case "Add Permission":
permission = {
'type': 'user',
'role': old_role,
'emailAddress': user
}
self.driveAPIservice.permissions().create(fileId=fileID, body=permission, sendNotificationEmail=False).execute()
return True
case "Remove Permission":
# Remove the user ID from the file permissions
self.driveAPIservice.permissions().delete(fileId=fileID, permissionId = userID).execute()
return True
case "Update Permission":
# Update the permission on file for user from one to another
new_user_role = new_role
new_permission = {'role' : new_user_role }
self.driveAPIservice.permissions().update(fileId=fileID, permissionId = userID, body=new_permission).execute()
return True
case _:
pass
return False
except LookupError as le:
return("Error in the key or index !!\n" + str(le))
except ValueError as ve:
return("Error in Value Entered !!\n" + str(ve))
except TypeError as te:
return("Error in Type matching !!\n" + str(te))