superdesk/superdesk-client-core

View on GitHub
scripts/api/user.ts

Summary

Maintainability
A
0 mins
Test Coverage
import ng from 'core/services/ng';

function hasPrivilege(privilege: string): boolean {
    const privileges = ng.get('privileges');

    return privileges.userHasPrivileges({[privilege]: 1});
}

function getCurrentUserId(): string {
    const session = ng.get('session');

    return session?.identity?._id;
}

function isLoggedIn() {
    const session = ng.get('session');

    return session?.identity?._id != null;
}

export const user = {
    hasPrivilege,
    isLoggedIn,
    getCurrentUserId,
};