Example #1
0
def general(request, *args, **kwargs):
    userinfo = UserInfo.getUserInfo(request)
      
    isSubmitted = request.POST.get("isSubmitted");
    pageYOffset = "0";
      
    if userinfo.isAdmin() and isSubmitted :
        config.TITLE            = request.POST.get("title")
        config.ROOT             = request.POST.get("root")
        config.HOME_USER        = request.POST.get("home_user")
        config.HOME_GUEST       = request.POST.get("home_guest")
        config.USING_GUEST      = isChecked(request,"using_guest")
        config.LOGIN_CAMPAIGN   = isChecked(request,"login_campaign")
        config.INDEX_FILE       = request.POST.get("index_file")       
          
        config.DEFAULT_AUTH_DIR_READABLE    = isChecked(request,"default_readable") 
        config.DEFAULT_AUTH_DIR_WRITEABLE   = isChecked(request,"default_writeable")
        config.DEFAULT_AUTH_DIR_DELETABLE   = isChecked(request,"default_deletable")
        config.DEFAULT_AUTH_DIR_INHERIT     = isChecked(request,"default_inherit")
        
        config.save()
          
        pageYOffset = request.POST.get("pageYOffset")
          
        restart(userinfo)
      
    context = { 
           "config"         : vars(config), 
           "pageYOffset"    : pageYOffset,
           "isAdmin"        : UserInfo.getUserInfo(request).isAdmin()
        } 
    return HttpResponse(render(request, "admin_general.html", context ))
Example #2
0
def general(request, *args, **kwargs):
    userinfo = UserInfo.getUserInfo(request)

    isSubmitted = request.POST.get("isSubmitted")
    pageYOffset = "0"

    if userinfo.isAdmin() and isSubmitted:
        config.TITLE = request.POST.get("title")
        config.ROOT = request.POST.get("root")
        config.HOME_USER = request.POST.get("home_user")
        config.HOME_GUEST = request.POST.get("home_guest")
        config.USING_GUEST = isChecked(request, "using_guest")
        config.LOGIN_CAMPAIGN = isChecked(request, "login_campaign")
        config.INDEX_FILE = request.POST.get("index_file")

        config.DEFAULT_AUTH_DIR_READABLE = isChecked(request,
                                                     "default_readable")
        config.DEFAULT_AUTH_DIR_WRITEABLE = isChecked(request,
                                                      "default_writeable")
        config.DEFAULT_AUTH_DIR_DELETABLE = isChecked(request,
                                                      "default_deletable")
        config.DEFAULT_AUTH_DIR_INHERIT = isChecked(request, "default_inherit")

        config.save()

        pageYOffset = request.POST.get("pageYOffset")

        restart(userinfo)

    context = {
        "config": vars(config),
        "pageYOffset": pageYOffset,
        "isAdmin": UserInfo.getUserInfo(request).isAdmin()
    }
    return HttpResponse(render(request, "admin_general.html", context))
Example #3
0
def userGet(request, *args, **kwargs):
    username    = request.POST.get("username")
    sessionInfo = UserInfo.getUserInfo(request)
     
    response = {
        "code"      : "",
        "message"   : ""
    }
     
    if sessionInfo.isAdmin() or request.user.username == username :
        result = UserInfo.objects.filter(username__exact = username)
        if not result.exists() :
            response["code"] = -1
            response["message"] = "존재하지 않는 아이디 입니다."
        else :
            userinfo    = result[0]
            user        = User.objects.get(username = userinfo.username )
             
            response["username"]    = userinfo.username
            response["name"]        = user.first_name
            response["email"]       = user.email
            response["usertype"]    = userinfo.usertype
            response["home"]        = userinfo.home 
            response["memo"]        = userinfo.memo
             
            response["code"]        = 0
    else :
        response["code"]    = -4
        response["message"] = "권한이 없습니다."
     
    return HttpResponse(json.dumps(response))
Example #4
0
def userDelete(request, *args, **kwargs):
    response = {
        "code"      : "",
        "message"   : ""
    }
     
    username    = request.POST.get("username")
    user        = User.objects.get(username = username)
    sessionInfo = UserInfo.getUserInfo(request)
    if not ( sessionInfo.isAdmin() or request.user.username == username ) :
        response["code"] = -4
        response["message"] = "권한이 없습니다."
        return HttpResponse(json.dumps(response))
     
    if user.is_superuser :
        response["code"] = -3
        response["message"] = "시스템 관리자 계정은 삭제할 수 없습니다."
        return HttpResponse(json.dumps(response))
         
    try :
        with transaction.atomic() :
            User.objects.get(username__exact = username ).delete()
            UserInfo.objects.get(username__exact = username ).delete()
    except IntegrityError :
        response["code"] = -1
        response["message"] = "사용자 계정을 삭제하는 도중에 오류가 발생했습니다."
        return HttpResponse(json.dumps(response))
                 
    response["code"] = 0
    response["message"] = "사용자 계정이 삭제 되었습니다."
    return HttpResponse(json.dumps(response))
Example #5
0
def getAuthorizedUsers(request, *args, **kwargs):
    response = {
        "code"      : 0,
        "message"   : "",
        "users"     : []
    }
     
    userinfo = UserInfo.getUserInfo(request)
    fullpath = userinfo.getHomePath() + request.POST.get("path")
    authType = int(request.POST.get("type"))
     
    if userinfo.isAdmin() :
        file_id = index.dir_get(fullpath)
        if file_id is not None :
            for user in UserAuthority.objects.filter(file_id=file_id)  :
                if      authType & 4 and not user.readable     : continue
                elif    authType & 2 and not user.writeable    : continue
                elif    authType & 1 and not user.deletable    : continue
                 
                response['users'].append([user.username.username,
                                          user.username.getName(),
                                          user.username.usertype])
    else :
        response['code'] = 1
        response['message'] = "최고 관리자만 가능합니다"
         
    return HttpResponse(json.dumps(response))
Example #6
0
def _getContext(request):
    userInfo = UserInfo.getUserInfo(request)
    return {
        "config": config,
        "isAdmin": userInfo.isAdmin(),
        "isSuper": userInfo.isSuper(),
        "is_ajax": request.is_ajax()
    }
Example #7
0
def _getContext(request) :
    userInfo = UserInfo.getUserInfo(request) 
    return {
        "config"    : config,
        "isAdmin"   : userInfo.isAdmin(),
        "isSuper"   : userInfo.isSuper(),
        "is_ajax"   : request.is_ajax()
    } 
Example #8
0
def userLogin(request, *args, **kwargs):
    redirectURL = None
    context = {}
     
    if request.POST.get("user.login") :
        username = request.POST.get('username')
        password = request.POST.get("password")
        
        redirectURL = request.POST.get("redirectURL", "cellar")
        
        if username and password :
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active :
                login(request, user) 
                   
                # django 에서 직접 만든 ID 의 경우 UserInfo 가 누락되어있으므로 생성해준다.
                if not UserInfo.objects.filter(username=username).exists() :
                    if user.is_superuser :
                        usertype = UserInfo.SUPER 
                    else  :
                        usertype = UserInfo.NORMAL
                       
                    userinfo = UserInfo(username=username, usertype=usertype)
                    userinfo.save()
                     
                if request.POST.get("auto_login") : 
                    request.session.set_expiry(86400 * 365 * 10)
                return redirect(reverse(redirectURL))
            else :
                context['message'] = '아이디 또는 암호가 잘못 되었습니다.'
        else :
            context['message'] = '아이디와 암호를 입력하여 주십시오.'
           
        if username :
            context['username'] = username
           
    else :
        info(kwargs)
        redirectURL = kwargs.get("redirect") 
             
    if redirectURL :
        context['redirectURL'] = redirectURL
             
    return HttpResponse(render(request, "user_login.html", {'userLogin' : context}))
Example #9
0
def myinfo(request, *args, **kwargs):
    userinfo    = UserInfo.getUserInfo(request)
    user        = User.objects.get(username = userinfo.username )
     
    context = {
        "username"  : user.username,
        "name"      : user.first_name,
        "email"     : user.email,
        "memo"      : userinfo.memo
    }
    return HttpResponse(render(request, "user_myinfo.html", context))
Example #10
0
def myinfo(request, *args, **kwargs):
    userinfo = UserInfo.getUserInfo(request)
    user = User.objects.get(username=userinfo.username)

    context = {
        "username": user.username,
        "name": user.first_name,
        "email": user.email,
        "memo": userinfo.memo
    }
    return HttpResponse(render(request, "user_myinfo.html", context))
Example #11
0
def simple_response(request, *args, **kwargs):
    template_name = kwargs["path"]
    if kwargs["type"] :
        template_name = kwargs["type"] + "/" + template_name
        
    userInfo = UserInfo.getUserInfo(request)
    context = {
        "isMetic"   : userInfo.isMetic(),
        "isYeoman"  : userInfo.isYeoman(),
        "isAdmin"   : userInfo.isAdmin(),
        "isSuper"   : userInfo.isSuper()
    }
        
    return HttpResponse(render(request, template_name, context))
Example #12
0
def simple_response(request, *args, **kwargs):
    template_name = kwargs["path"]
    if kwargs["type"]:
        template_name = kwargs["type"] + "/" + template_name

    userInfo = UserInfo.getUserInfo(request)
    context = {
        "isMetic": userInfo.isMetic(),
        "isYeoman": userInfo.isYeoman(),
        "isAdmin": userInfo.isAdmin(),
        "isSuper": userInfo.isSuper()
    }

    return HttpResponse(render(request, template_name, context))
Example #13
0
def userNew(request, *args, **kwargs):
    context = {}
    userinfo = UserInfo.getUserInfo(request)
    
    if request.POST.get("signup") :
        response = userCreate(request.POST, userinfo.isAdmin())
       
        if response["code"] == 0 :
            context["code"]     = 0
            context["message"]  = "사용자 {0} 이(가) 등록되었습니다.".format(response["username"])
        else :
            response["isAdmin"] = userinfo.isAdmin()
            return HttpResponse(render(request, "admin_user_new.html", response ))
        
    context["isAdmin"]  = userinfo.isAdmin()
    return HttpResponse(render(request, "admin_user_new.html", context))
Example #14
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 #15
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 #16
0
def userNew(request, *args, **kwargs):
    context = {}
    userinfo = UserInfo.getUserInfo(request)

    if request.POST.get("signup"):
        response = userCreate(request.POST, userinfo.isAdmin())

        if response["code"] == 0:
            context["code"] = 0
            context["message"] = "사용자 {0} 이(가) 등록되었습니다.".format(
                response["username"])
        else:
            response["isAdmin"] = userinfo.isAdmin()
            return HttpResponse(
                render(request, "admin_user_new.html", response))

    context["isAdmin"] = userinfo.isAdmin()
    return HttpResponse(render(request, "admin_user_new.html", context))
Example #17
0
def resetAllAuthority(request, *args, **kwargs) :
    response = {
        "code"      : 0,
        "message"   : ""
    }
    
    if not UserInfo.getUserInfo(request).isAdmin() :
        response['code']    = -1
        response['message'] = "권한 초기화는 최고 관리자만 가능합니다"
    else :
        # DB 초기화    
        FileDescriptor.objects.all().delete()
        UserAuthority.objects.all().delete()
        FileDescriptor(file_id=0, file="", reference=None).save()  # 이건 더미
     
        index.dir_reset()
         
    return HttpResponse(json.dumps(response))
Example #18
0
def download(request, *args, **kwargs):
    """
    Download a file
    @param kwargs:    
        filepath    : Relative file path of target file. Root is user home.
    """
    
    target = kwargs['filepath']
    
    # Authority Check
    fileManager = CELLAR_FileManager(request)
    if target is None or not fileManager.isReadable(os.path.dirname(target)) :
        raise PermissionDenied
    
    fullPath = UserInfo.getUserInfo(request).getHomePath() + "/" + target
    response = StreamingHttpResponse(FileWrapper(open(fullPath, mode='rb')), content_type='application/octet-stream')
    response['Content-Length'] = os.path.getsize(fullPath)    
    response['Content-Disposition'] = 'attachment'
     
    return response
Example #19
0
def getDefaultAuthority(request, *args, **kwargs):
    path = request.POST.get("path")
    response = {
        "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() + path
    file_id = index.dir_get(fullpath)
    if file_id is not None :
        fileDescriptor = FileDescriptor.objects.get(file_id=file_id)
        response['register']    = True
        response['readable']    = fileDescriptor.readable
        response['writeable']   = fileDescriptor.writeable
        response['deletable']   = fileDescriptor.deletable
        response['inherit']     = fileDescriptor.inherit
        
    return HttpResponse(json.dumps(response))
Example #20
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 #21
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 #22
0
def userEdit(request, *args, **kwargs):
    user_group = { 'group' : [], 'user' : []}
    users = []
    if request.POST.get('user.group.update') :
        username    = request.POST.get('username')
        groupname   = request.POST.get('groupname')
        assign      = request.POST.get('assign') == 'True' or request.POST.get('assign') == 'true'
            
        if assign :
            user        = UserInfo.objects.get(username=username)
            group       = UserInfo.objects.get(username=groupname)
            userGroup   = UserGroups(user=user, group=group)
            userGroup.save()
        else :
            userGroup   = UserGroups.objects.get(user=username, group=groupname)
            userGroup.delete()
            
        if request.is_ajax() :
            return HttpResponse({"username" : username, "groupname" : groupname, "assign" : assign })
        else :
            users = UserInfo.objects.filter(username=username)
    else :
        search_term = request.POST.get("user.group.search.term")
        if not search_term or not request.POST.get('user.group.search') :
            search_term = ""
        users = UserInfo.objects.filter(username__contains=search_term).exclude(usertype=UserInfo.GROUP)
            
    general = 0
    groupIndex = {}
    groups = list(UserInfo.objects.filter(usertype=UserInfo.GROUP))
    for group in groups :
        auth_group = User.objects.get(username=group.username)
        groupIndex[group.username] = general
        general = general + 1
        user_group['group'].append([general, {'username'     : group.username,
                                            'first_name'   : auth_group.first_name,
                                            'last_name'    : auth_group.last_name }])
            
    for userinfo in users :
        auth_user = User.objects.get(username=userinfo.username)
        user = {'username'      : userinfo.username, 
                'first_name'    : auth_user.first_name, 
                'last_name'     : auth_user.last_name,
                'usertype'      : userinfo.usertype,
                'isAdmin'       : userinfo.isAdmin(), 
                'assign'        : [] }
        for group in groups :
            user['assign'].append([group.username, False])
            
        userGroups = UserGroups.objects.filter(user=userinfo.username)
        for userGroup in userGroups :
            user['assign'][groupIndex[userGroup.group.username]][1] = True
            
        user_group['user'].append(user)
      
    context = {
        'user_group'    : user_group,
        'config'        : vars(config),
        'isAdmin'       : UserInfo.getUserInfo(request).isAdmin()
    }
    return render(request, "admin_user_edit.html", context)     
Example #23
0
def etc(request, *args, **kwargs):
    context = {
        'config'        : vars(config),
        'isAdmin'       : UserInfo.getUserInfo(request).isAdmin()
    }
    return HttpResponse(render(request, "admin_etc.html", context))
Example #24
0
def userEdit(request, *args, **kwargs):
    user_group = {'group': [], 'user': []}
    users = []
    if request.POST.get('user.group.update'):
        username = request.POST.get('username')
        groupname = request.POST.get('groupname')
        assign = request.POST.get('assign') == 'True' or request.POST.get(
            'assign') == 'true'

        if assign:
            user = UserInfo.objects.get(username=username)
            group = UserInfo.objects.get(username=groupname)
            userGroup = UserGroups(user=user, group=group)
            userGroup.save()
        else:
            userGroup = UserGroups.objects.get(user=username, group=groupname)
            userGroup.delete()

        if request.is_ajax():
            return HttpResponse({
                "username": username,
                "groupname": groupname,
                "assign": assign
            })
        else:
            users = UserInfo.objects.filter(username=username)
    else:
        search_term = request.POST.get("user.group.search.term")
        if not search_term or not request.POST.get('user.group.search'):
            search_term = ""
        users = UserInfo.objects.filter(
            username__contains=search_term).exclude(usertype=UserInfo.GROUP)

    general = 0
    groupIndex = {}
    groups = list(UserInfo.objects.filter(usertype=UserInfo.GROUP))
    for group in groups:
        auth_group = User.objects.get(username=group.username)
        groupIndex[group.username] = general
        general = general + 1
        user_group['group'].append([
            general, {
                'username': group.username,
                'first_name': auth_group.first_name,
                'last_name': auth_group.last_name
            }
        ])

    for userinfo in users:
        auth_user = User.objects.get(username=userinfo.username)
        user = {
            'username': userinfo.username,
            'first_name': auth_user.first_name,
            'last_name': auth_user.last_name,
            'usertype': userinfo.usertype,
            'isAdmin': userinfo.isAdmin(),
            'assign': []
        }
        for group in groups:
            user['assign'].append([group.username, False])

        userGroups = UserGroups.objects.filter(user=userinfo.username)
        for userGroup in userGroups:
            user['assign'][groupIndex[userGroup.group.username]][1] = True

        user_group['user'].append(user)

    context = {
        'user_group': user_group,
        'config': vars(config),
        'isAdmin': UserInfo.getUserInfo(request).isAdmin()
    }
    return render(request, "admin_user_edit.html", context)
Example #25
0
def userUpdate(request, *args, **kwargs):
    response = {
        "code"      : "",
        "message"   : "" 
    }
     
    username        = request.POST.get("username")
    usertype        = request.POST.get("usertype")
    home            = None
    name            = request.POST.get("name")
    email           = request.POST.get("email")
    memo            = request.POST.get("memo")
    password_new    = request.POST.get("password_new")
    password_old    = request.POST.get("password_old")
    if request.POST.__contains__("home") :
        home = request.POST.get("home")
     
    if usertype : usertype = int(usertype) 
     
    # 권한 확인 - 공통
    user        = User.objects.get(username = username)
    userinfo    = UserInfo.objects.get(username = username)
    sessionInfo = UserInfo.getUserInfo(request)
    if not sessionInfo.isAdmin() and sessionInfo.username != username :
        response["code"]    = -4
        response["message"] = "권한이 없습니다."
        return HttpResponse(json.dumps(response))
     
    # 권한 확인 - 관리자
    if not sessionInfo.isAdmin() and ( home is not None or usertype ) :
        response["code"]    = -5
        response["message"] = "관리자만이 변경 가능한 항목을 포함하고 있습니다."
        return HttpResponse(json.dumps(response))
     
    # 시스템 관리자는 계정 유형 변경 불가
    if user.is_superuser and usertype and usertype != UserInfo.SUPER :
        response["code"]    = -6
        response["message"] = "시스템 관리자의 계정 유형을 변경할 수 없습니다."
        return HttpResponse(json.dumps(response))
     
    # 암호 변경 요청 시 사용자 암호 확인
    if password_new :
        if sessionInfo.isAdmin() and not password_old :
            pass
        elif authenticate(username = username, password = password_old) :
            pass
        else :
            response["code"]    = -3
            response["message"] = "입력한 기존 암호가 잘못되었습니다."
            return HttpResponse(json.dumps(response))
     
    try :
        with transaction.atomic() :
            # 사용자 정보 갱신
            if email :
                user.email = email
            if name :
                user.first_name = name
            if password_new :
                user.set_password(password_new)
            user.save()
             
            if home is not None :
                userinfo.home = home
            if usertype :
                userinfo.usertype = usertype
            if memo :
                userinfo.memo = memo
            userinfo.save()
             
            response['code']    = 0
            response['message'] = "사용자 정보가 변경되었습니다."
             
            response['username']    = username
            response['name']        = user.first_name
            response['email']       = user.email
            response['home']        = userinfo.home
            response['memo']        = userinfo.memo
            response['usertype']    = userinfo.usertype
              
    except Exception as err :
        response['code'] = -2
        response['message'] = err.__str__()
     
    return HttpResponse(json.dumps(response))
Example #26
0
 def __init__(self, request):
     self.userinfo = UserInfo.getUserInfo(request)
     FileManager.__init__(self, self.userinfo.getHomePath())
Example #27
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))
Example #28
0
def userCreate(params, isAdmin = False) :
    response = {
        "code"  : 0,
    }
              
    is_group    = params.get('is_group')
    username    = params.get('username')
    password    = params.get("password")
    email       = params.get("email")
    first_name  = params.get("first_name")
    memo        = params.get("memo")
          
    # 최고 관리자에 의해 등록되는 ID 는 E-MAIL 은 필요 없음
    if not email and isAdmin :
        email = "" 
            
    if is_group and not isAdmin :
        response["code"]    = -2
        response["message"] = "그룹 사용자는 관리자만이 추가할 수 있습니다."
    elif not re.match("[a-zA-Z0-9_]{6,}|@[a-zA-Z0-9_]{5,}", username) :
        response["code"]    = -3
        response["message"] = "ID 는 6글자 이상의 영숫자와 '_' 로 작성해주세요."
    elif is_group and not re.match("@.*", username) :
        response["code"]    = -4
        response["message"] = "그룹 사용자의 아이디는 @로 시작해야합니다."
    elif username and password and first_name and ( email or isAdmin ) :
        try :
            usertype = UserInfo.NORMAL
            if is_group :
                usertype = UserInfo.GROUP
                     
            user        = User.objects.create_user(username, email, password, first_name=first_name)
            userinfo    = UserInfo(username=username, usertype=usertype, memo=memo)
            userinfo.save()
              
            response["code"]    = 0
            response["message"] = "사용자가 등록되었습니다."
            response["user"]    = user
            
            ok("user.create : " + username)
        except Exception as err :
            error("user.create : " + err.__str__())
            response["code"]    = 1
            response['message'] = "이미 존재하는 아이디 입니다."
    else :
        response["code"]    = -1
        response["message"] = "필수 항목을 모두 입력하여 주십시오."
        
    if isAdmin and is_group :
        response["is_group"] = is_group
        
    if username :
        response["username"] = username
            
    if email :
        response["email"] = email
        
    if first_name :
        response["first_name"] = first_name
        
    if memo :
        response["memo"] = memo
        
    return response  
Example #29
0
 def __init__(self, request):
     self.userinfo = UserInfo.getUserInfo(request)
     FileManager.__init__(self, self.userinfo.getHomePath())
Example #30
0
def etc(request, *args, **kwargs):
    context = {
        'config': vars(config),
        'isAdmin': UserInfo.getUserInfo(request).isAdmin()
    }
    return HttpResponse(render(request, "admin_etc.html", context))