Skip to content

Add new field isApplicationPageActive to the Job model #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ paths:
Create job.

**Authorization** All topcoder members are allowed

Permission rules on field `isApplicationPageActive`:
- M2M user is allowed to set the value of the field
- Other users are not allowed to set the value of the field

security:
- bearerAuth: []
requestBody:
Expand Down Expand Up @@ -352,6 +357,10 @@ paths:
Update the job.

**Authorization** Every topcoder member can update the job he/she created. bookingmanager and connectmember can update all jobs.

Permission rules on field `isApplicationPageActive`:
- M2M user is allowed to update the value of the field
- Other users are not allowed to update the value of the field
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -413,6 +422,10 @@ paths:
Update job.

**Authorization** Topcoder token with patch job scope is allowed

Permission rules on field `isApplicationPageActive`:
- M2M user is allowed to update the value of the field
- Other users are not allowed to update the value of the field
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -1980,6 +1993,9 @@ components:
description: "The job candidates."
items:
$ref: '#/components/schemas/JobCandidate'
isApplicationPageActive:
type: boolean
default: false
createdAt:
type: string
format: date-time
Expand Down Expand Up @@ -2057,6 +2073,9 @@ components:
type: string
format: uuid
description: "The skill id."
isApplicationPageActive:
type: boolean
default: false
JobCandidate:
required:
- id
Expand Down Expand Up @@ -2186,6 +2205,9 @@ components:
type: string
format: uuid
description: "The skill id."
isApplicationPageActive:
type: boolean
default: false
ResourceBooking:
required:
- id
Expand Down
17 changes: 17 additions & 0 deletions migrations/2021-02-27-job-add-is-application-page-active-field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Add isApplicationPageActive field to the Job model.
*/

module.exports = {
up: queryInterface => {
return Promise.all([
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ADD is_application_page_active BOOLEAN NOT NULL DEFAULT false'),
queryInterface.sequelize.query('UPDATE bookings.jobs SET is_application_page_active=false WHERE is_application_page_active is NULL'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this second query UPDATE bookings.jobs SET is_application_page_active=false WHERE is_application_page_active is NULL as the previous one would already set all the values bye default, and it also sets NOT NUL so there cannot be null values.

But it doesn't harm either.

])
},
down: queryInterface => {
return Promise.all([
queryInterface.sequelize.query('ALTER TABLE bookings.jobs DROP is_application_page_active')
])
}
}
1 change: 1 addition & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ esIndexPropertyMapping[config.get('esConfig.ES_INDEX_JOB')] = {
workload: { type: 'keyword' },
skills: { type: 'keyword' },
status: { type: 'keyword' },
isApplicationPageActive: { type: 'boolean' },
createdAt: { type: 'date' },
createdBy: { type: 'keyword' },
updatedAt: { type: 'date' },
Expand Down
6 changes: 6 additions & 0 deletions src/models/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ module.exports = (sequelize) => {
type: Sequelize.STRING(255),
allowNull: false
},
isApplicationPageActive: {
field: 'is_application_page_active',
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false
},
createdBy: {
field: 'created_by',
type: Sequelize.UUID,
Expand Down
20 changes: 17 additions & 3 deletions src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ async function createJob (currentUser, job) {
await helper.checkIsMemberOfProject(currentUser.userId, job.projectId)
}

// the "isApplicationPageActive" field can be set/updated only by M2M user
if (!_.isUndefined(job.isApplicationPageActive) && !currentUser.isMachine) {
throw new errors.ForbiddenError('You are not allowed to set/update the value of field "isApplicationPageActive".')
}

await _validateSkills(job.skills)
job.id = uuid()
job.createdBy = await helper.getUserId(currentUser.userId)
Expand All @@ -171,7 +176,8 @@ createJob.schema = Joi.object().keys({
resourceType: Joi.stringAllowEmpty().allow(null),
rateType: Joi.rateType().allow(null),
workload: Joi.workload().allow(null),
skills: Joi.array().items(Joi.string().uuid()).required()
skills: Joi.array().items(Joi.string().uuid()).required(),
isApplicationPageActive: Joi.boolean()
}).required()
}).required()

Expand All @@ -188,6 +194,12 @@ async function updateJob (currentUser, id, data) {
}
let job = await Job.findById(id)
const oldValue = job.toJSON()

// the "isApplicationPageActive" field can be set/updated only by M2M user
if (!_.isUndefined(data.isApplicationPageActive) && !currentUser.isMachine) {
throw new errors.ForbiddenError('You are not allowed to set/update the value of field "isApplicationPageActive".')
}

const ubahnUserId = await helper.getUserId(currentUser.userId)
if (!currentUser.hasManagePermission && !currentUser.isMachine) {
// Check whether user can update the job.
Expand Down Expand Up @@ -232,7 +244,8 @@ partiallyUpdateJob.schema = Joi.object().keys({
resourceType: Joi.stringAllowEmpty().allow(null),
rateType: Joi.rateType().allow(null),
workload: Joi.workload().allow(null),
skills: Joi.array().items(Joi.string().uuid())
skills: Joi.array().items(Joi.string().uuid()),
isApplicationPageActive: Joi.boolean()
}).required()
}).required()

Expand Down Expand Up @@ -262,7 +275,8 @@ fullyUpdateJob.schema = Joi.object().keys({
rateType: Joi.rateType().allow(null).default(null),
workload: Joi.workload().allow(null).default(null),
skills: Joi.array().items(Joi.string().uuid()).required(),
status: Joi.jobStatus().default('sourcing')
status: Joi.jobStatus().default('sourcing'),
isApplicationPageActive: Joi.boolean()
}).required()
}).required()

Expand Down