forked from coding-blocks/hacker-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in tag-updates (pull request coding-blocks#41)
React to tag changes appropriately Approved-by: Varun Hasija <[email protected]>
- Loading branch information
Showing
10 changed files
with
314 additions
and
72 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
migrations/20180217150447-add-tag-fk-to-practice-categories.js
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,28 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (Q, Sequelize) => { | ||
return Q.addColumn ( | ||
'practice_categories', | ||
'tag_id', | ||
{ | ||
type: Sequelize.INTEGER, | ||
references: { | ||
model: 'tags', | ||
key: 'id' | ||
}, | ||
onUpdate: 'cascade', | ||
onDelete: 'cascade' | ||
} | ||
) | ||
.then (() => { | ||
return Q.sequelize.query ( | ||
'update practice_categories set tag_id = tags.id from tags where tags.name = practice_categories.name' | ||
) | ||
}) | ||
}, | ||
|
||
down: (Q, Sequelize) => { | ||
return Q.removeColumn ('practice_categories', 'tag_id') | ||
} | ||
}; |
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,28 +1,28 @@ | ||
/** | ||
* Created by umair on 3/27/17. | ||
* Fixed by prajjwal on 17/02/18. | ||
*/ | ||
|
||
const db = require('../util/sequelize'); | ||
const Sequelize = require('sequelize'); | ||
const Problem = require('./problem'); | ||
const Contest = require('./contest'); | ||
|
||
const PracticeCategory = db.define('practice_category', { | ||
id: { | ||
type: Sequelize.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true | ||
}, | ||
c_id: Sequelize.INTEGER, | ||
name: Sequelize.STRING, | ||
status: Sequelize.INTEGER | ||
const db = require ('../util/sequelize'); | ||
|
||
const Contest = require ('./contest'); | ||
const Problem = require ('./problem'); | ||
const Sequelize = require ('sequelize'); | ||
const Tag = require ('./tag'); | ||
|
||
const PracticeCategory = db.define ('practice_category', { | ||
id : { | ||
type : Sequelize.INTEGER, | ||
primaryKey : true, | ||
autoIncrement : true | ||
}, | ||
c_id : Sequelize.INTEGER, | ||
name : Sequelize.STRING, | ||
status : Sequelize.INTEGER, | ||
tag_id : Sequelize.INTEGER, | ||
}); | ||
|
||
PracticeCategory.belongsTo(Contest, { foreignKey: 'c_id', as: 'contests'}); | ||
PracticeCategory.belongsTo (Contest, { foreignKey: 'c_id', as: 'contests'}); | ||
PracticeCategory.belongsTo (Tag, { foreignKey: 'tag_id' }); | ||
|
||
module.exports = PracticeCategory; | ||
|
||
|
||
|
||
|
||
|
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
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,4 +1,34 @@ | ||
const JsonAPI = require ('../util/json-api'), | ||
R = require ('ramda'), | ||
U = require ('../util/acl-util') | ||
; | ||
|
||
// -- [Helpers] -- | ||
|
||
const canCreateTag = | ||
R.anyPass ([U.currentUserIsAdmin, U.currentUserIsModerator]) | ||
|
||
// -- [/Helpers] -- | ||
|
||
const GETPolicy = (request, response, next) => | ||
next () | ||
|
||
const POSTPolicy = (request, response, next) => | ||
canCreateTag (response) | ||
? next () | ||
: response.sendStatus (403) | ||
|
||
const PATCHPolicy = (request, response, next) => | ||
U.currentUserIsAdmin (response) | ||
? next () | ||
: response.sendStatus (403) | ||
|
||
const DELETEPolicy = (request, response, next) => | ||
U.currentUserIsAdmin (response) | ||
? next () | ||
: response.sendStatus (403) | ||
|
||
exports.GETPolicy = GETPolicy | ||
exports.POSTPolicy = POSTPolicy | ||
exports.PATCHPolicy = PATCHPolicy | ||
exports.DELETEPolicy = DELETEPolicy |
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
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
Oops, something went wrong.