Example #1
0
def setDefaultAuthority(request, *args, **kwargs):
    path = request.POST.get("path")
    response = {
        "code"      : 0,
        "message"   : "",
        "path"      : path,
        "register"  : False,
        "readable"  : config.DEFAULT_AUTH_DIR_READABLE,
        "writeable" : config.DEFAULT_AUTH_DIR_WRITEABLE,
        "deletable" : config.DEFAULT_AUTH_DIR_DELETABLE,
        "inherit"   : config.DEFAULT_AUTH_DIR_INHERIT
    }
     
    userinfo = UserInfo.getUserInfo(request)
    fullpath = userinfo.getHomePath() + request.POST.get("path")

    if not userinfo.isAdmin() :
        response['code']    = -1
        response['message'] = "권한 초기화는 최고 관리자만 가능합니다"
    else :     
        inherit = request.POST.get("inherit")
        if inherit is not None :
            inherit = inherit == "1"
     
        readable = request.POST.get("readable")
        if readable is not None :
            readable = readable == "1"
          
        writeable = request.POST.get("writeable")
        if writeable is not None :
            writeable = writeable == "1"
          
        deletable = request.POST.get("deletable")
        if deletable is not None :
            deletable = deletable == "1"
     
        result = Directory.setAuth(fullpath, inherit, readable, writeable, deletable)
        if result[0] >= 0 :
            response["code"]        = 0
            response["message"]     = result[1]
            response['register']    = True
            response['inherit']     = inherit
            response['readable']    = readable
            response['writeable']   = writeable
            response['deletable']   = deletable
     
    return HttpResponse(json.dumps(response))
Example #2
0
def browseFilelist(request, *args, **kwrags):
    targetDir   = request.POST.get('target')
    result      = util.getFileGroup(request, targetDir)
     
    userinfo    = UserInfo.getUserInfo(request)
    auth        = Directory.getAuth(userinfo, userinfo.getHomePath() + targetDir)
      
    context = {
        'target'    : targetDir,
        'directory' : result[0],
        'file'      : result[1],
        'readable'  : auth[0],
        'writeable' : auth[1],
        'deletable' : auth[2]
    }
     
    # info("browse.filelist : " + targetDir)
    return HttpResponse(json.dumps(context))    
Example #3
0
def browse(request, *args, **kwrags):
    targetDir   = request.POST.get('target')
    filelist    = util.getFileGroup(request, targetDir)
    directree   = util.getDirTree(request, targetDir, 2)
 
    userinfo    = UserInfo.getUserInfo(request)
    auth        = Directory.getAuth(userinfo, userinfo.getHomePath() + targetDir)
         
    context = {
        'target'    : targetDir,
        'filelist'  : {
            'directory' : filelist[0],
            'file'      : filelist[1],
            'readable'  : auth[0],
            'writeable' : auth[1],
            'deletable' : auth[2] 
        },
        'directree' : {
            'node'      : directree
        }
    }
     
    # info("browse.all : " + targetDir)    
    return HttpResponse(json.dumps(context))
Example #4
0
def delDefaultAuthority(request, *args, **kwargs):
    path = request.POST.get("path")
    response = {
        "code"      : 0,
        "message"   : "",
        "path"      : path,
        "register"  : False,
        "readable"  : config.DEFAULT_AUTH_DIR_READABLE,
        "writeable" : config.DEFAULT_AUTH_DIR_WRITEABLE,
        "deletable" : config.DEFAULT_AUTH_DIR_DELETABLE,
        "inherit"   : config.DEFAULT_AUTH_DIR_INHERIT
    }
     
    userinfo = UserInfo.getUserInfo(request)
    fullpath = userinfo.getHomePath() + request.POST.get("path")
     
    if not userinfo.isAdmin() :
        response['code'] = 1
        response['message'] = "최고 관리자만 가능합니다"
    elif not Directory.delAuth(fullpath) : 
        response["code"] = -1
        response["message"] = "디렉토리 식별자 삭제 실패"
         
    return HttpResponse(json.dumps(response))
Example #5
0
def setAuthorizedUsers(request, *args, **kwargs):
    response = {
        "code"      : 0,
        "message"   : "",
        "users"     : []
    }
     
    userinfo = UserInfo.getUserInfo(request)
    fullpath = userinfo.getHomePath() + request.POST.get("path")
    
    ids         = request.POST.getlist("ids[]")
    readable    = request.POST.get('readable')
    readable    = (readable == "1", None)[readable == None]
    writeable   = request.POST.get('writeable')
    writeable   = (writeable == "1", None)[writeable == None]
    deletable   = request.POST.get('deletable')
    deletable   = (deletable == "1", None)[deletable == None]
    if userinfo.isAdmin() :         
        file_id = index.dir_get(fullpath) 
        if file_id is None :
            file_id = Directory.setAuth(fullpath, config.DEFAULT_AUTH_DIR_INHERIT, config.DEFAULT_AUTH_DIR_READABLE, config.DEFAULT_AUTH_DIR_WRITEABLE, config.DEFAULT_AUTH_DIR_DELETABLE)[0]
            
        fileDescriptor = FileDescriptor.objects.get(file_id=file_id)
        try :
            with transaction.atomic() :
                for authUser in UserInfo.objects.filter(username__in=ids) :
                    userAuthority = None
                    try :
                        userAuthority = UserAuthority.objects.get(username=authUser, file_id=fileDescriptor)
                        if (readable  is not None and userAuthority.readable == readable) or \
                           (writeable is not None and userAuthority.writeable == writeable) or \
                           (deletable is not None and userAuthority.deletable == deletable) :
                            continue
                          
                    except Exception as err :
                        userAuthority = UserAuthority(username=authUser, file_id=fileDescriptor)
                          
                    if readable is not None :
                        userAuthority.readable = readable
                    if writeable is not None :
                        userAuthority.writeable = writeable
                    if deletable is not None :
                        userAuthority.deletable = deletable
                    userAuthority.save()
                    response['users'].append([
                                authUser.username,
                                authUser.getName(),
                                authUser.usertype,
                                userAuthority.readable,
                                userAuthority.writeable,
                                userAuthority.deletable])
                      
        except Exception as err :
            response['code'] = -2
            response['message'] = err.__str__()
            response['users'].clear()
                 
    else :
        response['code'] = 1
        response['message'] = "최고 관리자만 가능합니다"
         
    return HttpResponse(json.dumps(response))