(privs_to_ensure_for_grantee, dry_run=False, verbose=False, roles_by_slug=None)
Adds a parameterless grant between grantee and priv, looked up by slug.
    :param privs_to_ensure_for_grantee: An iterable of tuples: `(grantee_slug, [priv_slugs])`
    :param dry_run: if True, will not make any changes to the DB
    :param verbose: if True, will log additional output
    :param roles_by_slug: can specify your own roles to consider, otherwise will fetch all Role objects
Adds a parameterless grant between grantee and priv, looked up by slug.
    :param privs_to_ensure_for_grantee: An iterable of tuples: `(grantee_slug, [priv_slugs])`
    :param dry_run: if True, will not make any changes to the DB
    :param verbose: if True, will log additional output
    :param roles_by_slug: can specify your own roles to consider, otherwise will fetch all Role objects
Adds a parameterless grant between grantee and priv looked up by slug . : param privs_to_ensure_for_grantee : An iterable of tuples : ( grantee_slug [ priv_slugs ] ) : param dry_run : if True will not make any changes to the DB : param verbose : if True will log additional output : param roles_by_slug : can specify your own roles to consider otherwise will fetch all Role objects
def ensure_grants(privs_to_ensure_for_grantee, dry_run=False, verbose=False, roles_by_slug=None):
    """
    Adds a parameterless grant between grantee and priv, looked up by slug.
    :param privs_to_ensure_for_grantee: An iterable of tuples: `(grantee_slug, [priv_slugs])`
    :param dry_run: if True, will not make any changes to the DB
    :param verbose: if True, will log additional output
    :param roles_by_slug: can specify your own roles to consider, otherwise will fetch all Role objects
    """
    dry_run_tag = "[DRY RUN] " if dry_run else ""
    roles_by_slug = roles_by_slug or get_all_roles_by_slug()
    granted_privs_for_grantee = get_granted_privs_for_grantee()

    grants_to_create = []
    for grantee_slug, priv_slugs in privs_to_ensure_for_grantee:
        if grantee_slug not in roles_by_slug:
            logger.info('grantee %s does not exist.', grantee_slug)
            continue

        for priv_slug in priv_slugs:
            if priv_slug not in roles_by_slug:
                logger.info('privilege %s does not exist.', priv_slug)
                continue

            if priv_slug in granted_privs_for_grantee[grantee_slug]:
                if verbose or dry_run:
                    logger.info('%sPrivilege already granted: %s => %s',
                        dry_run_tag, grantee_slug, priv_slug)
            else:
                granted_privs_for_grantee[grantee_slug].add(priv_slug)
                if verbose or dry_run:
                    logger.info('%sGranting privilege: %s => %s',
                        dry_run_tag, grantee_slug, priv_slug)
                if not dry_run:
                    grants_to_create.append(Grant(
                        from_role=roles_by_slug[grantee_slug],
                        to_role=roles_by_slug[priv_slug]
                    ))
    if grants_to_create:
        Role.get_cache().clear()
        Grant.objects.bulk_create(grants_to_create)
def ensure_grants ( privs_to_ensure_for_grantee , dry_run = False , verbose = False , roles_by_slug = None ) : dry_run_tag = "[DRY RUN] " if dry_run else "" roles_by_slug = roles_by_slug or get_all_roles_by_slug ( ) granted_privs_for_grantee = get_granted_privs_for_grantee ( ) grants_to_create = [ ] for grantee_slug , priv_slugs in privs_to_ensure_for_grantee : if grantee_slug not in roles_by_slug : logger . info ( 'grantee %s does not exist.' , grantee_slug ) continue for priv_slug in priv_slugs : if priv_slug not in roles_by_slug : logger . info ( 'privilege %s does not exist.' , priv_slug ) continue if priv_slug in granted_privs_for_grantee [ grantee_slug ] : if verbose or dry_run : logger . info ( '%sPrivilege already granted: %s => %s' , dry_run_tag , grantee_slug , priv_slug ) else : granted_privs_for_grantee [ grantee_slug ] . add ( priv_slug ) if verbose or dry_run : logger . info ( '%sGranting privilege: %s => %s' , dry_run_tag , grantee_slug , priv_slug ) if not dry_run : grants_to_create . append ( Grant ( from_role = roles_by_slug [ grantee_slug ] , to_role = roles_by_slug [ priv_slug ] ) ) if grants_to_create : Role . get_cache ( ) . clear ( ) Grant . objects . bulk_create ( grants_to_create )