From 2b95555e0f5ca5c18788d31c27deaed82db79c31 Mon Sep 17 00:00:00 2001 From: prathambatra Date: Tue, 9 Jun 2020 01:59:44 +0530 Subject: [PATCH 1/3] Replaced claim with claimId in getConflictedClaims Signed-off-by: prathambatra --- routes/root.js | 2 +- utils/datautils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/root.js b/routes/root.js index 0e9b722..28f562c 100644 --- a/routes/root.js +++ b/routes/root.js @@ -259,7 +259,7 @@ route.get('/claims/:id', auth.adminOnly, (req, res) => { if (!claim) throw new Error('No claim found') pullUrlDetail = getUrlDetails(claim["pullUrl"]) issueUrlDetail = getUrlDetails(claim["issueUrl"]) - du.getConflictedClaims(claim,issueUrlDetail,pullUrlDetail.type) + du.getConflictedClaims(claim.id,issueUrlDetail,pullUrlDetail.type) .then(conflictedClaims => { if(conflictedClaims.length === 0) res.render('pages/claims/id',{claim, hasConflict: false }) diff --git a/utils/datautils.js b/utils/datautils.js index 503a30f..75cc609 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -78,7 +78,7 @@ function delClaim(claimId) { }) } -function getConflictedClaims(claim,issueUrlDetail,pullUrlType) { +function getConflictedClaims(claimId,issueUrlDetail,pullUrlType) { projectName = '/' + issueUrlDetail.project + '/' issueId = '/' + issueUrlDetail.id pullUrlType = projectName + pullUrlType + '/' @@ -92,7 +92,7 @@ function getConflictedClaims(claim,issueUrlDetail,pullUrlType) { ] }, { pullUrl: { [Op.like]: '%' + pullUrlType + '%' } }, - { id : { [Op.ne] : claim.id } } + { id : { [Op.ne] : claimId } } ] } }) From 3795784db09ea83f9bbc926fe7b90a8a44ff91cd Mon Sep 17 00:00:00 2001 From: prathambatra Date: Thu, 11 Jun 2020 01:46:50 +0530 Subject: [PATCH 2/3] added reject-conflict controller Signed-off-by: prathambatra --- index.js | 2 +- utils/datautils.js | 82 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 1641601..d93bce9 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const db = require('./utils/db').Database; db.sync({force: false}).then(() => { console.log('Database configured'); - process.env.PORT = process.env.PORT || 3232; + process.env.PORT = process.env.PORT || 3000; app.listen(process.env.PORT, function () { console.log("Server started on http://localhost:" + process.env.PORT); }); diff --git a/utils/datautils.js b/utils/datautils.js index 75cc609..9d48cc1 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -5,6 +5,7 @@ const db = require('./db') const fs = require('fs') const consts = require('./consts') const {Op} = require('sequelize') +const { getUrlDetails } = require('./urlUtils') function getContestPeriod(year) { if (year) @@ -98,6 +99,40 @@ function getConflictedClaims(claimId,issueUrlDetail,pullUrlType) { }) } +function rejectConflicts(claimId) { + getClaimById(claimId) + .then((claim) => { + issueUrlDetail = getUrlDetails(claim.issueUrl) + projectName = '/' + issueUrlDetail.project + '/' + issueId = '/' + issueUrlDetail.id + pullUrlType = getUrlDetails(claim.pullUrl).type + return db.Claim.update( + { + status: "rejected", + reason: "Conflicting with other claim", + }, + { + where: { + [Op.and] : [ + { + [Op.or] : [ + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } }, + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } } + ] + }, + { pullUrl: { [Op.like]: '%' + pullUrlType + '%' } }, + { id : { [Op.ne] : claimId } } + ] + }, + returning: true + } + ) + }) + .catch(err => { + throw new Error('Error') + }) +} + function updateClaim(claimId, { status, reason, bounty }) { const claim = { action: 'update', @@ -107,19 +142,42 @@ function updateClaim(claimId, { status, reason, bounty }) { } fs.writeFile(__dirname + '/../audit/' + new Date().toISOString() + '.json', JSON.stringify(claim), () => {}) - return db.Claim.update( - { - status: status, - reason: reason, - bounty: bounty - }, - { - where: { - id: claimId + if(status === 'accepted') { + rejectConflicts(claimId) + .then((result) => { + console.log('Rejected') + return db.Claim.update( + { + status: status, + reason: reason, + bounty: bounty + }, + { + where: { + id: claimId + }, + returning: true + } + ) + }) + .catch(err => { + throw new Error('Error') + }) + } else { + return db.Claim.update( + { + status: status, + reason: reason, + bounty: bounty }, - returning: true - } - ) + { + where: { + id: claimId + }, + returning: true + } + ) + } } function getGithubResource(url) { From 012f91a0dbc9855385a6e04d537163e1d0b9a3b2 Mon Sep 17 00:00:00 2001 From: prathambatra Date: Thu, 11 Jun 2020 18:13:38 +0530 Subject: [PATCH 3/3] Reject conflicts working Signed-off-by: prathambatra --- index.js | 2 +- routes/root.js | 31 +++++++++--- utils/datautils.js | 104 ++++++++++++++------------------------ views/pages/claims/id.hbs | 9 ++++ 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/index.js b/index.js index d93bce9..1641601 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const db = require('./utils/db').Database; db.sync({force: false}).then(() => { console.log('Database configured'); - process.env.PORT = process.env.PORT || 3000; + process.env.PORT = process.env.PORT || 3232; app.listen(process.env.PORT, function () { console.log("Server started on http://localhost:" + process.env.PORT); }); diff --git a/routes/root.js b/routes/root.js index 28f562c..3209106 100644 --- a/routes/root.js +++ b/routes/root.js @@ -277,13 +277,32 @@ route.get('/claims/:id', auth.adminOnly, (req, res) => { }) route.post('/claims/:id/update', auth.adminOnly, (req, res) => { - du.updateClaim(req.params.id, req.body) - .then(result => { - res.redirect('/claims/' + req.params.id) - }) - .catch(error => { - res.send('Error updating claim') + if(req.body.status === 'accepted') { + du.getClaimById(req.params.id) + .then(claim => { + issueUrlDetail = getUrlDetails(claim["issueUrl"]) + pullUrlType = getUrlDetails(claim["pullUrl"]).type + du.rejectConflicts(req.params.id,issueUrlDetail,pullUrlType) + .then(result => { + du.updateClaim(req.params.id, req.body) + .then(result => { + res.redirect('/claims/' + req.params.id) + }) + .catch(error => { + res.send('Error updating claim') + }) + }) }) + } + else { + du.updateClaim(req.params.id, req.body) + .then(result => { + res.redirect('/claims/' + req.params.id) + }) + .catch(error => { + res.send('Error updating claim') + }) + } }) route.get('/claims/:id/edit', auth.ensureLoggedInGithub, auth.ensureUserCanEdit, (req, res) => { diff --git a/utils/datautils.js b/utils/datautils.js index 9d48cc1..1d63a27 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -99,38 +99,32 @@ function getConflictedClaims(claimId,issueUrlDetail,pullUrlType) { }) } -function rejectConflicts(claimId) { - getClaimById(claimId) - .then((claim) => { - issueUrlDetail = getUrlDetails(claim.issueUrl) - projectName = '/' + issueUrlDetail.project + '/' - issueId = '/' + issueUrlDetail.id - pullUrlType = getUrlDetails(claim.pullUrl).type - return db.Claim.update( - { - status: "rejected", - reason: "Conflicting with other claim", - }, - { - where: { - [Op.and] : [ - { - [Op.or] : [ - { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } }, - { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } } - ] - }, - { pullUrl: { [Op.like]: '%' + pullUrlType + '%' } }, - { id : { [Op.ne] : claimId } } +function rejectConflicts(claimId,issueUrlDetail,pullUrlType) { + console.log(issueUrlDetail) + projectName = '/' + issueUrlDetail.project + '/' + issueId = '/' + issueUrlDetail.id + pullUrlType = projectName + pullUrlType + '/' + return db.Claim.update( + { + status: "rejected", + reason: "Conflicting with other claim", + }, + { + where: { + [Op.and] : [ + { + [Op.or] : [ + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } }, + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } } ] }, - returning: true - } - ) - }) - .catch(err => { - throw new Error('Error') - }) + { pullUrl: { [Op.like]: '%' + pullUrlType + '%' } }, + { id : { [Op.ne] : claimId } } + ] + }, + returning: true + } + ) } function updateClaim(claimId, { status, reason, bounty }) { @@ -142,42 +136,19 @@ function updateClaim(claimId, { status, reason, bounty }) { } fs.writeFile(__dirname + '/../audit/' + new Date().toISOString() + '.json', JSON.stringify(claim), () => {}) - if(status === 'accepted') { - rejectConflicts(claimId) - .then((result) => { - console.log('Rejected') - return db.Claim.update( - { - status: status, - reason: reason, - bounty: bounty - }, - { - where: { - id: claimId - }, - returning: true - } - ) - }) - .catch(err => { - throw new Error('Error') - }) - } else { - return db.Claim.update( - { - status: status, - reason: reason, - bounty: bounty + return db.Claim.update( + { + status: status, + reason: reason, + bounty: bounty + }, + { + where: { + id: claimId }, - { - where: { - id: claimId - }, - returning: true - } - ) - } + returning: true + } + ) } function getGithubResource(url) { @@ -310,5 +281,6 @@ module.exports = { updateClaim, getCounts, getConflictedClaims, - getResourceFromUrl + getResourceFromUrl, + rejectConflicts, } diff --git a/views/pages/claims/id.hbs b/views/pages/claims/id.hbs index db0a943..be7bc95 100644 --- a/views/pages/claims/id.hbs +++ b/views/pages/claims/id.hbs @@ -128,6 +128,15 @@ window.location.href = conflictId } + {{#equal conflictedClaim.status "claimed"}} + {{conflictedClaim.status}} + {{/equal}} + {{#equal conflictedClaim.status "accepted"}} + {{conflictedClaim.status}} + {{/equal}} + {{#equal conflictedClaim.status "rejected"}} + {{conflictedClaim.status}} + {{/equal}}