python: setUsers for region protection

This commit is contained in:
sshakndr
2023-10-27 18:22:46 +07:00
parent ace724bc21
commit eaf0245216
4 changed files with 29 additions and 6 deletions

View File

@ -90,7 +90,7 @@ USERS = [
},
['group-2', ''],
True, [], descr_user_2, False),
User('uid-3', 'Hamish Mitchell', 'mitchell@example.com',
User('uid-3', 'Hamish Mitchell', None,
'group-3', ['group-2'], {
'view': ["group-3", "group-2"],
'edit': ["group-2"],
@ -126,6 +126,14 @@ def getUsersForMentions(uid):
usersData.append({'name':user.name, 'email':user.email})
return usersData
# get users data for protect
def getUsersForProtect(uid):
usersData = []
for user in USERS:
if(user.id != uid and user.name != None):
usersData.append({'id': user.id, 'name': user.name, 'email': user.email})
return usersData
def find_user(id: Optional[str]) -> User:
if id is None:
return DEFAULT_USER

View File

@ -322,6 +322,8 @@ def edit(request):
# users data for mentions
usersForMentions = users.getUsersForMentions(user.id)
# users data for protect
usersForProtect = users.getUsersForProtect(user.id)
if jwtManager.isEnabled(): # if the secret key to generate token exists
edConfig['token'] = jwtManager.encode(edConfig) # encode the edConfig object into a token
@ -340,7 +342,8 @@ def edit(request):
'dataInsertImage': json.dumps(dataInsertImage)[1 : len(json.dumps(dataInsertImage)) - 1], # the image which will be inserted into the document
'dataDocument': dataDocument, # document which will be compared with the current document
'dataSpreadsheet': json.dumps(dataSpreadsheet), # recipient data for mail merging
'usersForMentions': json.dumps(usersForMentions) if user.id !='uid-0' else None
'usersForMentions': json.dumps(usersForMentions) if user.id !='uid-0' else None,
'usersForProtect': json.dumps(usersForProtect) if user.id !='uid-0' else None
}
return render(request, 'editor.html', context) # execute the "editor.html" template with context data