Skip to content

Commit 8f1d3bb

Browse files
Merge pull request #169 from imcaizheng/job-add-new-field-is-application-page-active
Add new field `isApplicationPageActive` to the Job model
2 parents 53c453b + 868fbaf commit 8f1d3bb

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

docs/swagger.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ paths:
2323
Create job.
2424
2525
**Authorization** All topcoder members are allowed
26+
27+
Permission rules on field `isApplicationPageActive`:
28+
- M2M user is allowed to set the value of the field
29+
- Other users are not allowed to set the value of the field
30+
2631
security:
2732
- bearerAuth: []
2833
requestBody:
@@ -352,6 +357,10 @@ paths:
352357
Update the job.
353358
354359
**Authorization** Every topcoder member can update the job he/she created. bookingmanager and connectmember can update all jobs.
360+
361+
Permission rules on field `isApplicationPageActive`:
362+
- M2M user is allowed to update the value of the field
363+
- Other users are not allowed to update the value of the field
355364
security:
356365
- bearerAuth: []
357366
parameters:
@@ -413,6 +422,10 @@ paths:
413422
Update job.
414423
415424
**Authorization** Topcoder token with patch job scope is allowed
425+
426+
Permission rules on field `isApplicationPageActive`:
427+
- M2M user is allowed to update the value of the field
428+
- Other users are not allowed to update the value of the field
416429
security:
417430
- bearerAuth: []
418431
parameters:
@@ -1980,6 +1993,9 @@ components:
19801993
description: "The job candidates."
19811994
items:
19821995
$ref: '#/components/schemas/JobCandidate'
1996+
isApplicationPageActive:
1997+
type: boolean
1998+
default: false
19831999
createdAt:
19842000
type: string
19852001
format: date-time
@@ -2057,6 +2073,9 @@ components:
20572073
type: string
20582074
format: uuid
20592075
description: "The skill id."
2076+
isApplicationPageActive:
2077+
type: boolean
2078+
default: false
20602079
JobCandidate:
20612080
required:
20622081
- id
@@ -2186,6 +2205,9 @@ components:
21862205
type: string
21872206
format: uuid
21882207
description: "The skill id."
2208+
isApplicationPageActive:
2209+
type: boolean
2210+
default: false
21892211
ResourceBooking:
21902212
required:
21912213
- id
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Add isApplicationPageActive field to the Job model.
3+
*/
4+
5+
module.exports = {
6+
up: queryInterface => {
7+
return Promise.all([
8+
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ADD is_application_page_active BOOLEAN NOT NULL DEFAULT false'),
9+
queryInterface.sequelize.query('UPDATE bookings.jobs SET is_application_page_active=false WHERE is_application_page_active is NULL'),
10+
])
11+
},
12+
down: queryInterface => {
13+
return Promise.all([
14+
queryInterface.sequelize.query('ALTER TABLE bookings.jobs DROP is_application_page_active')
15+
])
16+
}
17+
}

src/common/helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_JOB')] = {
7070
workload: { type: 'keyword' },
7171
skills: { type: 'keyword' },
7272
status: { type: 'keyword' },
73+
isApplicationPageActive: { type: 'boolean' },
7374
createdAt: { type: 'date' },
7475
createdBy: { type: 'keyword' },
7576
updatedAt: { type: 'date' },

src/models/Job.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ module.exports = (sequelize) => {
9898
type: Sequelize.STRING(255),
9999
allowNull: false
100100
},
101+
isApplicationPageActive: {
102+
field: 'is_application_page_active',
103+
type: Sequelize.BOOLEAN,
104+
defaultValue: false,
105+
allowNull: false
106+
},
101107
createdBy: {
102108
field: 'created_by',
103109
type: Sequelize.UUID,

src/services/JobService.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ async function createJob (currentUser, job) {
148148
await helper.checkIsMemberOfProject(currentUser.userId, job.projectId)
149149
}
150150

151+
// the "isApplicationPageActive" field can be set/updated only by M2M user
152+
if (!_.isUndefined(job.isApplicationPageActive) && !currentUser.isMachine) {
153+
throw new errors.ForbiddenError('You are not allowed to set/update the value of field "isApplicationPageActive".')
154+
}
155+
151156
await _validateSkills(job.skills)
152157
job.id = uuid()
153158
job.createdBy = await helper.getUserId(currentUser.userId)
@@ -171,7 +176,8 @@ createJob.schema = Joi.object().keys({
171176
resourceType: Joi.stringAllowEmpty().allow(null),
172177
rateType: Joi.rateType().allow(null),
173178
workload: Joi.workload().allow(null),
174-
skills: Joi.array().items(Joi.string().uuid()).required()
179+
skills: Joi.array().items(Joi.string().uuid()).required(),
180+
isApplicationPageActive: Joi.boolean()
175181
}).required()
176182
}).required()
177183

@@ -188,6 +194,12 @@ async function updateJob (currentUser, id, data) {
188194
}
189195
let job = await Job.findById(id)
190196
const oldValue = job.toJSON()
197+
198+
// the "isApplicationPageActive" field can be set/updated only by M2M user
199+
if (!_.isUndefined(data.isApplicationPageActive) && !currentUser.isMachine) {
200+
throw new errors.ForbiddenError('You are not allowed to set/update the value of field "isApplicationPageActive".')
201+
}
202+
191203
const ubahnUserId = await helper.getUserId(currentUser.userId)
192204
if (!currentUser.hasManagePermission && !currentUser.isMachine) {
193205
// Check whether user can update the job.
@@ -232,7 +244,8 @@ partiallyUpdateJob.schema = Joi.object().keys({
232244
resourceType: Joi.stringAllowEmpty().allow(null),
233245
rateType: Joi.rateType().allow(null),
234246
workload: Joi.workload().allow(null),
235-
skills: Joi.array().items(Joi.string().uuid())
247+
skills: Joi.array().items(Joi.string().uuid()),
248+
isApplicationPageActive: Joi.boolean()
236249
}).required()
237250
}).required()
238251

@@ -262,7 +275,8 @@ fullyUpdateJob.schema = Joi.object().keys({
262275
rateType: Joi.rateType().allow(null).default(null),
263276
workload: Joi.workload().allow(null).default(null),
264277
skills: Joi.array().items(Joi.string().uuid()).required(),
265-
status: Joi.jobStatus().default('sourcing')
278+
status: Joi.jobStatus().default('sourcing'),
279+
isApplicationPageActive: Joi.boolean()
266280
}).required()
267281
}).required()
268282

0 commit comments

Comments
 (0)