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

v0.2.0 #23

Merged
merged 21 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
298f5c0
Refactor authentication and authorization logic in AuthContainer.astr…
kcoderhtml Apr 27, 2024
28055ac
Update sign-in options in index.astro and join/[joinCode].astro
kcoderhtml Apr 27, 2024
3754600
feat: add org type to team id to make it unique
kcoderhtml Apr 27, 2024
10c7f71
Update team ID in seed.ts to include "slack-" prefix
kcoderhtml Apr 27, 2024
4bde15d
Merge pull request #19 from kcoderhtml/github-oauth
kcoderhtml Apr 27, 2024
3574c47
chore: fix broken and opperator in auth
kcoderhtml Apr 27, 2024
309a8d2
feat: add messaging feature for users
kcoderhtml Apr 27, 2024
9ab8775
feat: bcc users instead of emailing all directly
kcoderhtml Apr 27, 2024
284852f
feat: add last message sent protection
kcoderhtml Apr 28, 2024
786540b
Merge pull request #20 from kcoderhtml/announcements
kcoderhtml Apr 28, 2024
3fa8c3e
chore: remove seed.ts
kcoderhtml Apr 28, 2024
472acc3
chore: hide db/seed.ts
kcoderhtml Apr 28, 2024
bacf4ac
docs: update homepage
kcoderhtml Apr 28, 2024
2e1466e
chore: remove github oauth
kcoderhtml Apr 28, 2024
8c93f49
Merge pull request #21 from kcoderhtml/remove-github
kcoderhtml Apr 28, 2024
4cef2d9
feat: add initial reminder api endpoint for sending out reminders for…
kcoderhtml Apr 28, 2024
dd6f530
feat: update email sender address in remind.ts and messages.astro to …
kcoderhtml Apr 28, 2024
2622d63
feat: add footer and ending salutation
kcoderhtml Apr 28, 2024
fe96f4e
feat: added timeout to route and restart functionality
kcoderhtml Apr 28, 2024
dfdb74c
chore: refactor remind endpoint to just provide db data
kcoderhtml Apr 29, 2024
21a5093
Merge pull request #22 from kcoderhtml/reminders
kcoderhtml Apr 29, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production
Expand All @@ -23,3 +22,6 @@ pnpm-debug.log*

# Local Netlify folder
.netlify

# seed file
db/seed.ts
186 changes: 96 additions & 90 deletions auth.config.mjs
Original file line number Diff line number Diff line change
@@ -1,101 +1,107 @@
import Slack from "@auth/core/providers/slack";
import { defineConfig } from "auth-astro";
import { db, like, User, Organization } from "astro:db";
import { db, like, and, User, Organization } from "astro:db";

export default defineConfig({
providers: [
Slack({
clientId: import.meta.env.SLACK_CLIENT_ID,
clientSecret: import.meta.env.SLACK_CLIENT_SECRET,
checks: ["pkce", "nonce"],
async profile(profile) {
const role = await db
.select()
.from(User)
.where(like(User.userId, profile["https://slack.com/user_id"]));
providers: [
Slack({
clientId: import.meta.env.SLACK_CLIENT_ID,
clientSecret: import.meta.env.SLACK_CLIENT_SECRET,
checks: ["pkce", "nonce"],
async profile(profile) {
profile["https://slack.com/team_id"] =
"slack-" + profile["https://slack.com/team_id"];

if (role.length === 0) {
const users = await db
.select()
.from(User)
.where(like(User.team, profile["https://slack.com/team_id"]));
const role = await db
.select()
.from(User)
.where(
and(like(User.userId, profile["https://slack.com/user_id"])),
like(User.team, profile["https://slack.com/team_id"])
);

const organizations = await db
.select()
.from(Organization)
.where(
like(Organization.team, profile["https://slack.com/team_id"]),
);
if (role.length === 0) {
const users = await db
.select()
.from(User)
.where(like(User.team, profile["https://slack.com/team_id"]));

// check if the user is part of an organization in the db by checking if the team id is the same
if (
organizations
.map((org) => org.team)
.includes(profile["https://slack.com/team_id"])
) {
if (users.length === 0) {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
});
const organizations = await db
.select()
.from(Organization)
.where(
like(Organization.team, profile["https://slack.com/team_id"])
);

role[0] = { role: "admin" };
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
});
// check if the user is part of an organization in the db by checking if the team id is the same
if (
organizations
.map((org) => org.team)
.includes(profile["https://slack.com/team_id"])
) {
if (users.length === 0) {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
});

role[0] = { role: "user" };
}
} else {
role[0] = { role: "guest" };
}
}
role[0] = { role: "admin" };
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
});

return {
id: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
teamName: profile["https://slack.com/team_name"],
teamImage: profile["https://slack.com/team_image_230"],
role: role[0].role || "user",
};
},
}),
],
callbacks: {
jwt({ token, user }) {
if (user) {
// User is available during sign-in
token.team = user.team;
token.teamName = user.teamName;
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
}
return token;
},
session({ session, token }) {
if (token) {
// Token is available during sign-in
session.team = token.team;
session.teamName = token.teamName;
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
}
return session;
},
},
role[0] = { role: "user" };
}
} else {
role[0] = { role: "guest" };
}
}

return {
id: profile["https://slack.com/user_id"],
name: profile.name,
email: profile.email,
image: profile.picture,
team: profile["https://slack.com/team_id"],
teamName: profile["https://slack.com/team_name"],
teamImage: profile["https://slack.com/team_image_230"],
role: role[0].role || "user",
};
},
}),
],
callbacks: {
jwt({ token, user }) {
if (user) {
// User is available during sign-in
token.team = user.team;
token.teamName = user.teamName;
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
}
return token;
},
session({ session, token }) {
if (token) {
// Token is available during sign-in
session.team = token.team;
session.teamName = token.teamName;
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
}
return session;
},
},
});
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions db/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Organization = defineTable({
team: column.text({ primaryKey: true }),
name: column.text(),
image: column.text(),
lastMessageHash: column.text({ optional: true, default: "" }),
},
indexes: {
teamx: { on: ["team"], unique: true },
Expand Down
33 changes: 0 additions & 33 deletions db/seed.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"prettier": "^3.2.5",
"prettier-plugin-astro": "^0.13.0",
"tailwindcss": "^3.4.2",
"ts-md5": "^1.3.1",
"typescript": "^5.4.3"
},
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions src/components/AuthContainer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ type ExtendedSession = {
<a href="/settings" class="nav">
Settings
</a>
{
session.user.role == "admin" ? (
<>
/{" "}
<a href="/messages" class="nav">
Messages
</a>
</>
) : null
}
</nav>
</div>
</div>
Expand Down
31 changes: 31 additions & 0 deletions src/pages/api/remind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { APIRoute } from "astro"
import { db, User, Organization, Event } from "astro:db";

export const POST: APIRoute = async ({ request }) => {
// get authorization header
const auth = request.headers.get("Authorization")

if (auth === process.env.API_SECRET) {
const events = await db.select().from(Event)
const users = await db.select().from(User)
const organizations = await db.select().from(Organization)

console.log(`Found ${events.length} events and ${users.length} users`)

const eventsHappeningToday = events.filter((e) => {
const eventDate = new Date(e.date)
const now = new Date()
const diff = eventDate.getTime() - now.getTime()
const diffHours = diff / (1000 * 60 * 60)
return diffHours < 24 && diffHours > 0
})

return new Response(JSON.stringify({
ok: true, eventsHappeningToday: eventsHappeningToday, users: users, organizations: organizations
}), { status: 200 })
} else {
return new Response(JSON.stringify({
ok: false, error: "Unauthorized"
}), { status: 401 })
}
}
22 changes: 12 additions & 10 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,13 @@ import AuthContainer from "../components/AuthContainer.astro";
<tbody>
<tr>
<td>Sign-in with Slack</td>
<td
>Allows you to sign in with slack and auto asigns admins based on
slack admin status.</td
>
<td>Allows you to sign in with Slack!</td>
<td>Fully Functional!</td>
</tr>
<tr>
<td>Team Creation</td>
<td>Allows you to create a team and add team members.</td>
<td
>Fully functional but currently a manual process; working on
transitioning to a auto invite system</td
>
<td>Fully functional!</td>
</tr>
<tr>
<td>Event Scheduling</td>
Expand All @@ -75,12 +69,20 @@ import AuthContainer from "../components/AuthContainer.astro";
<tr>
<td>Team Management</td>
<td>Allows teams to manage their team members and roles.</td>
<td>WIP - Active Progress</td>
<td>Fully Functional</td>
</tr>
<tr>
<td>Team Annoucements</td>
<td
>Allows teams to make announcements to their team members via
email.</td
>
<td>Finished!</td>
</tr>
<tr>
<td>FRC Dashboard Integration</td>
<td>Enable easy adding of team members to your FRC Dashboard!</td>
<td>Next up after team management</td>
<td>WIP</td>
</tr>
</tbody>
</table>
Expand Down
Loading
Loading