Skip to content

Commit

Permalink
Merge branch 'feature/casl-permission-voyage-sprints' of https://gith…
Browse files Browse the repository at this point in the history
…ub.com/chingu-x/chingu-dashboard-be into feature/casl-permission-voyage-sprints
  • Loading branch information
Ajen07 committed Sep 1, 2024
2 parents a9142c4 + e687ebc commit 24d24ff
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Another example [here](https://co-pilot.dev/changelog)
- Fix form responses giving error and not inserting values when the boolean value is false ([#156](https://github.com/chingu-x/chingu-dashboard-be/pull/156))
- Fix a bug for check on voyageTeamMemberId ([#159](https://github.com/chingu-x/chingu-dashboard-be/pull/159))
- Fix users unit test failing due to a schema change
- Fix seed data for alpha test (check in form question changes, gravatar) ([#190](https://github.com/chingu-x/chingu-dashboard-be/pull/190))

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[name]` on the table `OAuthProvider` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "OAuthProvider_name_key" ON "OAuthProvider"("name");
35 changes: 18 additions & 17 deletions prisma/production-seed/users.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prisma } from "../seed/prisma-client";
import { hashPassword } from "../../src/utils/auth";
import { getRoleId } from "../seed/users";
import { generateGravatarUrl } from "../seed/utils";

export const populateUsersProd = async () => {
const roles = await prisma.role.findMany({});
Expand All @@ -13,7 +14,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Admin",
lastName: "Surname",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("admin@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -34,7 +35,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Jim",
lastName: "PO",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("jim@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -54,7 +55,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Razieh",
lastName: "PO",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("razieh@example.com"),
timezone: "Europe/Madrid",
countryCode: "ES",
},
Expand All @@ -74,7 +75,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Mladen",
lastName: "PO",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("mladen@example.com"),
timezone: "Europe/Madrid",
countryCode: "ES",
},
Expand All @@ -96,7 +97,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Eury",
lastName: "Design",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("eury@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -116,7 +117,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Joe",
lastName: "Design",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("joe@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -136,7 +137,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Joseph",
lastName: "Design",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("joseph@example.com"),
timezone: "America/Lima",
countryCode: "PE",
},
Expand All @@ -156,7 +157,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Austin",
lastName: "Design",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("austin@example.com"),
timezone: "US/Pacific",
countryCode: "US",
},
Expand All @@ -178,7 +179,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Dan",
lastName: "Frontend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("dan@example.com"),
timezone: "US/Eastern",
countryCode: "US",
},
Expand All @@ -198,7 +199,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Jane",
lastName: "Frontend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("jane@example.com"),
timezone: "Asia/Tbilisi",
countryCode: "GE",
},
Expand All @@ -218,7 +219,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Timothy",
lastName: "Frontend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("timothy@example.com"),
timezone: "Europe/Rome",
countryCode: "IT",
},
Expand All @@ -238,7 +239,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Winnie",
lastName: "Frontend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("winnie@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -260,7 +261,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Cheryl",
lastName: "Backend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("cheryl@example.com"),
timezone: "Australia/Melbourne",
countryCode: "AU",
},
Expand All @@ -280,7 +281,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Curt",
lastName: "Backend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("curt@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -300,7 +301,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Josh",
lastName: "Backend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("josh@example.com"),
timezone: "US/Pacific",
countryCode: "US",
},
Expand All @@ -320,7 +321,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Tim",
lastName: "Backend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("tim@example.com"),
timezone: "US/Central",
countryCode: "US",
},
Expand All @@ -340,7 +341,7 @@ export const populateUsersProd = async () => {
emailVerified: true,
firstName: "Arman",
lastName: "Backend",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("arman@example.com"),
timezone: "Asia/Kolkata",
countryCode: "IN",
},
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema/user.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ model UserRole {

model OAuthProvider {
id Int @id @default(autoincrement())
name String
name String @unique
createdAt DateTime @default(now()) @db.Timestamptz()
updatedAt DateTime @updatedAt
Expand Down
45 changes: 3 additions & 42 deletions prisma/seed/forms/checkinform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ export const populateCheckinForm = async () => {
name: "teamMembersCheckbox",
},
},
text: "Is there anyone on your team who has not been super helpful, kind, hard-working, etc. and deserves a shout-out in the Chingu Weekly? If so, please add his/her Discord username here:",
text: "Is there anyone on your team who has been super helpful, kind, hard-working, etc. and deserves a shout-out in the Chingu Weekly? If so, please add his/her Discord username here:",
answerRequired: false,
},
{
order: 9,
inputType: {
connect: {
name: "text",
name: "teamMembersCheckbox",
},
},
text: "Please share any personal or team achievements this week here. (ex. held a meeting, teammate got a job, had a pair programming session, learned a valuable team lesson, solved a challenging problem).",
Expand Down Expand Up @@ -235,49 +235,10 @@ export const populateCheckinForm = async () => {
},
},
text: "Is there anything else you'd like to tell us about your Voyage Guide?",
answerRequired: true,
answerRequired: false,
},
{
order: 12,
inputType: {
connect: {
name: "radio",
},
},
text: "What is your role in your team?",
answerRequired: true,
optionGroup: {
create: {
name: "checkin-form-role",
optionChoices: {
createMany: {
data: [
{
text: "Product Owner",
},
{
text: "Scrum Master",
},
{
text: "Web Developer",
},
{
text: "UI/UX Designer",
},
{
text: "Data Scientist",
},
{
text: "Voyage Guide",
},
],
},
},
},
},
},
{
order: 13,
inputType: {
connect: {
name: "text",
Expand Down
31 changes: 24 additions & 7 deletions prisma/seed/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { hashPassword } from "../../src/utils/auth";
import { prisma } from "./prisma-client";
import { generateGravatarUrl } from "./utils";

export const getRoleId = (roles, name) => {
return roles.filter((role) => role.name == name)[0].id;
Expand All @@ -15,14 +16,30 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Jessica",
lastName: "Williamson",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("jessica.williamson@gmail.com"),
timezone: "Australia/Melbourne",
countryCode: "AU",
gender: {
connect: {
abbreviation: "F",
},
},
oAuthProfiles: {
create: {
providerUserId: "1234567",
providerUsername: "jessica-discord",
provider: {
connectOrCreate: {
where: {
name: "discord",
},
create: {
name: "discord",
},
},
},
},
},
},
});

Expand All @@ -47,7 +64,7 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Larry",
lastName: "Castro",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x",
avatar: generateGravatarUrl("l.castro@outlook.com"),
timezone: "America/Chicago",
comment: "Member seems to be inactive",
countryCode: "US",
Expand Down Expand Up @@ -80,7 +97,7 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Leonarda",
lastName: "Rowe",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x",
avatar: generateGravatarUrl("leo.rowe@outlook.com"),
timezone: "America/Los_Angeles",
comment: "This is a random admin comment",
countryCode: "US",
Expand All @@ -106,7 +123,7 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Joso",
lastName: "Mađar",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
avatar: generateGravatarUrl("JosoMadar@dayrep.com"),
timezone: "Europe/Zagreb",
comment: "This is a random admin comment",
countryCode: "HR",
Expand All @@ -127,7 +144,7 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Dan",
lastName: "Ko",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
avatar: generateGravatarUrl("dan@random.com"),
timezone: "America/Los_Angeles",
comment: "No comment",
countryCode: "US",
Expand All @@ -148,7 +165,7 @@ export const populateUsers = async () => {
emailVerified: true,
firstName: "Not in a voyage",
lastName: "Voyage",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
avatar: generateGravatarUrl("not_in_voyage@example.com"),
timezone: "America/New_York",
comment:
"This user is not in a voyage - does not have the 'voyager' role",
Expand All @@ -163,7 +180,7 @@ export const populateUsers = async () => {
emailVerified: false,
firstName: "Yoshi",
lastName: "Amano",
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
avatar: generateGravatarUrl("yoshi@gmail.com"),
timezone: "Australia/Melbourne",
countryCode: "AU",
gender: {
Expand Down
8 changes: 8 additions & 0 deletions prisma/seed/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { prisma } from "../prisma-client";
import * as crypto from "crypto";

export const addDays = (date, days: number) => {
const newDate = new Date(date);
Expand Down Expand Up @@ -26,3 +27,10 @@ export const getRandomDateDuringSprint = async (sprintId) => {
});
return addDays(sprint?.startDate, Math.floor(Math.random() * 6));
};

export const generateGravatarUrl = (email: string = "noemail@example.com") => {
const themes = ["identicon", "monsterid", "wavatar", "retro", "robohash"];
const hash = crypto.createHash("sha256").update(email).digest("hex");
return `https://gravatar.com/avatar/${hash}?s=200&r=g&d=${themes[Math.floor(Math.random() * themes.length)]}
`;
};

0 comments on commit 24d24ff

Please sign in to comment.