feat: add public read-only sharing for computers
Adds the ability for an owner to share a computer build via a public, unauthenticated link, inspired by a feature request from the original pcbuilder repo (no such feature actually existed there — implemented from scratch here). - New columns on computers: share_token (unique, nullable), share_enabled, share_show_sell_price, share_show_cost - computer_share_service.ts: generates a non-guessable share token (crypto.randomBytes, base64url), enables/disables sharing, and supports rotating the token to invalidate previously distributed links - ComputerShareController (authenticated, owner-scoped like the rest of the app): PUT /computers/:id/share to update settings, POST /computers/:id/share/rotate to rotate the token - PublicComputerController + GET /share/:token (outside any auth/guest group, reachable anonymously): resolves only computers with share_enabled = true, 404 otherwise - ComputerPublicTransformer: dedicated read-only projection that never leaks userId, and only includes sellPrice/cost when the owner opted in via share_show_sell_price / share_show_cost — everything else (title, scores, state, components, pictures) is always visible on a shared link - ComputerShareModal.vue: owner-facing UI (toggle sharing, choose which prices to expose, copy the public link, revoke/rotate it) wired into computers/show.vue via a new 'Share' button - share/show.vue: public page rendered with EmptyLayout (no authenticated header/sidebar) - Boolean columns use a cast since MySQL returns tinyint(1), not native booleans, through Lucid - 6 new functional tests covering: enabling sharing, price visibility toggles, disabling sharing revokes the link, cross-user protection on the share settings endpoint (404), token rotation invalidating the old link, and anonymous access to a shared computer
This commit is contained in:
1 parent
84ae2b9617
commit
da71d33450
22 files changed
+714
-8
No files matched your search
Vendored
+5
@@ -6,10 +6,15 @@
|
||||
/// <reference path="./manifest.d.ts" />
|
||||
import type { InferData, InferVariants } from '@adonisjs/core/types/transformers'
|
||||
import type { InferSharedProps } from '@adonisjs/inertia/types'
|
||||
import type ComputerPublicTransformer from '#transformers/computer_public_transformer'
|
||||
import type UserTransformer from '#transformers/user_transformer'
|
||||
import type InertiaMiddleware from '#middleware/inertia_middleware'
|
||||
|
||||
export namespace Data {
|
||||
export type ComputerPublic = InferData<ComputerPublicTransformer>
|
||||
export namespace ComputerPublic {
|
||||
export type Variants = InferVariants<ComputerPublicTransformer>
|
||||
}
|
||||
export type User = InferData<UserTransformer>
|
||||
export namespace User {
|
||||
export type Variants = InferVariants<UserTransformer>
|
||||
|
||||
@@ -84,6 +84,24 @@ const routes = {
|
||||
tokens: [{"old":"/computers/:id","type":0,"val":"computers","end":""},{"old":"/computers/:id","type":1,"val":"id","end":""}],
|
||||
types: placeholder as Registry['computers.destroy']['types'],
|
||||
},
|
||||
'computers.share.update': {
|
||||
methods: ["PUT"],
|
||||
pattern: '/computers/:id/share',
|
||||
tokens: [{"old":"/computers/:id/share","type":0,"val":"computers","end":""},{"old":"/computers/:id/share","type":1,"val":"id","end":""},{"old":"/computers/:id/share","type":0,"val":"share","end":""}],
|
||||
types: placeholder as Registry['computers.share.update']['types'],
|
||||
},
|
||||
'computers.share.rotate': {
|
||||
methods: ["POST"],
|
||||
pattern: '/computers/:id/share/rotate',
|
||||
tokens: [{"old":"/computers/:id/share/rotate","type":0,"val":"computers","end":""},{"old":"/computers/:id/share/rotate","type":1,"val":"id","end":""},{"old":"/computers/:id/share/rotate","type":0,"val":"share","end":""},{"old":"/computers/:id/share/rotate","type":0,"val":"rotate","end":""}],
|
||||
types: placeholder as Registry['computers.share.rotate']['types'],
|
||||
},
|
||||
'share.show': {
|
||||
methods: ["GET","HEAD"],
|
||||
pattern: '/share/:token',
|
||||
tokens: [{"old":"/share/:token","type":0,"val":"share","end":""},{"old":"/share/:token","type":1,"val":"token","end":""}],
|
||||
types: placeholder as Registry['share.show']['types'],
|
||||
},
|
||||
'components.index': {
|
||||
methods: ["GET","HEAD"],
|
||||
pattern: '/components',
|
||||
|
||||
+36
@@ -163,6 +163,42 @@ export interface Registry {
|
||||
errorResponse: ExtractErrorResponse<Awaited<ReturnType<import('#controllers/computers_controller').default['destroy']>>>
|
||||
}
|
||||
}
|
||||
'computers.share.update': {
|
||||
methods: ["PUT"]
|
||||
pattern: '/computers/:id/share'
|
||||
types: {
|
||||
body: ExtractBody<InferInput<(typeof import('#validators/Computers/share').updateShareSettingsValidator)>>
|
||||
paramsTuple: [ParamValue]
|
||||
params: { id: ParamValue }
|
||||
query: ExtractQuery<InferInput<(typeof import('#validators/Computers/share').updateShareSettingsValidator)>>
|
||||
response: ExtractResponse<Awaited<ReturnType<import('#controllers/computer_share_controller').default['update']>>>
|
||||
errorResponse: ExtractErrorResponse<Awaited<ReturnType<import('#controllers/computer_share_controller').default['update']>>> | { status: 422; response: { errors: SimpleError[] } }
|
||||
}
|
||||
}
|
||||
'computers.share.rotate': {
|
||||
methods: ["POST"]
|
||||
pattern: '/computers/:id/share/rotate'
|
||||
types: {
|
||||
body: {}
|
||||
paramsTuple: [ParamValue]
|
||||
params: { id: ParamValue }
|
||||
query: {}
|
||||
response: ExtractResponse<Awaited<ReturnType<import('#controllers/computer_share_controller').default['rotate']>>>
|
||||
errorResponse: ExtractErrorResponse<Awaited<ReturnType<import('#controllers/computer_share_controller').default['rotate']>>>
|
||||
}
|
||||
}
|
||||
'share.show': {
|
||||
methods: ["GET","HEAD"]
|
||||
pattern: '/share/:token'
|
||||
types: {
|
||||
body: {}
|
||||
paramsTuple: [ParamValue]
|
||||
params: { token: ParamValue }
|
||||
query: {}
|
||||
response: ExtractResponse<Awaited<ReturnType<import('#controllers/public_computer_controller').default['show']>>>
|
||||
errorResponse: ExtractErrorResponse<Awaited<ReturnType<import('#controllers/public_computer_controller').default['show']>>>
|
||||
}
|
||||
}
|
||||
'components.index': {
|
||||
methods: ["GET","HEAD"]
|
||||
pattern: '/components'
|
||||
|
||||
Vendored
+7
@@ -20,6 +20,13 @@ export interface ApiDefinition {
|
||||
edit: typeof routes['computers.edit']
|
||||
update: typeof routes['computers.update']
|
||||
destroy: typeof routes['computers.destroy']
|
||||
share: {
|
||||
update: typeof routes['computers.share.update']
|
||||
rotate: typeof routes['computers.share.rotate']
|
||||
}
|
||||
}
|
||||
share: {
|
||||
show: typeof routes['share.show']
|
||||
}
|
||||
components: {
|
||||
index: typeof routes['components.index']
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
export const controllers = {
|
||||
Components: () => import('#controllers/components_controller'),
|
||||
ComputerShare: () => import('#controllers/computer_share_controller'),
|
||||
Computers: () => import('#controllers/computers_controller'),
|
||||
NewAccount: () => import('#controllers/new_account_controller'),
|
||||
PublicComputer: () => import('#controllers/public_computer_controller'),
|
||||
Session: () => import('#controllers/session_controller'),
|
||||
}
|
||||
Vendored
+2
@@ -26,11 +26,13 @@ declare module '@adonisjs/inertia/types' {
|
||||
'layout/emptyLayout': ExtractProps<(typeof import('../../inertia/pages/layout/emptyLayout.vue'))['default']>
|
||||
'layout/header': ExtractProps<(typeof import('../../inertia/pages/layout/header.vue'))['default']>
|
||||
'layout/sidebar': ExtractProps<(typeof import('../../inertia/pages/layout/sidebar.vue'))['default']>
|
||||
'share/show': ExtractProps<(typeof import('../../inertia/pages/share/show.vue'))['default']>
|
||||
'widgets/AuthErrorAlert': ExtractProps<(typeof import('../../inertia/pages/widgets/AuthErrorAlert.vue'))['default']>
|
||||
'widgets/ComponentEditor': ExtractProps<(typeof import('../../inertia/pages/widgets/ComponentEditor.vue'))['default']>
|
||||
'widgets/ComponentsViewer': ExtractProps<(typeof import('../../inertia/pages/widgets/ComponentsViewer.vue'))['default']>
|
||||
'widgets/ComputerCard': ExtractProps<(typeof import('../../inertia/pages/widgets/ComputerCard.vue'))['default']>
|
||||
'widgets/ComputerComponentsTable': ExtractProps<(typeof import('../../inertia/pages/widgets/ComputerComponentsTable.vue'))['default']>
|
||||
'widgets/ComputerShareModal': ExtractProps<(typeof import('../../inertia/pages/widgets/ComputerShareModal.vue'))['default']>
|
||||
'widgets/ComputersViewer': ExtractProps<(typeof import('../../inertia/pages/widgets/ComputersViewer.vue'))['default']>
|
||||
'widgets/CustomSelect': ExtractProps<(typeof import('../../inertia/pages/widgets/CustomSelect.vue'))['default']>
|
||||
'widgets/DeleteConfirmationModal': ExtractProps<(typeof import('../../inertia/pages/widgets/DeleteConfirmationModal.vue'))['default']>
|
||||
|
||||
Vendored
+7
@@ -17,6 +17,9 @@ export type ScannedRoutes = {
|
||||
'computers.edit': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.update': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.destroy': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.share.update': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.share.rotate': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'share.show': { paramsTuple: [ParamValue]; params: {'token': ParamValue} }
|
||||
'components.index': { paramsTuple?: []; params?: {} }
|
||||
'components.create': { paramsTuple?: []; params?: {} }
|
||||
'components.store': { paramsTuple?: []; params?: {} }
|
||||
@@ -33,6 +36,7 @@ export type ScannedRoutes = {
|
||||
'computers.create': { paramsTuple?: []; params?: {} }
|
||||
'computers.show': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.edit': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'share.show': { paramsTuple: [ParamValue]; params: {'token': ParamValue} }
|
||||
'components.index': { paramsTuple?: []; params?: {} }
|
||||
'components.create': { paramsTuple?: []; params?: {} }
|
||||
'components.show': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
@@ -46,6 +50,7 @@ export type ScannedRoutes = {
|
||||
'computers.create': { paramsTuple?: []; params?: {} }
|
||||
'computers.show': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.edit': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'share.show': { paramsTuple: [ParamValue]; params: {'token': ParamValue} }
|
||||
'components.index': { paramsTuple?: []; params?: {} }
|
||||
'components.create': { paramsTuple?: []; params?: {} }
|
||||
'components.show': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
@@ -56,10 +61,12 @@ export type ScannedRoutes = {
|
||||
'session.store': { paramsTuple?: []; params?: {} }
|
||||
'session.destroy': { paramsTuple?: []; params?: {} }
|
||||
'computers.store': { paramsTuple?: []; params?: {} }
|
||||
'computers.share.rotate': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'components.store': { paramsTuple?: []; params?: {} }
|
||||
}
|
||||
PUT: {
|
||||
'computers.update': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'computers.share.update': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
'components.update': { paramsTuple: [ParamValue]; params: {'id': ParamValue} }
|
||||
}
|
||||
DELETE: {
|
||||
|
||||
Reference in new issue
Block a user