Skip to content
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

Reject conflicts on accepting claim. #407

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 26 additions & 7 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be under a transaction.

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) => {
Expand Down
36 changes: 33 additions & 3 deletions utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,7 +79,7 @@ function delClaim(claimId) {
})
}

function getConflictedClaims(claim,issueUrlDetail,pullUrlType) {
function getConflictedClaims(claimId,issueUrlDetail,pullUrlType) {
projectName = '/' + issueUrlDetail.project + '/'
issueId = '/' + issueUrlDetail.id
pullUrlType = projectName + pullUrlType + '/'
Expand All @@ -92,12 +93,40 @@ function getConflictedClaims(claim,issueUrlDetail,pullUrlType) {
]
},
{ pullUrl: { [Op.like]: '%' + pullUrlType + '%' } },
{ id : { [Op.ne] : claim.id } }
{ 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 + '/' } }
]
},
{ pullUrl: { [Op.like]: '%' + pullUrlType + '%' } },
{ id : { [Op.ne] : claimId } }
]
},
returning: true
}
)
}

function updateClaim(claimId, { status, reason, bounty }) {
const claim = {
action: 'update',
Expand Down Expand Up @@ -252,5 +281,6 @@ module.exports = {
updateClaim,
getCounts,
getConflictedClaims,
getResourceFromUrl
getResourceFromUrl,
rejectConflicts,
}
9 changes: 9 additions & 0 deletions views/pages/claims/id.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
window.location.href = conflictId
}
</script>
{{#equal conflictedClaim.status "claimed"}}
<span class="badge badge-pill badge-warning">{{conflictedClaim.status}}</span>
{{/equal}}
{{#equal conflictedClaim.status "accepted"}}
<span class="badge badge-pill badge-success">{{conflictedClaim.status}}</span>
{{/equal}}
{{#equal conflictedClaim.status "rejected"}}
<span class="badge badge-pill badge-danger">{{conflictedClaim.status}}</span>
{{/equal}}
</div>
</div>
<div class="col-md-8">
Expand Down