Skip to content

Commit c41aa6c

Browse files
committed
Foundation for jobs, events, learning paths, media, e-mails and sponsors
- Tables and models: jobs, events + registrations, learning paths / steps / progress, media, user tokens (password reset, e-mail verification), sponsors, tag pages body, e-mail preferences and locale on users - Generic notifications with their own sentence and link - Navigation entries (Emplois, Événements, Apprendre, with a "Plus" menu below 1280px) and admin entries; shared captcha key and e-mail status - Mailer entry point (logs until the mail integration lands)
1 parent 5541409 commit c41aa6c

34 files changed

Lines changed: 974 additions & 12 deletions

‎app/controllers/notifications_controller.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { safeRedirectPath } from '#services/safe_redirect'
12
import type { HttpContext } from '@adonisjs/core/http'
23
import { DateTime } from 'luxon'
34
import db from '@adonisjs/lucid/services/db'
@@ -41,6 +42,9 @@ async function replyPage(
4142
* Where a notification leads: the exact reply, on the right page.
4243
*/
4344
async function targetOf(notification: Notification) {
45+
// Generic notifications (jobs, events) carry their own same-site link.
46+
if (notification.url) return safeRedirectPath(notification.url, '') || null
47+
4448
const anchor = notification.replyId ? `#reponse-${notification.replyId}` : ''
4549

4650
if (notification.threadId !== null) {

‎app/middleware/inertia_middleware.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class InertiaMiddleware extends BaseInertiaMiddleware {
5353
preferences: ctx.inertia.always({ theme }),
5454
features: ctx.inertia.always(socialFeatures()),
5555
site: ctx.inertia.always({ url: env.get('APP_URL') }),
56+
captcha: ctx.inertia.always({ siteKey: env.get('TURNSTILE_SITE_KEY') ?? null }),
5657
unreadNotifications: ctx.inertia.always(unreadNotifications),
5758
reportQueueCount: ctx.inertia.always(reportQueueCount),
5859
}

‎app/models/event.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { EventSchema } from '#database/schema'
2+
import { belongsTo, hasMany } from '@adonisjs/lucid/orm'
3+
import type { BelongsTo, HasMany } from '@adonisjs/lucid/types/relations'
4+
import User from '#models/user'
5+
import EventRegistration from '#models/event_registration'
6+
7+
export default class Event extends EventSchema {
8+
@belongsTo(() => User)
9+
declare organizer: BelongsTo<typeof User>
10+
11+
@hasMany(() => EventRegistration)
12+
declare registrations: HasMany<typeof EventRegistration>
13+
}

‎app/models/event_registration.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { EventRegistrationSchema } from '#database/schema'
2+
import { belongsTo } from '@adonisjs/lucid/orm'
3+
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
4+
import User from '#models/user'
5+
import Event from '#models/event'
6+
7+
export default class EventRegistration extends EventRegistrationSchema {
8+
@belongsTo(() => Event)
9+
declare event: BelongsTo<typeof Event>
10+
11+
@belongsTo(() => User)
12+
declare user: BelongsTo<typeof User>
13+
}

‎app/models/job.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { DateTime } from 'luxon'
2+
import { JobSchema } from '#database/schema'
3+
import { belongsTo, scope } from '@adonisjs/lucid/orm'
4+
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
5+
import User from '#models/user'
6+
7+
export default class Job extends JobSchema {
8+
@belongsTo(() => User)
9+
declare poster: BelongsTo<typeof User>
10+
11+
/**
12+
* Published and not expired: what the public board shows.
13+
*/
14+
static visible = scope((query) => {
15+
query
16+
.where('status', 'published')
17+
.where((q) => q.whereNull('expires_at').orWhere('expires_at', '>', DateTime.now().toSQL()!))
18+
})
19+
20+
get isFeatured() {
21+
return this.featuredUntil !== null && this.featuredUntil > DateTime.now()
22+
}
23+
}

‎app/models/learning_path.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LearningPathSchema } from '#database/schema'
2+
import { hasMany } from '@adonisjs/lucid/orm'
3+
import type { HasMany } from '@adonisjs/lucid/types/relations'
4+
import LearningStep from '#models/learning_step'
5+
6+
/**
7+
* Member progress lives in the "learning_progress" table (composite key
8+
* user_id + step_id): query it with the db query builder.
9+
*/
10+
export default class LearningPath extends LearningPathSchema {
11+
@hasMany(() => LearningStep, { foreignKey: 'pathId' })
12+
declare steps: HasMany<typeof LearningStep>
13+
}

‎app/models/learning_step.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LearningStepSchema } from '#database/schema'
2+
import { belongsTo } from '@adonisjs/lucid/orm'
3+
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
4+
import LearningPath from '#models/learning_path'
5+
import Article from '#models/article'
6+
7+
export default class LearningStep extends LearningStepSchema {
8+
@belongsTo(() => LearningPath, { foreignKey: 'pathId' })
9+
declare path: BelongsTo<typeof LearningPath>
10+
11+
@belongsTo(() => Article)
12+
declare article: BelongsTo<typeof Article>
13+
}

‎app/models/media.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MediaSchema } from '#database/schema'
2+
import { belongsTo } from '@adonisjs/lucid/orm'
3+
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
4+
import User from '#models/user'
5+
6+
export default class Media extends MediaSchema {
7+
static table = 'media'
8+
9+
@belongsTo(() => User)
10+
declare uploader: BelongsTo<typeof User>
11+
12+
get url() {
13+
return `/media/${this.key}`
14+
}
15+
}

‎app/models/sponsor.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { SponsorSchema } from '#database/schema'
2+
3+
export default class Sponsor extends SponsorSchema {}

‎app/models/user_token.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UserTokenSchema } from '#database/schema'
2+
import { belongsTo } from '@adonisjs/lucid/orm'
3+
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
4+
import User from '#models/user'
5+
6+
/**
7+
* One-time e-mail token (password reset, e-mail verification). Only the
8+
* SHA-256 hash of the token is stored.
9+
*/
10+
export default class UserToken extends UserTokenSchema {
11+
@belongsTo(() => User)
12+
declare user: BelongsTo<typeof User>
13+
}

0 commit comments

Comments
 (0)