-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweaks to invitation codes from review feedback.
- Move to a dedicated model. This prevents invitation codes from leaking unintentionally as part of the hunt, and also lets us track old code generation, who generated codes, etc. - Change invitation view from a link to plain text with a Copy to Clipboard button.
- Loading branch information
Showing
11 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { z } from "zod"; | ||
import type { ModelType } from "./Model"; | ||
import SoftDeletedModel from "./SoftDeletedModel"; | ||
import { foreignKey, nonEmptyString } from "./customTypes"; | ||
import withCommon from "./withCommon"; | ||
|
||
// Invitation codes that can be used to join a hunt. | ||
// These take the place of direct (user-to-user) invitations. | ||
export const InvitationCode = withCommon( | ||
z.object({ | ||
hunt: foreignKey, | ||
code: nonEmptyString, | ||
}), | ||
); | ||
|
||
const InvitationCodes = new SoftDeletedModel( | ||
"jr_invitation_codes", | ||
InvitationCode, | ||
); | ||
InvitationCodes.addIndex({ hunt: 1 }); | ||
InvitationCodes.addIndex({ code: 1 }); | ||
export type InvitationCodeType = ModelType<typeof InvitationCodes>; | ||
|
||
export default InvitationCodes; |
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,5 @@ | ||
import TypedPublication from "./TypedPublication"; | ||
|
||
export default new TypedPublication<{ huntId: string }>( | ||
"InvitationCodes.publications.forHunt", | ||
); |
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,5 @@ | ||
import TypedMethod from "./TypedMethod"; | ||
|
||
export default new TypedMethod<{ huntId: string }, string>( | ||
"fetchHuntInvitationCode", | ||
); |
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
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
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,32 @@ | ||
import { check } from "meteor/check"; | ||
import Hunts from "../../lib/models/Hunts"; | ||
import InvitationCodes from "../../lib/models/InvitationCodes"; | ||
import MeteorUsers from "../../lib/models/MeteorUsers"; | ||
import { userMayAddUsersToHunt } from "../../lib/permission_stubs"; | ||
import invitationCodesForHunt from "../../lib/publications/invitationCodesForHunt"; | ||
import definePublication from "./definePublication"; | ||
|
||
definePublication(invitationCodesForHunt, { | ||
validate(arg) { | ||
check(arg, { | ||
huntId: String, | ||
}); | ||
return arg; | ||
}, | ||
|
||
async run({ huntId }) { | ||
if (!this.userId) { | ||
return []; | ||
} | ||
|
||
const user = await MeteorUsers.findOneAsync(this.userId); | ||
const hunt = await Hunts.findOneAsync({ _id: huntId }); | ||
if (!userMayAddUsersToHunt(user, hunt)) { | ||
return []; | ||
} | ||
|
||
return InvitationCodes.find({ | ||
hunt: huntId, | ||
}); | ||
}, | ||
}); |