<commit_before>from rules import add_perm, is_authenticated, predicate


@predicate
def is_creator(user, association):
    return association.container.versions.first().author == user.gestalt


add_perm('associations.delete', is_authenticated & is_creator)<commit_msg>Allow deleting any group content if membership is older than one week, refs #641<commit_after>from datetime import date, timedelta
from rules import add_perm, is_authenticated, predicate

from grouprise.features.memberships.models import Membership


@predicate
def is_creator(user, association):
    return association.container.versions.first().author == user.gestalt


@predicate
def is_long_standing_group_member(user, association):
    if not association.entity.is_group:
        return False
    membership = Membership.objects.filter(group=association.entity, member=user.gestalt) \
                                   .first()
    if not membership:
        return False
    return membership.date_joined < date.today() - timedelta(weeks=1)


add_perm('associations.delete', is_authenticated \
                                & (is_creator | is_long_standing_group_member))
{'fraction_non_alphanumeric': 0.08188153310104529, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 3.9740259740259742, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6331887', 'n_tokens_mistral': 328, 'n_tokens_neox': 305, 'n_words': 76}