dimanche 26 juillet 2020

Django rules re-using predicate

I've created 2 predicate's, which are extremely similar in nature. One consumes a list and the other a static string.

@rules.predicate
def can_edit_items(user, fields):
    for perm in user.groups.all()
        if perm.name not in settings.fields[fields]
            return False
    return True

@rules.predicate
def can_edit_specific_item(user, field):
    for perm in user.groups.all()
        if perm.name not in settings.fields[field]
            return False
    return True

My requirements are that can_edit_specific_item() must make use of can_edit_items() by passing in a single string field_1

I've tried creating the following variation but it doesn't seem to work as I intend it to

@rules.predicate
def can_edit_specific_item(user, field):
    for perm in user.groups.all()
        if perm.name not in can_edit_items[field]
            return False
    return True



Aucun commentaire:

Enregistrer un commentaire