Example #1
0
def id_perm_changes(s, handle, fd, permdata, set):
    removelist = []
    changelist = []
    addlist = []
       
    if not check_fd_sel(fd, set) or not check_perm_sel(permdata, set):
        return([removelist,changelist,addlist])
    
    for perm_act in set['PermAct']:
        # pass if no action is defined
        if not perm_act['Action']:
            pass
        elif perm_act['Action']['Action'] == 'Remove':
            for perm in permdata['perms']:
                if Match.parse(perm_act['Criteria'], perm):
                    removelist.append(perm)
        elif perm_act['Action']['Action'] == 'Change':
            for perm in permdata['perms']:
                if Match.parse(perm_act['Criteria'], perm):
                    # delete the old permission
                    newperm = perm.copy()
                    if 'Read' in perm: del(newperm['Read'])
                    if 'Write'in perm: del(newperm['Write'])
                    if 'Manage' in perm: del(newperm['Manage'])
                    for key,val in perm_act['Action']['Perms'].items():
                        newperm[key] = val
                    changelist.append(newperm)  
        elif perm_act['Action']['Action'] == 'Add':
            addFlag = True
            for perm in permdata['perms']:
                if not Match.parse(perm_act['Criteria'], perm):
                    addFlag = False
            if addFlag:
                pEntry = {}
                pEntry['handle'] = perm_act['Action']['Handle']
                grpdata = DCC.prop_get(s, pEntry['handle'], InfoSet = 'Title')
                pEntry['name'] = grpdata['title']
                if 'Read' in perm_act['Action']['Perms']:
                    pEntry['Read'] = perm_act['Action']['Perms']['Read']
                if 'Write' in perm_act['Action']['Perms']:
                    pEntry['Write'] = perm_act['Action']['Perms']['Write']
                if 'Manage' in perm_act['Action']['Perms']:
                    pEntry['Manage'] = perm_act['Action']['Perms']['Manage']
                addlist.append(pEntry) 
                
        elif perm_act['Action']['Action'] == 'Message':
            for perm in permdata['perms']:
                if Match.parse(perm_act['Criteria'], perm):
                    print(perm_act['Action']['Message'])
                    DCC.print_perm(perm, LF = True)
        
    return([removelist, changelist, addlist])
Example #2
0
def check_fd_sel(fd, set):
    try:
        obj_sel = set['ObjSel']['Criteria']
        if Match.parse(obj_sel, fd):
            return(True)
        return(False)
    except:
        if debug: print('ObjSel is not defined')
        return(True)
Example #3
0
def fix_objact(s, fd, handle, set, **kwargs):
    ask_flag = kwargs.get('Ask',True)
    
    if not check_fd_sel(fd, set):
        return
        
    for obj_act in set['ObjAct']:
        if not obj_act['Action']:
            pass

        if Match.parse(obj_act['Criteria'], fd):
            if obj_act['Action']['Action'] == 'SetOwner':
                nu = DCC.prop_get(s, obj_act['Action']['Owner'], InfoSet = 'User')
                print('??? Change Owner from [', fd['owner-userid'], ',', fd['owner-username'], '] to [', 
                                        nu['owner-userid'], ',', nu['owner-username'], ']', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.change_owner(s, handle, obj_act['Action']['Owner'])
                    
            elif obj_act['Action']['Action'] == 'AddKeyword':
                print('??? Add Keyword "', obj_act['Action']['Keyword'], '" to "', fd['keywords'].strip(), '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    kw = obj_act['Action']['Keyword'] + fd['keywords'].strip(' ')
                    DCC.set_metadata(s, handle, Keywords = kw)

            elif obj_act['Action']['Action'] == 'DelKeyword':
                print('??? Remove Keyword "', obj_act['Action']['Keyword'], '" from "', fd['keywords'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    kw = fd['keywords'].strip(' ').replace(obj_act['Action']['Keyword'], '')
                    DCC.set_metadata(s, handle, Keywords = kw)
                
            elif obj_act['Action']['Action'] == 'RepTitle':
                print('??? Change Title to "', obj_act['Action']['Title'], '" from "', fd['title'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.set_metadata(s, handle, Title = obj_act['Action']['Title'])

            elif obj_act['Action']['Action'] == 'RepTmtNum':
                print('??? Change TmtNum to "', obj_act['Action']['TmtNum'], '" from "', fd['tmtnum'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.set_metadata(s, handle, Summary = obj_act['Action']['TmtNum'])
                pass
                
            elif obj_act['Action']['Action'] == 'Message':
                print(obj_act['Action']['Message'])
                
            else:
                print('Error in PERM.fix_objact: ObjAct Action not recognized:', obj_act['Action']['Action'])
Example #4
0
def check_perm_sel(permdata, set):
    # PermSel Criteria is a list of checks against permissions.  If the complete list passes
    # then the PermAct actions will be undertaken.
    try:
        perm_sels = set['PermSel']['Criteria']
        for perm_sel in perm_sels:
            if debug: print('check_perm_sel:',perm_sel)
            for perm in permdata['perms']:
                match_flag = False
                if Match.parse(perm_sel, perm):
                    match_flag = True
                    break
            if match_flag == False:
                if debug: print('check_perm_sel: returning False')
                return(False)
        if debug: print('check_perm_sel: returning True')
        return(True)
    except:
        if debug: print('PermSel is not defined')
        return(True)