Skip to content

Commit

Permalink
fix(protos): rename State to FulfillmentState
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Apr 19, 2024
1 parent a89c396 commit 4debc8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
15 changes: 11 additions & 4 deletions packages/acs-client/src/acs/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as _ from 'lodash';
import * as uuid from 'uuid';
import { Logger } from 'winston';
import { Provider as ServiceConfig } from 'nconf';
Expand Down Expand Up @@ -168,7 +169,7 @@ export function access_controlled_function<T extends ResourceList>(kwargs: {
}
}

const response = await accessRequest(
const accessResponse = await accessRequest(
subject,
resource ?? [],
kwargs.action,
Expand All @@ -179,9 +180,16 @@ export function access_controlled_function<T extends ResourceList>(kwargs: {
}
);

if (response?.decision !== Response_Decision.PERMIT) {
return response;
if (accessResponse?.decision !== Response_Decision.PERMIT) {
return accessResponse;
}

const appResponse = await method.apply(this, arguments);
const property = accessResponse.obligations?.flatMap(
obligation => obligation.property
);

return appResponse //_.omitDeep(appResponse, property);
}
catch (err) {
return {
Expand All @@ -192,7 +200,6 @@ export function access_controlled_function<T extends ResourceList>(kwargs: {
}
};
}
return await method.apply(this, arguments);
};
};
}
Expand Down
15 changes: 8 additions & 7 deletions packages/acs-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const checkSubjectMatch = (user: ResolvedSubject, ruleSubjectAttributes: Attribu
// 2) Now check if the subject rule role value matches with one of the users ctx role_associations
// then get the corresponding scope instance and check if the targetScope is present in user HR scope Object
let hierarchicalRoleScopingCheck = 'true'; // by default HR scoping check is considered
let ruleRoleValue;
let ruleRoleScopeEntityName;
let ruleRoleValue: string;
let ruleRoleScopeEntityName: string;
const urns = cfg.get('authorization:urns');
if (ruleSubjectAttributes?.length === 0) {
return true;
Expand All @@ -94,7 +94,8 @@ const checkSubjectMatch = (user: ResolvedSubject, ruleSubjectAttributes: Attribu
const matchingRoleScopedInstance: string[] = user?.role_associations?.filter((roleObj) => {
return roleObj?.attributes?.some((roleAttributeObj) => {
if (roleAttributeObj?.id === urns?.roleScopingEntity
&& roleAttributeObj?.value === ruleRoleScopeEntityName) {
&& roleAttributeObj?.value === ruleRoleScopeEntityName
) {
return roleAttributeObj?.attributes?.some((roleScopingInstanceObj) => {
if (roleScopingInstanceObj?.id === urns?.roleScopingInstance) {
return roleScopingInstanceObj?.value;
Expand Down Expand Up @@ -353,8 +354,8 @@ export const buildFilterPermissions = async (
}
}
else {
subject.hierarchical_scopes ??=[];
subject.role_associations ??=[];
subject.hierarchical_scopes ??= [];
subject.role_associations ??= [];
}

const urns = cfg.get('authorization:urns');
Expand All @@ -372,7 +373,7 @@ export const buildFilterPermissions = async (
const algorithm = policy.combining_algorithm;
// iterate through policy_set and check subject in policy and Rule:
if (policy?.target?.subjects) {
let userSubjectMatched = checkSubjectMatch(subject, policy.target.subjects);
const userSubjectMatched = checkSubjectMatch(subject, policy.target.subjects);
if (!userSubjectMatched) {
logger.debug(`Skipping policy as policy subject and user subject don't match`);
continue;
Expand All @@ -396,7 +397,7 @@ export const buildFilterPermissions = async (
for (let rule of policy?.rules) {
let reducedUserScope = [];
if (rule?.target?.subjects) {
let userSubjectMatched = checkSubjectMatch(subject, rule.target.subjects, reducedUserScope);
const userSubjectMatched = checkSubjectMatch(subject, rule.target.subjects, reducedUserScope);
if (!userSubjectMatched) {
logger.debug(`Skipping rule as user subject and rule subject don't match`);
continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/protos/io/restorecommerce/fulfillment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ message Label {
}
optional string parcel_id = 4;
optional string shipment_number = 5; //filled on Order
optional State state = 6; //update by Track
optional FulfillmentState state = 6; //update by Track
optional io.restorecommerce.status.Status status = 7; //API status
}

Expand Down

0 comments on commit 4debc8b

Please sign in to comment.