enonic / xp

Enonic XP
https://enonic.com
GNU General Public License v3.0
202 stars 34 forks source link

lib-common.sanitize gives java.lang.ClassNotFoundException: com.enonic.xp.name.NamePrettyfier #6823

Closed ComLock closed 4 years ago

ComLock commented 5 years ago

gradle.properties

xpVersion=6.14.0

build.gradle

compile "com.enonic.xp:core-api:${xpVersion}"
compile "com.enonic.xp:portal-api:${xpVersion}"
include "com.enonic.xp:lib-auth:${xpVersion}"
include "com.enonic.xp:lib-common:${xpVersion}"

main.es

import {createRole} from '/lib/xp/auth';
import {sanitize} from '/lib/xp/common';
import {run} from '/lib/xp/context';

function runAsSu(fn, {
    branch = 'master',
    repository = 'system-repo'
} = {}) {
    return run({
        branch,
        repository,
        user: {
            login: 'su',
            userStore: 'system'
        },
        principals: ['role:system.admin']
    }, () => fn());
}

function ignoreErrors(fn) {
    let rv;
    try {
        rv = fn();
    } catch (e) {
        // no-op
    }
    return rv;
}

runAsSu(() => {
    ignoreErrors(() => {
        createRole({
            name: sanitize(`${app.name}.admin`),
            displayName: 'Phrases Administrator',
            description: 'This role gives permissions to the Phrases Admin application.'
        });
    });
});
ComLock commented 5 years ago

Adding lib-portal to dependencies "fixes" this.