-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Allow users to view admin-owned websites #4330
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,24 @@ export async function getWebsite(websiteId: string) { | |
| return attachShareIdToWebsite(website); | ||
| } | ||
|
|
||
| export async function isAdminOwnedWebsite(websiteId: string) { | ||
| const website = await prisma.client.website.findFirst({ | ||
| where: { | ||
| id: websiteId, | ||
| deletedAt: null, | ||
| user: { | ||
| role: ROLES.admin, | ||
| deletedAt: null, | ||
| }, | ||
| }, | ||
| select: { | ||
| id: true, | ||
| }, | ||
| }); | ||
|
|
||
| return !!website; | ||
| } | ||
|
|
||
| export async function getWebsites(criteria: Prisma.WebsiteFindManyArgs, filters: QueryFilters) { | ||
| const { search } = filters; | ||
| const { getSearchParameters, pagedQuery } = prisma; | ||
|
|
@@ -48,6 +66,12 @@ export async function getAllUserWebsitesIncludingTeamOwner(userId: string, filte | |
| where: { | ||
| OR: [ | ||
| { userId }, | ||
| { | ||
| user: { | ||
| role: ROLES.admin, | ||
| deletedAt: null, | ||
| }, | ||
| }, | ||
| { | ||
| team: { | ||
| deletedAt: null, | ||
|
|
@@ -91,6 +115,36 @@ export async function getUserWebsites(userId: string, filters?: QueryFilters) { | |
| ); | ||
| } | ||
|
|
||
| export async function getUserWebsitesIncludingAdminOwned(userId: string, filters?: QueryFilters) { | ||
| return getWebsites( | ||
| { | ||
| where: { | ||
| OR: [ | ||
| { userId }, | ||
| { | ||
| user: { | ||
| role: ROLES.admin, | ||
| deletedAt: null, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| include: { | ||
| user: { | ||
| select: { | ||
| username: true, | ||
| id: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| orderBy: 'name', | ||
| ...filters, | ||
| }, | ||
| ); | ||
| } | ||
|
Comment on lines
+118
to
+146
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| export async function getTeamWebsites(teamId: string, filters?: QueryFilters) { | ||
| return getWebsites( | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAdminOwnedWebsiteonly checks whether the website's owner has the admin role — it does not verify any relationship between the requesting user and that admin. Any authenticated non-admin user can now directly view the data of every website owned by any admin account simply by knowing (or guessing) its ID. There is no per-website opt-in or per-admin sharing intent captured here; if an admin has websites intended to remain private, this check will still returntrueand grant access to all authenticated users.