예제 #1
0
def searchForNewPSafeFilesByRepoName(username, password, repoByName, sync, **kw):
    """ Search the given repos for NEW psafes. Will not reload existing safes.
    @param repoByName: A list of repo names to check for new safes
    @type repoByName: array of strings
    @return: True on success, false otherwise
    @raise NoPermissionError: User lacks password sync perms
    @raise EntryDoesntExistError: One of the repo PKs doesn't exist or the user lacks at least read-only perms to the safe. 
    """
    repos = []
    for repoName in repoByName:
        # Make sure it exists and the user has access
        try:
            repo = PasswordSafeRepo.objects.get(pk = repoName)
        except PasswordSafeRepo.DoesNotExist:
            raise EntryDoesntExistError, "Couldn't find a PasswordSafeRepo where name=%r" % repoName
        if not repo.user_can_access(user = kw['user'], mode = "R"):
            raise EntryDoesntExistError, "Couldn't find a PasswordSafeRepo where name=%r" % repoName
    if kw['user'].has_perm('psafe.can_sync_passwordsafe'):
        res = findSafes.delay()  # @UndefinedVariable
        try:
            if sync:
                safesFound = res.wait()
        except:
            # TODO: Add some sort of logging for this
            return False
        return True
    raise NoPermissionError, "User can't sync psafes"
예제 #2
0
def searchForNewPSafeFiles(username, password, sync, **kw):
    """ Search all repos for NEW psafes. Will not reload existing safes.
    
    @return: True on success, false otherwise
    @raise NoPermissionError: User lacks password sync perms 
    """
    if kw['user'].has_perm('psafe.can_sync_passwordsafe'):
        # Limit to repos the user has at least read-only access to
        # Only do if the user has sync perms as this may take a while 
        repos = []
        for repo in PasswordSafeRepo.objects.all():
            if repo.user_can_access(user = kw['user'], mode = "R"):
                repos.append(repo.pk)
        res = findSafes.delay(repoByPK = repos)  # @UndefinedVariable
        try:
            if sync:
                safesFound = res.wait()
        except:
            # TODO: Add some sort of logging for this
            return False
        return True
    raise NoPermissionError, "User can't sync psafes"