"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccessRightsProvider = void 0;
const lodash_1 = require("lodash");
const extension_description_1 = require("../../integration/extension-description");
const extension_provider_1 = require("./../../integration/extension.provider");
const access_rights_interceptor_1 = require("./../../interceptors/access-rights.interceptor");
const application_service_1 = require("./../application.service");
const content_entity_provider_1 = require("./../content-entity/content-entity.provider");
const uri_complete_provider_1 = require("./../uri-complete/uri-complete.provider");
const access_rights_node_service_1 = require("./access-rights-node.service");
const access_rights_tree_service_1 = require("./access-rights-tree.service");
const access_rights_type_service_1 = require("./access-rights-type.service");
const access_rights_user_service_1 = require("./access-rights-user.service");
const access_rights_const_1 = require("./access-rights.const");
const access_rights_service_1 = require("./access-rights.service");
class AccessRightsProvider extends extension_provider_1.ExtensionProvider {
    constructor(app) {
        super(access_rights_const_1.ACCESS_RIGHT_PROVIDER, app);
        this.app = app;
        this.requiredProviders.push(uri_complete_provider_1.UriCompleteProvider, content_entity_provider_1.ContentEntityCoreProvider);
        this.services.push({ cls: access_rights_service_1.AccessRightsService });
        this.services.push({ cls: access_rights_tree_service_1.AccessRightsTreeService });
        this.services.push({ cls: access_rights_node_service_1.AccessRightsNodeService });
        this.services.push({ cls: access_rights_type_service_1.AccessRightsTypeService });
        this.services.push({ cls: access_rights_user_service_1.AccessRightsUserService });
        this.interceptorsPrepend.push({
            id: 'AccessRightsInterceptor',
            interceptor: access_rights_interceptor_1.AccessRightsInterceptor,
            description: {
                preTreatment: new extension_description_1.RunnerTreatmentDescription('Check access rights on target entity(ies)', ['AccessRightsService']),
                postTreatment: new extension_description_1.RunnerTreatmentDescription('Remove forbidden entities', ['AccessRightsService']),
            },
        });
        this.objectTypes.push({
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            contentType: application_service_1.ApplicationService.CONTENT_TYPE.USER,
            iconView: 'far fa-id-card',
        }, {
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER,
            iconView: 'fas fa-mask',
        }, access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE, access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE, access_rights_const_1.ACCESS_RIGHTS_OWNERS_TYPE, access_rights_const_1.ACCESS_RIGHTS_ACCESS_MANAGERS_TYPE);
        this.objectSubTypes.push(lodash_1.merge({
            typeName: () => this.appCtx.repositoryType.value.name,
            subTypeName: () => access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
        }, access_rights_const_1.ACCESS_RIGHT_SUBTYPE), {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
            subTypeName: () => access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ACCESS_RIGHT_GROUP,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name,
            subTypeName: () => application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name,
            subTypeName: () => application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
            max: 1,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
            subTypeName: () => access_rights_const_1.ACCESS_RIGHTS_OWNERS_TYPE.name,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ACCESS_RIGHT_OWNERS,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
            max: 1,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_OWNERS_TYPE.name,
            subTypeName: () => application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
            subTypeName: () => access_rights_const_1.ACCESS_RIGHTS_ACCESS_MANAGERS_TYPE.name,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ACCESS_RIGHT_ACCESS_MANAGERS,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
            max: 1,
        }, {
            typeName: () => access_rights_const_1.ACCESS_RIGHTS_ACCESS_MANAGERS_TYPE.name,
            subTypeName: () => application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            name: application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER,
            acl: false,
            namespace: false,
            owner: false,
            tree: false,
        }, lodash_1.merge({
            typeName: () => this.appCtx.folderType.value.name,
            subTypeName: () => access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
        }, access_rights_const_1.ACCESS_RIGHT_SUBTYPE));
        this.objectTrees = {
            rootACL: {
                parentNode: () => this.appCtx.rootNode.value,
                treeNodeTypeId: access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
                treeNodeName: application_service_1.ApplicationService.OBJECT_NODE_NAMES.AccessRightsDefinition,
                tree: {
                    treeNode: {},
                    children: {
                        [access_rights_const_1.ACCESS_RIGHTS_OWNERS_TYPE.name]: {
                            [access_rights_const_1.ACCESS_RIGHT_OWNERS_NODE.name]: [
                                {
                                    treeNode: lodash_1.omit(access_rights_const_1.ACCESS_RIGHT_OWNERS_NODE, [
                                        'name',
                                        'objectTypeId',
                                    ]),
                                    children: {
                                        [application_service_1.ApplicationService.OBJECT_TYPE_NAMES.USER]: {
                                            JacquesLebourgeois: [
                                                {
                                                    treeNode: {
                                                        contentUser: 'jacques.lebourgeois@gmail.com',
                                                    },
                                                    children: {},
                                                },
                                            ],
                                        },
                                    },
                                },
                            ],
                        },
                    },
                },
            },
            publicACL: {
                parentNode: () => this.appCtx.publicNode.value,
                treeNodeTypeId: access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
                treeNodeName: application_service_1.ApplicationService.OBJECT_NODE_NAMES.AccessRightsDefinition,
                tree: {
                    treeNode: {},
                    children: {
                        [access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name]: {
                            ['PublicAccess']: [
                                {
                                    treeNode: {
                                        grantRead: true,
                                        grantUpdate: false,
                                        grantDelete: false,
                                        grantCreate: false,
                                    },
                                    children: {
                                        [application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER]: {
                                            Anonymous: [
                                                {
                                                    treeNode: {},
                                                    children: {},
                                                },
                                            ],
                                        },
                                    },
                                },
                            ],
                        },
                    },
                },
            },
            demonstrationAccountACL: {
                parentNode: () => this.appCtx.demonstrationAccountNode.value,
                treeNodeTypeId: access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
                treeNodeName: application_service_1.ApplicationService.OBJECT_NODE_NAMES.AccessRightsDefinition,
                tree: {
                    treeNode: {},
                    children: {
                        [access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name]: {
                            ['DemonstrationAccess']: [
                                {
                                    treeNode: {
                                        grantRead: true,
                                        grantUpdate: false,
                                        grantDelete: false,
                                        grantCreate: false,
                                    },
                                    children: {
                                        [application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER]: {
                                            Anonymous: [
                                                {
                                                    treeNode: {},
                                                    children: {},
                                                },
                                            ],
                                        },
                                    },
                                },
                            ],
                        },
                    },
                },
            },
            demonstrationSandboxACL: {
                parentNode: () => this.appCtx.demonstrationSandboxNode.value,
                treeNodeTypeId: access_rights_const_1.ACCESS_RIGHTS_DEFINITION_TYPE.name,
                treeNodeName: application_service_1.ApplicationService.OBJECT_NODE_NAMES.AccessRightsDefinition,
                tree: {
                    treeNode: {},
                    children: {
                        [access_rights_const_1.ACCESS_RIGHTS_GROUP_TYPE.name]: {
                            ['SandboxAccess']: [
                                {
                                    treeNode: {
                                        grantRead: true,
                                        grantUpdate: true,
                                        grantDelete: true,
                                        grantCreate: true,
                                    },
                                    children: {
                                        [application_service_1.ApplicationService.OBJECT_TYPE_NAMES.ANONYMOUS_USER]: {
                                            Anonymous: [
                                                {
                                                    treeNode: {},
                                                    children: {},
                                                },
                                            ],
                                        },
                                    },
                                },
                            ],
                        },
                    },
                },
            },
        };
    }
}
exports.AccessRightsProvider = AccessRightsProvider;
//# sourceMappingURL=access-rights.provider.js.map