<commit_before>package whelk.plugin.libris.security
import groovy.util.logging.Slf4j as Log

import whelk.Document
import whelk.plugin.BasicPlugin

@Log
class AccessControl extends BasicPlugin {

    boolean checkDocument(Document newdoc, Document olddoc, Map userPrivileges) {
        if (newdoc?.dataset == "hold") {
            def sigel = newdoc.dataAsMap.about.heldBy.notation
            log.debug("User tries to change a holding for sigel ${sigel}.")

            def privs = userPrivileges.authorization.find { it.sigel == sigel }
            log.trace("User has these privs for ${sigel}: $privs")
            if (!privs?.reg && !privs?.kat) {
                log.debug("User does not have sufficient privileges.")
                return false
            }

            def currentSigel =olddoc?.dataAsMap?.about?.heldBy?.notation
            if (currentSigel) {
                log.trace("Checking sigel privs for existing document.")
                privs = userPrivileges.authorization.find { it.sigel == currentSigel }
                log.trace("User has these privs for current sigel ${sigel}: $privs")
                if (!privs?.reg && !privs?.kat) {
                    log.debug("User does NOT have enough privileges.")
                    return false
                }
            }
        }

        if (newdoc) {
            docnew.entry.lastChangeBy = userPrivileges.username
        }
        log.debug("User is authorized to make the change.")
        return true
    }
}<commit_msg>Fixed tiny bug<commit_after>package whelk.plugin.libris.security
import groovy.util.logging.Slf4j as Log

import whelk.Document
import whelk.plugin.BasicPlugin

@Log
class AccessControl extends BasicPlugin {

    boolean checkDocument(Document newdoc, Document olddoc, Map userPrivileges) {
        if (newdoc?.dataset == "hold") {
            def sigel = newdoc.dataAsMap.about.heldBy.notation
            log.debug("User tries to change a holding for sigel ${sigel}.")

            def privs = userPrivileges.authorization.find { it.sigel == sigel }
            log.trace("User has these privs for ${sigel}: $privs")
            if (!privs?.reg && !privs?.kat) {
                log.debug("User does not have sufficient privileges.")
                return false
            }

            def currentSigel = olddoc?.dataAsMap?.about?.heldBy?.notation
            if (currentSigel) {
                log.trace("Checking sigel privs for existing document.")
                privs = userPrivileges.authorization.find { it.sigel == currentSigel }
                log.trace("User has these privs for current sigel ${sigel}: $privs")
                if (!privs?.reg && !privs?.kat) {
                    log.debug("User does NOT have enough privileges.")
                    return false
                }
            }
        }

        if (newdoc) {
            newdoc.entry.lastChangeBy = userPrivileges.username
        }
        log.debug("User is authorized to make the change.")
        return true
    }
}
{'fraction_non_alphanumeric': 0.09933774834437085, 'fraction_numerical': 0.0006622516556291391, 'mean_word_length': 1.9444444444444444, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1115585', 'n_tokens_mistral': 841, 'n_tokens_neox': 801, 'n_words': 218}