# (c) cavaliba.com - data - permissions.py



#  -------
# aaa
#  -------
def aaa_perms_valid(aaa):
    try:
        if type(aaa["perms"]) is not list:
            return False
    except:
        return False
    return True



#  -------
# SCHEMA
#  -------
def has_schema_read_permission(aaa=None):
    ''' permission to read all schemas definitions and fields'''

    if not aaa_perms_valid(aaa):
        return False
    
    if 'p_schema_read' in aaa['perms']:
        return True
    if 'p_schema_write' in aaa['perms']:
        return True    
    return False

def has_schema_write_permission(aaa=None):

    if not aaa_perms_valid(aaa):
        return False
        
    ''' permission to write all schemas definitions and fields'''
    if 'p_schema_write' in aaa['perms']:
        return True    
    return False







#  ----
# IAM
#  ----
def has_iam_export_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_iam_export' in aaa['perms']:
        return True
    return False

# user read
def has_user_read_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_user_read' in aaa['perms']:
        return True
    return False
# user create
def has_user_create_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_user_create' in aaa['perms']:
        return True
    return False
# user update
def has_user_update_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_user_update' in aaa['perms']:
        return True
    return False
# user delete
def has_user_delete_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_user_delete' in aaa['perms']:
        return True
    return False

# group read
def has_group_read_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_group_read' in aaa['perms']:
        return True
    return False

# group create
def has_group_create_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_group_create' in aaa['perms']:
        return True
    return False

# group update
def has_group_update_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_group_update' in aaa['perms']:
        return True
    return False

# group delete
def has_group_delete_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_group_delete' in aaa['perms']:
        return True
    return False

# role read
def has_role_read_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_role_read' in aaa['perms']:
        return True
    return False
# role create
def has_role_create_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_role_create' in aaa['perms']:
        return True
    return False
# role update
def has_role_update_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_role_update' in aaa['perms']:
        return True
    return False
# role delete
def has_role_delete_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_role_delete' in aaa['perms']:
        return True
    return False


# permission read
def has_permission_read_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_permission_read' in aaa['perms']:
        return True
    return False
# permission create
def has_permission_create_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_permission_create' in aaa['perms']:
        return True
    return False
# permission update
def has_permission_update_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_permission_update' in aaa['perms']:
        return True
    return False
# permission delete
def has_permission_delete_permission(aaa=None):
    if not aaa_perms_valid(aaa):
        return False
    if 'p_permission_delete' in aaa['perms']:
        return True
    return False
