@@ -274,7 +274,7 @@ async function searchChallenges (currentUser, criteria) {
274
274
{ wildcard : { name : `*${ criteria . search } *` } } ,
275
275
{ wildcard : { name : `${ criteria . search } *` } } ,
276
276
{ wildcard : { name : `*${ criteria . search } ` } } ,
277
- { match_phrase : { tags : criteria . search } } ,
277
+ { match_phrase : { tags : criteria . search } }
278
278
]
279
279
} } )
280
280
} else {
@@ -1649,6 +1649,39 @@ async function update (currentUser, challengeId, data, isFull) {
1649
1649
await validateWinners ( data . winners , challengeId )
1650
1650
}
1651
1651
1652
+ // Only m2m tokens are allowed to modify the `task.*` information on a challenge
1653
+ if ( ! _ . isUndefined ( _ . get ( data , 'task' ) ) && ! currentUser . isMachine ) {
1654
+ if ( ! _ . isUndefined ( _ . get ( challenge , 'task' ) ) ) {
1655
+ logger . info ( `User ${ currentUser . handle || currentUser . sub } is not allowed to modify the task information on challenge ${ challengeId } ` )
1656
+ data . task = challenge . task
1657
+ logger . info ( `Task information on challenge ${ challengeId } is reset to ${ JSON . stringify ( challenge . task ) } . Original data: ${ JSON . stringify ( data . task ) } ` )
1658
+ } else {
1659
+ delete data . task
1660
+ }
1661
+ }
1662
+
1663
+ // task.memberId goes out of sync due to another processor setting "task.memberId" but subsequent immediate update to the task
1664
+ // will not have the memberId set. So we need to set it using winners to ensure it is always in sync. The proper fix is to correct
1665
+ // the sync issue in the processor. However this is quick fix that works since winner.userId is task.memberId.
1666
+ if ( _ . get ( challenge , 'legacy.pureV5Task' ) && ! _ . isUndefined ( data . winners ) ) {
1667
+ const winnerMemberId = _ . get ( data . winners , '[0].userId' )
1668
+ logger . info ( `Setting task.memberId to ${ winnerMemberId } for challenge ${ challengeId } . Task ${ _ . get ( data , 'task' ) } - ${ _ . get ( challenge , 'task' ) } ` )
1669
+
1670
+ if ( winnerMemberId != null && _ . get ( data , 'task.memberId' ) !== winnerMemberId ) {
1671
+ logger . info ( `Task ${ challengeId } has a winner ${ winnerMemberId } ` )
1672
+ data . task = {
1673
+ isTask : true ,
1674
+ isAssigned : true ,
1675
+ memberId : winnerMemberId
1676
+ }
1677
+ logger . warn ( `task.memberId mismatched with winner memberId. task.memberId is updated to ${ winnerMemberId } ` )
1678
+ } else {
1679
+ logger . info ( `task ${ challengeId } has no winner set yet.` )
1680
+ }
1681
+ } else {
1682
+ logger . info ( `${ challengeId } is not a pureV5 challenge or has no winners set yet.` )
1683
+ }
1684
+
1652
1685
data . updated = moment ( ) . utc ( )
1653
1686
data . updatedBy = currentUser . handle || currentUser . sub
1654
1687
const updateDetails = { }
@@ -1709,6 +1742,9 @@ async function update (currentUser, challengeId, data, isFull) {
1709
1742
op = '$PUT'
1710
1743
} else if ( _ . isUndefined ( challenge [ key ] ) || challenge [ key ] !== value ) {
1711
1744
op = '$PUT'
1745
+ } else if ( _ . get ( challenge , 'legacy.pureV5Task' ) && key === 'task' ) {
1746
+ // always update task for pureV5 challenges
1747
+ op = '$PUT'
1712
1748
}
1713
1749
1714
1750
if ( op ) {
@@ -1848,15 +1884,6 @@ async function update (currentUser, challengeId, data, isFull) {
1848
1884
1849
1885
const { track, type } = await validateChallengeData ( _ . pick ( challenge , [ 'trackId' , 'typeId' ] ) )
1850
1886
1851
- // Only m2m tokens are allowed to modify the `task.*` information on a challenge
1852
- if ( ! _ . isUndefined ( _ . get ( data , 'task' ) ) && ! currentUser . isMachine ) {
1853
- if ( ! _ . isUndefined ( _ . get ( challenge , 'task' ) ) ) {
1854
- data . task = challenge . task
1855
- } else {
1856
- delete data . task
1857
- }
1858
- }
1859
-
1860
1887
if ( _ . get ( type , 'isTask' ) ) {
1861
1888
if ( ! _ . isEmpty ( _ . get ( data , 'task.memberId' ) ) ) {
1862
1889
const challengeResources = await helper . getChallengeResources ( challengeId )
0 commit comments