Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit ec32076

Browse files
authored
✨ [issue-12][developerdao.com-264] Add GeneralQuery to get news_ticker (#13)
- add Markup component - update Seeding to allow Public quering
1 parent e7c2cd9 commit ec32076

File tree

11 files changed

+192
-6
lines changed

11 files changed

+192
-6
lines changed

cms/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"strapi": "strapi"
1313
},
1414
"devDependencies": {
15-
"@faker-js/faker": "^7.3.0"
15+
"@faker-js/faker": "^7.3.0",
16+
"lodash.merge": "^4.6.2"
1617
},
1718
"dependencies": {
1819
"@strapi/plugin-graphql": "4.2.2",

cms/src/_seed/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
SEED_USERNAME: 'seed_user',
3+
DEFAULT_PUBLIC_ROLE_ID: 2, // Auth user - 1, Public - 2 - this is by default
34
APPLICATION_COLLECTION_TYPE_UIDS: [
45
'api::contributor.contributor',
56
'api::partner.partner',

cms/src/_seed/general.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {Strapi} strapi
3+
* @returns {Promise<void>}
4+
*/
5+
const fillGeneralData = async (strapi) => {
6+
console.log('filling general data...')
7+
8+
let generalObject = await strapi.entityService.findMany('api::general.general', {})
9+
10+
if (!generalObject) {
11+
generalObject = await strapi.entityService.create('api::general.general', {
12+
data: {
13+
publishedAt: new Date().toISOString()
14+
}
15+
})
16+
}
17+
18+
await strapi.entityService.update('api::general.general', generalObject.id, {
19+
data: {
20+
news_ticker: {
21+
name: 'news_ticker',
22+
content: '# markdown content'
23+
}
24+
}
25+
})
26+
27+
console.log('general data has been filled successfully!')
28+
}
29+
30+
module.exports = {
31+
fillGeneralData,
32+
}

cms/src/_seed/helpers.js

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { APPLICATION_COLLECTION_TYPE_UIDS } = require('./constants');
1+
const { APPLICATION_COLLECTION_TYPE_UIDS, DEFAULT_PUBLIC_ROLE_ID, } = require('./constants');
22
const { statSync } = require('fs');
3+
const merge = require('lodash.merge')
34

45
/**
56
* @param {Strapi} strapi
@@ -58,8 +59,16 @@ const uploadFile = async (strapi, {
5859
data,
5960
file,
6061
}) => {
61-
const { refId, ref, field } = data
62-
const { name, path, type } = file
62+
const {
63+
refId,
64+
ref,
65+
field
66+
} = data
67+
const {
68+
name,
69+
path,
70+
type
71+
} = file
6372

6473
const fileStat = statSync(path);
6574

@@ -80,10 +89,78 @@ const uploadFile = async (strapi, {
8089
return uploadedFile
8190
}
8291

92+
/**
93+
* @param {Strapi} strapi
94+
*/
95+
const updateStrapiPublicRole = async (strapi,) => {
96+
const roleService = strapi.plugin('users-permissions').service('role')
97+
98+
const publicRoleSettings = await roleService.findOne(DEFAULT_PUBLIC_ROLE_ID)
99+
const overridePermissions = {
100+
'api::contributor': {
101+
controllers: {
102+
contributor: {
103+
find: {
104+
enabled: true,
105+
},
106+
findOne: {
107+
enabled: true,
108+
},
109+
}
110+
}
111+
},
112+
'api::general': {
113+
controllers: {
114+
general: {
115+
find: {
116+
enabled: true,
117+
},
118+
}
119+
}
120+
},
121+
'api::home-page': {
122+
controllers: {
123+
'home-page': {
124+
find: {
125+
enabled: true,
126+
},
127+
}
128+
}
129+
},
130+
'api::partner': {
131+
controllers: {
132+
partner: {
133+
find: {
134+
enabled: true,
135+
},
136+
findOne: {
137+
enabled: true,
138+
},
139+
}
140+
}
141+
},
142+
'api::project': {
143+
controllers: {
144+
project: {
145+
find: {
146+
enabled: true,
147+
},
148+
findOne: {
149+
enabled: true,
150+
},
151+
}
152+
}
153+
},
154+
}
155+
156+
await roleService.updateRole(DEFAULT_PUBLIC_ROLE_ID, merge({ ...publicRoleSettings }, { permissions: overridePermissions }))
157+
}
158+
83159
module.exports = {
84160
ensureSQLite,
85161
randomBoolean,
86162
clearData,
87163
sampleSize,
88164
uploadFile,
165+
updateStrapiPublicRole,
89166
}

cms/src/_seed/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const { seedUserExists, generateUserData } = require('./user');
2-
const { clearData } = require('./helpers');
2+
const { clearData, updateStrapiPublicRole } = require('./helpers');
33
const { generatePartnerData } = require('./partner');
44
const { generateProjectAndContributorData } = require('./project-and-contributor');
55
const { fillHomePage } = require('./pages');
6+
const { fillGeneralData } = require('./general');
67

78
/**
89
* @param {Strapi} strapi
@@ -36,14 +37,18 @@ const generateSeedData = async (strapi) => {
3637
throw new Error(e)
3738
})
3839

39-
// Pages
40+
// Single Types
4041
await Promise.all([
4142
fillHomePage(strapi),
43+
fillGeneralData(strapi),
4244
]).catch(e => {
4345
console.error('error during generating page data! Stopping the application...')
4446
throw new Error(e)
4547
})
4648

49+
console.log('updating Public role to access pages and data')
50+
await updateStrapiPublicRole(strapi)
51+
4752
console.log('generating seed data has been finished successfully!')
4853
}
4954

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"kind": "singleType",
3+
"collectionName": "generals",
4+
"info": {
5+
"singularName": "general",
6+
"pluralName": "generals",
7+
"displayName": "General"
8+
},
9+
"options": {
10+
"draftAndPublish": true
11+
},
12+
"pluginOptions": {},
13+
"attributes": {
14+
"news_ticker": {
15+
"type": "component",
16+
"repeatable": false,
17+
"component": "general.markup"
18+
}
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
/**
4+
* general controller
5+
*/
6+
7+
const { createCoreController } = require('@strapi/strapi').factories;
8+
9+
module.exports = createCoreController('api::general.general');

cms/src/api/general/routes/general.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
/**
4+
* general router.
5+
*/
6+
7+
const { createCoreRouter } = require('@strapi/strapi').factories;
8+
9+
module.exports = createCoreRouter('api::general.general');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
/**
4+
* general service.
5+
*/
6+
7+
const { createCoreService } = require('@strapi/strapi').factories;
8+
9+
module.exports = createCoreService('api::general.general');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"collectionName": "components_general_markups",
3+
"info": {
4+
"displayName": "Markup",
5+
"icon": "align-justify"
6+
},
7+
"options": {},
8+
"attributes": {
9+
"name": {
10+
"type": "string",
11+
"required": true
12+
},
13+
"content": {
14+
"type": "richtext",
15+
"required": true
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)