Skip to content

Commit

Permalink
feat(config): vod/live-channels default entries list/creation-view on…
Browse files Browse the repository at this point in the history
… build

* feat(config) vod entries list + creation view default config on build

* feat(config) live-Channels entries list + creation view default config on build
  • Loading branch information
mezzLMC authored Dec 23, 2023
1 parent f6deac1 commit 6dfd324
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 112 deletions.
120 changes: 8 additions & 112 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,14 @@
const readOnlyPermissions = [
{
action: 'plugin::content-manager.explorer.read',
subject: 'plugin::users-permissions.user',
conditions: [],
properties: {
fields: [
'username',
'email',
'provider',
'password',
'resetPasswordToken',
'confirmationToken',
'confirmed',
'blocked',
'role',
],
},
},
{
action: 'plugin::content-manager.explorer.read',
subject: 'api::category.category',
conditions: [],
properties: {
fields: ['Name', 'genre'],
},
},
{
action: 'plugin::content-manager.explorer.read',
subject: 'api::genre.genre',
conditions: [],
properties: {
fields: ['Name', 'categories'],
},
},
{
action: 'plugin::content-manager.explorer.read',
subject: 'api::live-channel.live-channel',
conditions: [],
properties: {
fields: [
'name',
'input_type',
'output_type',
'thumbnail',
'Live_to_vod',
'catch_up',
'genre',
'category',
'genre-category-relation',
'vods',
],
},
},
{
action: 'plugin::content-manager.explorer.read',
subject: 'api::vod.vod',
conditions: [],
properties: {
fields: [
'Name',
'Thumbnails',
'rotation_start',
'rotation_end',
'description',
'live_channel',
'genre-category-relation',
'views',
'genre',
'category',
'media_url',
'highlighted',
],
},
},
]

const createReadOnlyRole = async () => {
const roleService = strapi.services["admin::role"];
const data = await strapi.entityService.create('admin::role', {
data: {
name: 'Read-Only',
code: `read-only`,
description: 'Read only access for demo user',
},
});
await roleService.assignPermissions(data.id, readOnlyPermissions);
}

const createReadOnlyRoleIfNotExists = async () => {
const data: any[] = await strapi.entityService.findMany("admin::role", {
filters: { code: {$eq: "read-only"}}
})
if (data.length == 0)
await createReadOnlyRole();
};

import { createReadOnlyRoleIfNotExists } from "./setup/readOnlyRole";
import { setVODLayout, setLiveChannelLayout } from "./setup/layouts";

export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register(/*{ strapi }*/) {},
register({ strapi }) {

},

/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
async bootstrap({ strapi }) {
createReadOnlyRoleIfNotExists();
createReadOnlyRoleIfNotExists(strapi);
setVODLayout(strapi);
setLiveChannelLayout(strapi);
},
};
19 changes: 19 additions & 0 deletions src/setup/layouts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import VODLayout from "./layouts/VOD.json"
import LiveChannelLayout from "./layouts/LiveChannel.json"

export const setVODLayout = (strapi) => {
const contentTypeService = strapi.services["plugin::content-manager.content-types"];
const contentType = contentTypeService.findContentType("api::vod.vod");
const defaultConfig = contentTypeService.findConfiguration(contentType);
contentTypeService.updateConfiguration(contentType, {...defaultConfig, layouts: VODLayout.layouts});
}

export const setLiveChannelLayout = (strapi) => {
const contentTypeService = strapi.services["plugin::content-manager.content-types"];
const contentType = contentTypeService.findContentType("api::live-channel.live-channel");
const defaultConfig = contentTypeService.findConfiguration(contentType);
contentTypeService.updateConfiguration(contentType, {...defaultConfig, layouts: LiveChannelLayout.layouts});
}



52 changes: 52 additions & 0 deletions src/setup/layouts/LiveChannel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"layouts": {
"edit": [
[
{
"name": "name",
"size": 6
},
{
"name": "thumbnail",
"size": 6
}
],
[
{
"name": "input_type",
"size": 6
},
{
"name": "output_type",
"size": 6
}
],
[
{
"name": "vods",
"size": 6
},
{
"name": "genre-category-relation",
"size": 6
}
],
[
{
"name": "catch_up",
"size": 6
},
{
"name": "Live_to_vod",
"size": 6
}
]
],
"list": [
"thumbnail",
"name",
"genre",
"category"
]
}
}
60 changes: 60 additions & 0 deletions src/setup/layouts/VOD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"layouts": {
"edit": [
[
{
"name": "Name",
"size": 6
},
{
"name": "Thumbnails",
"size": 6
}
],
[
{
"name": "description",
"size": 6
},
{
"name": "genre-category-relation",
"size": 6
}
],
[
{
"name": "media_url",
"size": 12
}
],
[
{
"name": "rotation_start",
"size": 6
},
{
"name": "rotation_end",
"size": 6
}
],
[
{
"name": "live_channel",
"size": 6
},
{
"name": "highlighted",
"size": 6
}
]
],
"list": [
"Thumbnails",
"Name",
"media_url",
"genre",
"category",
"views"
]
}
}
63 changes: 63 additions & 0 deletions src/setup/readOnlyRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const readOnlyUsersPermissions = {
action: 'plugin::content-manager.explorer.read',
subject: 'plugin::users-permissions.user',
conditions: [],
properties: {
fields: [
'username',
'email',
'provider',
'password',
'resetPasswordToken',
'confirmationToken',
'confirmed',
'blocked',
'role',
],
},
}

const getApiContentTypesFields = (contentTypeService) => {
const apiUIDs : string[] = contentTypeService.findAllContentTypes()
.map(ct => ct.uid)
.filter(uid => uid.startsWith("api::"));
const permissions = apiUIDs.map((uid) => {
const contentType = contentTypeService.findContentType(uid);
const fields = Object.keys(contentType.attributes).filter(key => key !== "id");
return {
action: 'plugin::content-manager.explorer.read',
subject: uid,
conditions: [],
properties: {
fields,
},
}
});
return permissions
};


const createReadOnlyRole = async (strapi) => {
const contentTypeService = strapi.services["plugin::content-manager.content-types"];
const roleService = strapi.services["admin::role"];
const permissions = [
readOnlyUsersPermissions,
...getApiContentTypesFields(contentTypeService),
];
const data = await strapi.entityService.create('admin::role', {
data: {
name: 'Read-Only',
code: `read-only`,
description: 'Read only access for demo user',
},
});
await roleService.assignPermissions(data.id, permissions);
}

export const createReadOnlyRoleIfNotExists = async (strapi) => {
const data: any[] = await strapi.entityService.findMany("admin::role", {
filters: { code: {$eq: "read-only"}}
})
if (data.length == 0)
await createReadOnlyRole(strapi);
};

0 comments on commit 6dfd324

Please sign in to comment.