-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Init refactor target -> resource #213
Changes from 1 commit
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 |
---|---|---|
|
@@ -44,7 +44,7 @@ export const PATCH = request() | |
authz(({ can, extra }) => | ||
can | ||
.perform(Permission.TargetUpdate) | ||
.on({ type: "targetProvider", id: extra.params.providerId }), | ||
.on({ type: "resourceProvider", id: extra.params.providerId }), | ||
), | ||
) | ||
.handle< | ||
|
@@ -60,7 +60,7 @@ export const PATCH = request() | |
.where(eq(targetProvider.id, params.providerId)) | ||
.then(takeFirstOrNull); | ||
|
||
const provider = query?.target_provider; | ||
const provider = query?.resource_provider; | ||
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. Inconsistent terminology between schema and variable names The variable has been renamed to Either:
-const provider = query?.resource_provider;
+const provider = query?.target_provider;
|
||
if (!provider) | ||
return NextResponse.json( | ||
{ error: "Provider not found" }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ export const GET = request() | |
if (target == null) return false; | ||
return can | ||
.perform(Permission.TargetGet) | ||
.on({ type: "target", id: target.id }); | ||
.on({ type: "resource", id: target.id }); | ||
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. 💡 Codebase verification Permission naming inconsistency detected across the codebase The verification reveals that while authorization types have been updated from "target" to "resource", the Permission enum still extensively uses "Target" prefixes across the codebase. Found inconsistencies:
🔗 Analysis chainVerify permission naming consistency While the authorization type has been updated to "resource", the permission enum still uses 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if Permission enum still uses "Target" prefix across the codebase
# and if there are any pending renames needed for consistency
# Search for Permission enum definition and usages
ast-grep --pattern 'enum Permission {
$$$
}'
# Search for any remaining "Target" prefixed permissions
rg "Permission\.Target" -A 1
Length of output: 9241 |
||
}), | ||
) | ||
.handle<unknown, { params: { workspaceId: string; identifier: string } }>( | ||
|
@@ -72,7 +72,7 @@ export const DELETE = request() | |
if (target == null) return false; | ||
return can | ||
.perform(Permission.TargetDelete) | ||
.on({ type: "target", id: target.id }); | ||
.on({ type: "resource", id: target.id }); | ||
}), | ||
) | ||
.handle<unknown, { params: { workspaceId: string; identifier: string } }>( | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -119,7 +119,7 @@ export const releaseRouter = createTRPCRouter({ | |||||
.map((j) => ({ | ||||||
...j.release_job_trigger, | ||||||
job: j.job, | ||||||
target: j.target, | ||||||
target: j.resource, | ||||||
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. 🛠️ Refactor suggestion Maintain consistency in the target -> resource refactoring While the value has been updated to use Apply this change: - target: j.resource,
+ resource: j.resource, 📝 Committable suggestion
Suggested change
|
||||||
})), | ||||||
})); | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ export const targetProviderRouter = createTRPCRouter({ | |
.where( | ||
inArray( | ||
target.providerId, | ||
providers.map((p) => p.target_provider.id), | ||
providers.map((p) => p.resource_provider.id), | ||
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. Critical: Schema and property access mismatch The code attempts to access properties using Apply this fix to align with the imported schema names: - providers.map((p) => p.resource_provider.id)
+ providers.map((p) => p.target_provider.id)
- ...provider.resource_provider,
- googleConfig: provider.resource_provider_google,
+ ...provider.target_provider,
+ googleConfig: provider.target_provider_google,
- (pc) => pc.providerId === provider.resource_provider.id,
+ (pc) => pc.providerId === provider.target_provider.id,
- .filter((pk) => pk.providerId === provider.resource_provider.id)
+ .filter((pk) => pk.providerId === provider.target_provider.id) Also applies to: 64-64, 71-72, 75-75, 78-78 |
||
), | ||
) | ||
.groupBy(target.providerId); | ||
|
@@ -61,21 +61,21 @@ export const targetProviderRouter = createTRPCRouter({ | |
.where( | ||
inArray( | ||
target.providerId, | ||
providers.map((p) => p.target_provider.id), | ||
providers.map((p) => p.resource_provider.id), | ||
), | ||
) | ||
.groupBy(target.providerId, target.kind, target.version) | ||
.orderBy(sql`count(*) DESC`); | ||
|
||
return providers.map((provider) => ({ | ||
...provider.target_provider, | ||
googleConfig: provider.target_provider_google, | ||
...provider.resource_provider, | ||
googleConfig: provider.resource_provider_google, | ||
targetCount: | ||
providerCounts.find( | ||
(pc) => pc.providerId === provider.target_provider.id, | ||
(pc) => pc.providerId === provider.resource_provider.id, | ||
)?.count ?? 0, | ||
kinds: providerKinds | ||
.filter((pk) => pk.providerId === provider.target_provider.id) | ||
.filter((pk) => pk.providerId === provider.resource_provider.id) | ||
.map(({ kind, version, count }) => ({ kind, version, count })), | ||
})); | ||
}), | ||
|
@@ -85,7 +85,7 @@ export const targetProviderRouter = createTRPCRouter({ | |
authorizationCheck: ({ canUser, input }) => | ||
canUser | ||
.perform(Permission.TargetList) | ||
.on({ type: "targetProvider", id: input }), | ||
.on({ type: "resourceProvider", id: input }), | ||
}) | ||
.input(z.string().uuid()) | ||
.query(({ ctx, input }) => | ||
|
@@ -102,7 +102,7 @@ export const targetProviderRouter = createTRPCRouter({ | |
authorizationCheck: ({ canUser, input }) => | ||
canUser | ||
.perform(Permission.TargetProviderUpdate) | ||
.on({ type: "targetProvider", id: input }), | ||
.on({ type: "resourceProvider", id: input }), | ||
}) | ||
.input(z.string().uuid()) | ||
.mutation(async ({ input }) => | ||
|
@@ -209,7 +209,7 @@ export const targetProviderRouter = createTRPCRouter({ | |
authorizationCheck: ({ canUser, input }) => | ||
canUser | ||
.perform(Permission.TargetDelete) | ||
.on({ type: "targetProvider", id: input.providerId }), | ||
.on({ type: "resourceProvider", id: input.providerId }), | ||
}) | ||
.input( | ||
z.object({ | ||
|
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.
💡 Codebase verification
Inconsistent authorization type with Permission enum
The authorization type has been changed to "resourceProvider" but this is inconsistent with the Permission enum which still uses "target" prefixes. The code is using
Permission.TargetUpdate
but checking againsttype: "resourceProvider"
, creating a mismatch in the authorization system.packages/validators/src/auth/index.ts
: Permission enum still usesTargetUpdate
,TargetProviderUpdate
, etc.apps/webservice/src/app/api/v1/target-providers/[providerId]/set/route.ts
: UsesPermission.TargetUpdate
withtype: "resourceProvider"
This inconsistency could lead to authorization failures and needs to be addressed by either:
🔗 Analysis chain
Verify permission enum consistency
The authorization type has been changed to "resourceProvider", but we need to verify if this matches the Permission enum which still uses
TargetUpdate
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 121
Script:
Length of output: 22718