예제 #1
0
def populate_user_roles(drop):
    """
    Populate default set of user roles into the system.

    :param drop: Drop the existing collection before trying to populate.
    :type: boolean
    """

    # define your user roles here
    # note: you MUST have Administrator, Read Only, and a third option
    # available!
    user_roles = ['Administrator', 'Analyst', 'Read Only']
    if drop:
        UserRole.drop_collection()
    if len(UserRole.objects()) < 1:
        for role in user_roles:
            ur = UserRole()
            ur.name = role
            ur.save()
        print "User Roles: added %s roles!" % len(user_roles)
    else:
        print "User Roles: existing documents detected. skipping!"
예제 #2
0
def populate_user_roles(drop):
    """
    Populate default set of user roles into the system.

    :param drop: Drop the existing collection before trying to populate.
    :type: boolean
    """

    # define your user roles here
    # note: you MUST have Administrator, Read Only, and a third option
    # available!
    user_roles = ['Administrator', 'Analyst', 'Read Only']
    if drop:
        UserRole.drop_collection()
    if len(UserRole.objects()) < 1:
        for role in user_roles:
            ur = UserRole()
            ur.name = role
            ur.save()
        print "User Roles: added %s roles!" % len(user_roles)
    else:
        print "User Roles: existing documents detected. skipping!"
예제 #3
0
def add_new_user_role(name, analyst):
    """
    Add a new user role to the system.

    :param name: The name of the role.
    :type name: str
    :param analyst: The user adding the role.
    :type analyst: str
    :returns: True, False
    """

    from crits.core.user_role import UserRole
    name = name.strip()
    role = UserRole.objects(name=name).first()
    if not role:
        role = UserRole()
        role.name = name
        try:
            role.save(username=analyst)
            return True
        except ValidationError:
            return False
    else:
        return False
예제 #4
0
파일: user_tools.py 프로젝트: 0x3a/crits
def add_new_user_role(name, analyst):
    """
    Add a new user role to the system.

    :param name: The name of the role.
    :type name: str
    :param analyst: The user adding the role.
    :type analyst: str
    :returns: True, False
    """

    from crits.core.user_role import UserRole
    name = name.strip()
    role = UserRole.objects(name=name).first()
    if not role:
        role = UserRole()
        role.name = name
        try:
            role.save(username=analyst)
            return True
        except ValidationError:
            return False
    else:
        return False