-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): vod/live-channels default entries list/creation-view on…
… 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
Showing
5 changed files
with
202 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |