Пример #1
0
 def take_file(self, fileId, format="json", **kwargs):
     user, sMessages, fMessages = (cherrypy.session.get("user"), [], [])
     config = cherrypy.request.app.config['filelocker']
     try:
         flFile = session.query(File).filter(File.id == fileId).one()
         if flFile.owner_id == user.id:
             fMessages.append("You cannot take your own file")
         elif flFile.shared_with(
                 user) or AccountService.user_has_permission(user, "admin"):
             if (FileService.get_user_quota_usage_bytes(user) +
                     flFile.size) >= (user.quota * 1024 * 1024):
                 cherrypy.log.error(
                     "[%s] [take_file] [User has insufficient quota space remaining to check in file: %s]"
                     % (user.id, flFile.name))
                 raise Exception(
                     "You may not copy this file because doing so would exceed your quota"
                 )
             takenFile = flFile.get_copy()
             takenFile.owner_id = user.id
             takenFile.date_uploaded = datetime.datetime.now()
             takenFile.notify_on_download = False
             session.add(takenFile)
             session.commit()
             shutil.copy(os.path.join(config['vault'], str(flFile.id)),
                         os.path.join(config['vault'], str(takenFile.id)))
             sMessages.append(
                 "Successfully took ownership of file %s. This file can now be shared with other users just as if you had uploaded it. "
                 % flFile.name)
         else:
             fMessages.append(
                 "You do not have permission to take this file")
     except sqlalchemy.orm.exc.NoResultFound, nrf:
         fMessages.append("Could not find file with ID: %s" % str(fileId))
Пример #2
0
 def take_file(self, fileId, format="json", requestOrigin="", **kwargs):
     user, sMessages, fMessages = (cherrypy.session.get("user"), [], [])
     if requestOrigin != cherrypy.session['request-origin']:
         fMessages.append("Missing request key!!")
     else:
         config = cherrypy.request.app.config['filelocker']
         try:
             flFile = session.query(File).filter(File.id==fileId).one()
             if flFile.owner_id == user.id:
                 fMessages.append("You cannot take your own file")
             elif flFile.shared_with(user) or AccountService.user_has_permission(user, "admin"):
                 if (FileService.get_user_quota_usage_bytes(user) + flFile.size) >= (user.quota*1024*1024):
                     cherrypy.log.error("[%s] [take_file] [User has insufficient quota space remaining to check in file: %s]" % (user.id, flFile.name))
                     raise Exception("You may not copy this file because doing so would exceed your quota")
                 takenFile = flFile.get_copy()
                 takenFile.owner_id = user.id
                 takenFile.date_uploaded = datetime.datetime.now()
                 takenFile.notify_on_download = False
                 session.add(takenFile)
                 session.commit()
                 shutil.copy(os.path.join(config['vault'],str(flFile.id)), os.path.join(config['vault'],str(takenFile.id)))
                 sMessages.append("Successfully took ownership of file %s. This file can now be shared with other users just as if you had uploaded it. " % flFile.name)
             else:
                 fMessages.append("You do not have permission to take this file")
         except sqlalchemy.orm.exc.NoResultFound, nrf:
             fMessages.append("Could not find file with ID: %s" % str(fileId))
         except Exception, e:
             session.rollback()
             fMessages.append(str(e))
Пример #3
0
 def get_quota_usage(self, format="json", **kwargs):
     user, sMessages, fMessages, quotaMB, quotaUsedMB = (cherrypy.session.get("user"),[], [], 0, 0)
     try:
         quotaMB, quotaUsage = 0,0
         if cherrypy.session.get("current_role") is not None:
             quotaMB = cherrypy.session.get("current_role").quota
             quotaUsage = FileService.get_role_quota_usage_bytes(cherrypy.session.get("current_role").id)
         else:
             quotaMB = user.quota
             quotaUsage = FileService.get_user_quota_usage_bytes(user.id)
         quotaUsedMB = int(quotaUsage) / 1024 / 1024
     except Exception, e:
         fMessages.append(str(e))
Пример #4
0
 def get_quota_usage(self, format="json", **kwargs):
     user, sMessages, fMessages, quotaMB, quotaUsedMB = (
         cherrypy.session.get("user"), [], [], 0, 0)
     try:
         quotaMB, quotaUsage = 0, 0
         if cherrypy.session.get("current_role") is not None:
             quotaMB = cherrypy.session.get("current_role").quota
             quotaUsage = FileService.get_role_quota_usage_bytes(
                 cherrypy.session.get("current_role").id)
         else:
             quotaMB = user.quota
             quotaUsage = FileService.get_user_quota_usage_bytes(user.id)
         quotaUsedMB = int(quotaUsage) / 1024 / 1024
     except Exception, e:
         fMessages.append(str(e))
Пример #5
0
            fMessages.append(
                "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified."
            )
            raise cherrypy.HTTPError(
                413,
                "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified."
            )
        quotaSpaceRemainingBytes = 0
        if role is not None:
            quotaSpaceRemainingBytes = (
                role.quota * 1024 *
                1024) - FileService.get_role_quota_usage_bytes(role.id)
        else:
            quotaSpaceRemainingBytes = (
                user.quota * 1024 *
                1024) - FileService.get_user_quota_usage_bytes(user.id)
        if fileSizeBytes > quotaSpaceRemainingBytes:
            fMessages.append(
                "File size is larger than your quota will accommodate")
            raise cherrypy.HTTPError(
                413, "File size is larger than your quota will accommodate")

        #The server won't respond to additional user requests (polling) until we release the lock
        cherrypy.session.release_lock()

        newFile = File()
        newFile.size = fileSizeBytes
        #Get the file name
        fileName, tempFileName = None, None
        if fileName is None and lcHDRS.has_key('x-file-name'):
            fileName = lcHDRS['x-file-name']
Пример #6
0
            fileSizeBytes = int(lcHDRS['content-length'])
        except KeyError, ke:
            fMessages.append("Request must have a valid content length")
            raise cherrypy.HTTPError(411, "Request must have a valid content length")
        fileSizeMB = ((fileSizeBytes/1024)/1024)
        vaultSpaceFreeMB, vaultCapacityMB = FileService.get_vault_usage()
        
        if (fileSizeMB*2) >= vaultSpaceFreeMB:
            cherrypy.log.error("[system] [upload] [File vault is running out of space and cannot fit this file. Remaining Space is %s MB, fileSizeBytes is %s]" % (vaultSpaceFreeMB, fileSizeBytes))
            fMessages.append("The server doesn't have enough space left on its drive to fit this file. The administrator has been notified.")
            raise cherrypy.HTTPError(413, "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified.")
        quotaSpaceRemainingBytes = 0
        if role is not None:
            quotaSpaceRemainingBytes = (role.quota*1024*1024) - FileService.get_role_quota_usage_bytes(role.id)
        else:
            quotaSpaceRemainingBytes = (user.quota*1024*1024) - FileService.get_user_quota_usage_bytes(user.id)
        if fileSizeBytes > quotaSpaceRemainingBytes:
            fMessages.append("File size is larger than your quota will accommodate")
            raise cherrypy.HTTPError(413, "File size is larger than your quota will accommodate")

        #The server won't respond to additional user requests (polling) until we release the lock
        cherrypy.session.release_lock()

        newFile = File()
        newFile.size = fileSizeBytes
        #Get the file name
        fileName, tempFileName = None,None
        if fileName is None and lcHDRS.has_key('x-file-name'):
            fileName = lcHDRS['x-file-name']
        if kwargs.has_key("fileName"):
            fileName = kwargs['fileName']