Skip to content

Commit

Permalink
Merge branch 'report-challenge' into delta
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreCat committed Jul 13, 2023
2 parents 50cea7e + 4573953 commit 10ed8e5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
19 changes: 10 additions & 9 deletions website/client/src/components/challenges/challengeDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
<div class="col-12 col-md-8 standard-page">
<div class="row">
<div class="col-12 col-md-6">
<span
class="flagged"
<div
v-if="canViewFlags"
class="flagged"
>
<span
<div
v-if="flaggedNotHidden"
>
{{ $t("flaggedNotHidden") }}
</span>
<span
</div>
<div
v-else-if="flaggedAndHidden"
>
{{ $t("flaggedAndHidden") }}
</span>
</span>
</div>
</div>
<h1 v-markdown="challenge.name"></h1>
<div>
<span class="mr-1 ml-0 d-block">
Expand Down Expand Up @@ -461,13 +461,13 @@ export default {
canJoin () {
return !this.isMember;
},
// canViewFlags should allow only moderators/aadmins to see flags
// canViewFlags should allow only moderators/admins to see flags
canViewFlags () {
const isAdmin = Boolean(this.user.contributor.admin);
if (isAdmin && this.challenge.flagCount > 0) return true;
return false;
},
// flaggedNotHidden should allow moder/admins & challenge owner to see flags
// flaggedNotHidden should allow mods/admins & challenge owner to see flags
flaggedNotHidden () {
return this.challenge.flagCount === 1;
},
Expand Down Expand Up @@ -664,6 +664,7 @@ export default {
},
cloneChallenge () {
this.$root.$emit('habitica:clone-challenge', {
flags: this.challenge.flags = [],
challenge: this.challenge,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ export default {
summary: '',
description: '',
categories: [],
flags: [],
group: '',
dailys: [],
habits: [],
Expand Down
2 changes: 0 additions & 2 deletions website/client/src/components/challenges/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

<script>
import SecondaryMenu from '@/components/secondaryMenu';
import reportChallengeModal from './reportChallengeModal';
export default {
components: {
SecondaryMenu,
reportChallengeModal,
},
};
</script>
27 changes: 13 additions & 14 deletions website/server/controllers/api-v3/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,9 @@ api.getUserChallenges = {
orOptions.push({ leader: user._id });

if (!req.query.member) {
const memberQuery = {
$and: [
{ group: { $in: user.getGroups() } },
],
};
if (!user.contributor.admin) {
memberQuery.$and.push({ flagCount: { $lt: 2 } });
}
orOptions.push(memberQuery); // Challenges in groups where I'm a member
orOptions.push({
group: { $in: user.getGroups() },
}); // Challenges in groups where I'm a member
}

const query = {
Expand All @@ -425,11 +419,16 @@ api.getUserChallenges = {
if (owned) {
if (owned === 'not_owned') {
query.$and.push({ leader: { $ne: user._id } });
if (!user.hasPermission('moderator')) {
query.$and.push({ $not: { flagCount: { gt: 1 } } });
}
}

if (owned === 'owned') {
query.$and.push({ leader: user._id });
}
} else if (!user.hasPermission('moderator')) {
query.$and.push({ $not: { flagCount: { gt: 1 } } });
}

if (req.query.search) {
Expand Down Expand Up @@ -529,7 +528,7 @@ api.getGroupChallenges = {
|| (user.challenges
&& user.challenges.findIndex(cId => cId === challenge._id) === -1);
const isFlaggedForNonAdminUser = challenge.flagCount > 1
&& !user.contributor.admin
&& !user.hasPermission('moderator')
&& nonParticipant
&& challenge.leader !== user._id;

Expand Down Expand Up @@ -587,7 +586,7 @@ api.getChallenge = {
|| (user.challenges
&& user.challenges.findIndex(cId => cId === challenge._id) === -1);
const isFlaggedForNonAdminUser = challenge.flagCount > 1
&& !user.contributor.admin
&& !user.hasPermission('moderator')
&& nonParticipant
&& challenge.leader !== user._id;
if (isFlaggedForNonAdminUser) throw new NotFound(res.t('challengeNotFound'));
Expand Down Expand Up @@ -848,7 +847,7 @@ api.selectChallengeWinner = {
|| (user.challenges
&& user.challenges.findIndex(cId => cId === challenge._id) === -1);
const isFlaggedForNonAdminUser = challenge.flagCount > 1
&& !user.contributor.admin
&& !user.hasPermission('moderator')
&& nonParticipant
&& challenge.leader !== user._id;
if (isFlaggedForNonAdminUser) throw new NotFound(res.t('challengeNotFound'));
Expand Down Expand Up @@ -906,7 +905,7 @@ api.cloneChallenge = {
|| (user.challenges
&& user.challenges.findIndex(cId => cId === challengeToClone._id) === -1);
const isFlaggedForNonAdminUser = challengeToClone.flagCount > 1
&& !user.contributor.admin
&& !user.hasPermission('moderator')
&& nonParticipant
&& challengeToClone.leader !== user._id;
if (isFlaggedForNonAdminUser) throw new NotFound(res.t('challengeNotFound'));
Expand Down Expand Up @@ -1001,7 +1000,7 @@ api.clearFlagsChallenge = {
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;

if (!user.contributor.admin) {
if (!user.hasPermission('moderator')) {
throw new NotAuthorized(res.t('messageGroupChatAdminClearFlagCount'));
}

Expand Down

0 comments on commit 10ed8e5

Please sign in to comment.