Merge branch 'fix/duplicateRights' into dev
This commit is contained in:
commit
a6cbc6a76a
@ -123,16 +123,19 @@ class AccessControlList():
|
||||
except:
|
||||
raise CommandException("Can\'t remove this user from this group.")
|
||||
|
||||
def addFile(self, user, file, read=[], write=[], execute=[]):
|
||||
def addFile(self, user, file):
|
||||
if list(self.__data['files'].keys()).count(file) == 0:
|
||||
read = []
|
||||
execute = []
|
||||
write = []
|
||||
# Only owner and its group (plus selected persons) can access this file
|
||||
read.extend(getGroupsByUser(self.__data['groups'], user))
|
||||
|
||||
# Only owner (plus selected persons) can modify this file
|
||||
# write.append(user) (Not mandatory, the own test is done)
|
||||
|
||||
# Only owner and its group (plus selected persons) can execute this file
|
||||
execute.extend(getGroupsByUser(self.__data['groups'], user))
|
||||
print(read)
|
||||
|
||||
self.__data['files'][file] = {'owner': user, 'read': read, 'write': write, 'execute': execute}
|
||||
|
||||
@ -176,7 +179,7 @@ class AccessControlList():
|
||||
|
||||
def changeOwnOnFile(self, user, file, newUser):
|
||||
try:
|
||||
if user == self.__data['files'][file]['owner']:
|
||||
if user == self.__data['files'][file]['owner'] or self.isAdministrator(user):
|
||||
self.__data['files'][file]['owner'] = newUser
|
||||
self.saveToFile()
|
||||
|
||||
|
@ -91,7 +91,7 @@ def removeFile(command, client, acl):
|
||||
if os.path.exists(path):
|
||||
with client.mutex:
|
||||
if os.path.isdir(path):
|
||||
if acl.isAllowedToOn(client.username, 'write', path + '/'):
|
||||
if acl.isAllowedToOn(client.username, 'write', path + '/') or acl.isAdministrator(client.username):
|
||||
try:
|
||||
os.rmdir(path)
|
||||
acl.deleteFile(client.username, path + '/')
|
||||
@ -103,7 +103,7 @@ def removeFile(command, client, acl):
|
||||
raise CommandException("You\'re not allowed to perform this operation.")
|
||||
|
||||
else:
|
||||
if acl.isAllowedToOn(client.username, 'write', path):
|
||||
if acl.isAllowedToOn(client.username, 'write', path) or acl.isAdministrator(client.username):
|
||||
try:
|
||||
os.remove(path)
|
||||
acl.deleteFile(client.username, path)
|
||||
@ -125,7 +125,7 @@ def removeFile(command, client, acl):
|
||||
path = interpretPath(command[1], client)
|
||||
if os.path.exists(path):
|
||||
with client.mutex:
|
||||
if acl.isAllowedToOn(client.username, 'write', path + '/'):
|
||||
if acl.isAllowedToOn(client.username, 'write', path + '/') or acl.isAdministrator(client.username):
|
||||
if os.path.isdir(path):
|
||||
try:
|
||||
acl.deleteFile(client.username, path + '/')
|
||||
@ -184,7 +184,7 @@ def moveFile(command, client, acl):
|
||||
with client.mutex:
|
||||
if os.path.isdir(source):
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'write', source.rpartition('/')[0] + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/'):
|
||||
if (acl.isAllowedToOn(client.username, 'write', source.rpartition('/')[0] + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/')) or acl.isAdministrator(client.username):
|
||||
acl.deleteFile(client.username, source + '/')
|
||||
acl.addFile(client.username, destination + '/')
|
||||
updateAclDelete(source + '/', acl)
|
||||
@ -206,7 +206,7 @@ def moveFile(command, client, acl):
|
||||
with client.mutex:
|
||||
if os.path.isdir(source):
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'write', source.rpartition('/')[0] + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/'):
|
||||
if (acl.isAllowedToOn(client.username, 'write', source.rpartition('/')[0] + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/')) or acl.isAdministrator(client.username):
|
||||
acl.deleteFile(client.username, source + '/')
|
||||
acl.addFile(client.username, destination + '/' + command[1] + '/')
|
||||
updateAclDelete(source + '/', acl)
|
||||
@ -252,7 +252,7 @@ def makeDirectory(command, client, acl):
|
||||
directories.remove(directories[0])
|
||||
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'write', pathKnown):
|
||||
if acl.isAllowedToOn(client.username, 'write', pathKnown) or acl.isAdministrator(client.username):
|
||||
with client.mutex:
|
||||
os.makedirs(path)
|
||||
updateAcl(pathKnown, directories, acl)
|
||||
@ -265,7 +265,7 @@ def makeDirectory(command, client, acl):
|
||||
elif nbArgs == 2:
|
||||
try:
|
||||
path = interpretPath(command[1], client)
|
||||
if acl.isAllowedToOn(client.username, 'write', path.rpartition('/')[0] + '/'):
|
||||
if acl.isAllowedToOn(client.username, 'write', path.rpartition('/')[0] + '/') or acl.isAdministrator(client.username):
|
||||
with client.mutex:
|
||||
os.mkdir(path)
|
||||
acl.addFile(client.username, path + '/')
|
||||
@ -291,7 +291,7 @@ def changeDirectory(command, client, acl):
|
||||
raise CommandException("This directory does not exist.")
|
||||
|
||||
else:
|
||||
if acl.isAllowedToOn(client.username, 'execute', path):
|
||||
if acl.isAllowedToOn(client.username, 'execute', path) or acl.isAdministrator(client.username):
|
||||
client.currentWorkingDir = path
|
||||
|
||||
else:
|
||||
@ -306,7 +306,7 @@ def changeDirectory(command, client, acl):
|
||||
raise CommandException("This directory does not exist.")
|
||||
|
||||
else:
|
||||
if acl.isAllowedToOn(client.username, 'execute', path):
|
||||
if acl.isAllowedToOn(client.username, 'execute', path) or acl.isAdministrator(client.username):
|
||||
client.currentWorkingDir = path
|
||||
|
||||
else:
|
||||
@ -336,7 +336,7 @@ def listFiles(command, client, acl):
|
||||
else:
|
||||
message = ''
|
||||
|
||||
if acl.isAllowedToOn(client.username, 'read', path):
|
||||
if acl.isAllowedToOn(client.username, 'read', path) or acl.isAdministrator(client.username):
|
||||
files = os.listdir(path)
|
||||
if len(files) == 0:
|
||||
message = "This directory is empty."
|
||||
@ -363,7 +363,7 @@ def listFiles(command, client, acl):
|
||||
|
||||
message = ''
|
||||
|
||||
if acl.isAllowedToOn(client.username, 'read', path):
|
||||
if acl.isAllowedToOn(client.username, 'read', path) or acl.isAdministrator(client.username):
|
||||
files = os.listdir(path)
|
||||
if len(files) == 0:
|
||||
message = "This directory is empty."
|
||||
@ -412,7 +412,7 @@ def copyFile(command, client, acl):
|
||||
if not os.path.isdir(source):
|
||||
with client.mutex:
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0]):
|
||||
if (acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0])) or acl.isAdministrator(client.username):
|
||||
shutil.copy(source, destination)
|
||||
acl.addFile(client.username, destination)
|
||||
|
||||
@ -443,7 +443,7 @@ def copyFile(command, client, acl):
|
||||
with client.mutex:
|
||||
if os.path.isdir(source):
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'read', source + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/'):
|
||||
if (acl.isAllowedToOn(client.username, 'read', source + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/')) or acl.isAdministrator(client.username):
|
||||
shutil.copytree(source, destination)
|
||||
acl.addFile(client.username, destination + '/')
|
||||
updateAcl(destination + '/', acl)
|
||||
@ -456,7 +456,7 @@ def copyFile(command, client, acl):
|
||||
|
||||
else:
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0]):
|
||||
if (acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0])) or acl.isAdministrator(client.username):
|
||||
shutil.copy(source, destination)
|
||||
acl.addFile(client.username, destination)
|
||||
|
||||
@ -467,7 +467,7 @@ def copyFile(command, client, acl):
|
||||
with client.mutex:
|
||||
if os.path.isdir(source):
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'read', source + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/'):
|
||||
if (acl.isAllowedToOn(client.username, 'read', source + '/') and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0] + '/')) or acl.isAdministrator(client.username):
|
||||
shutil.copytree(source, destination + '/' + command[2])
|
||||
acl.addFile(client.username, destination + '/' + command[2] + '/')
|
||||
updateAcl(destination + '/' + command[2] + '/', acl)
|
||||
@ -479,7 +479,7 @@ def copyFile(command, client, acl):
|
||||
|
||||
else:
|
||||
try:
|
||||
if acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0]):
|
||||
if (acl.isAllowedToOn(client.username, 'read', source) and acl.isAllowedToOn(client.username, 'write', destination.rpartition('/')[0])) or acl.isAdministrator(client.username):
|
||||
shutil.copy(source, destination)
|
||||
acl.addFile(client.username, destination + '/' + command[2])
|
||||
|
||||
|
@ -18,7 +18,7 @@ from ACL import AccessControlList
|
||||
from socketCommands import sendData, recvData
|
||||
from fileCommands import DATA_PATH, listFiles, changeDirectory, makeDirectory, removeFile, copyFile, textEditor, moveFile
|
||||
from CommandException import CommandException
|
||||
from ulCommands import add, remove, addUserGroup, removeUserGroup
|
||||
from ulCommands import add, remove, addUserGroup, removeUserGroup, ownerFile
|
||||
|
||||
|
||||
__authors__ = "HorlogeSkynet, Tatiyk, CaumartinYann"
|
||||
@ -236,6 +236,9 @@ def computeCommand(command, client):
|
||||
elif command[0] == 'removeusergroup' and len(command) == 3:
|
||||
sendData(client.sock, removeUserGroup(command, client, acl))
|
||||
|
||||
elif command[0] == 'owner' and len(command) == 3:
|
||||
sendData(client.sock, ownerFile(command, client, acl))
|
||||
|
||||
# Unknown command
|
||||
else:
|
||||
sendData(client.sock, "An unknown command has been received by server.")
|
||||
|
@ -13,6 +13,7 @@ __status__ = "Development"
|
||||
__date__ = "03/30/2017"
|
||||
|
||||
from CommandException import CommandException
|
||||
from fileCommands import interpretPath
|
||||
|
||||
|
||||
def add(command, client, userList, acl):
|
||||
@ -45,3 +46,9 @@ def removeUserGroup(command, client, acl):
|
||||
return "User " + command[1] + " removed from " + command[2]
|
||||
else:
|
||||
raise CommandException("You\'re not allowed to perform this operation.")
|
||||
|
||||
|
||||
def ownerFile(command, client, acl):
|
||||
command[1] = interpretPath(command[1], client) + "/"
|
||||
acl.changeOwnOnFile(client.username, command[1], command[2])
|
||||
return "The owner of " + command[1] + " is now " + command[2]
|
||||
|
Reference in New Issue
Block a user