@backstage-community/plugin-rbac-backend 5.5.0 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ### Dependencies
2
2
 
3
+ ## 5.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fcfaf89: Fixed an issue where aliases would not be applied across all conditional policy rules.
8
+
3
9
  ## 5.5.0
4
10
 
5
11
  ### Minor Changes
@@ -49,14 +49,13 @@ function replaceAliases(conditions, userInfo) {
49
49
  if ("anyOf" in conditions) {
50
50
  for (const condition of conditions.anyOf) {
51
51
  replaceAliases(condition, userInfo);
52
- return;
53
52
  }
53
+ return;
54
54
  }
55
- const params = conditions.params;
56
- if (params) {
57
- for (const key of Object.keys(params)) {
55
+ if (conditions.params) {
56
+ for (const key of Object.keys(conditions.params)) {
58
57
  let modifiedParams = replaceAliasWithValue(
59
- params,
58
+ conditions.params,
60
59
  key,
61
60
  isCurrentUserAlias,
62
61
  userInfo.userEntityRef
@@ -1 +1 @@
1
- {"version":3,"file":"alias-resolver.cjs.js","sources":["../../src/conditional-aliases/alias-resolver.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { BackstageUserInfo } from '@backstage/backend-plugin-api';\nimport type {\n PermissionCondition,\n PermissionCriteria,\n PermissionRuleParam,\n PermissionRuleParams,\n} from '@backstage/plugin-permission-common';\nimport type { JsonPrimitive } from '@backstage/types';\n\nimport {\n CONDITION_ALIAS_SIGN,\n ConditionalAliases,\n} from '@backstage-community/plugin-rbac-common';\n\ninterface Predicate<T> {\n (item: T): boolean;\n}\n\nfunction isOwnerRefsAlias(value: PermissionRuleParam): boolean {\n const alias = `${CONDITION_ALIAS_SIGN}${ConditionalAliases.OWNER_REFS}`;\n return value === alias;\n}\n\nfunction isCurrentUserAlias(value: PermissionRuleParam): boolean {\n const alias = `${CONDITION_ALIAS_SIGN}${ConditionalAliases.CURRENT_USER}`;\n return value === alias;\n}\n\nfunction replaceAliasWithValue<\n K extends string,\n V extends JsonPrimitive | JsonPrimitive[],\n>(\n params: Record<K, PermissionRuleParam> | undefined,\n key: K,\n predicate: Predicate<PermissionRuleParam>,\n newValue: V,\n): Record<K, PermissionRuleParam> | undefined {\n if (!params) {\n return params;\n }\n\n if (Array.isArray(params[key])) {\n const oldValues = params[key] as JsonPrimitive[];\n const nonAliasValues: JsonPrimitive[] = [];\n for (const oldValue of oldValues) {\n const isAliasMatched = predicate(oldValue);\n if (isAliasMatched) {\n const newValues = Array.isArray(newValue) ? newValue : [newValue];\n nonAliasValues.push(...newValues);\n } else {\n nonAliasValues.push(oldValue);\n }\n }\n return { ...params, [key]: nonAliasValues };\n }\n\n const oldValue = params[key] as JsonPrimitive;\n const isAliasMatched = predicate(oldValue);\n if (isAliasMatched && !Array.isArray(newValue)) {\n return { ...params, [key]: newValue };\n }\n\n return params;\n}\n\nexport function replaceAliases(\n conditions: PermissionCriteria<\n PermissionCondition<string, PermissionRuleParams>\n >,\n userInfo: BackstageUserInfo,\n) {\n if ('not' in conditions) {\n replaceAliases(conditions.not, userInfo);\n return;\n }\n if ('allOf' in conditions) {\n for (const condition of conditions.allOf) {\n replaceAliases(condition, userInfo);\n }\n return;\n }\n if ('anyOf' in conditions) {\n for (const condition of conditions.anyOf) {\n replaceAliases(condition, userInfo);\n return;\n }\n }\n\n const params = (\n conditions as PermissionCondition<string, PermissionRuleParams>\n ).params;\n if (params) {\n for (const key of Object.keys(params)) {\n let modifiedParams = replaceAliasWithValue(\n params,\n key,\n isCurrentUserAlias,\n userInfo.userEntityRef,\n );\n\n modifiedParams = replaceAliasWithValue(\n modifiedParams,\n key,\n isOwnerRefsAlias,\n userInfo.ownershipEntityRefs,\n );\n\n (conditions as PermissionCondition<string, PermissionRuleParams>).params =\n modifiedParams;\n }\n }\n}\n"],"names":["CONDITION_ALIAS_SIGN","ConditionalAliases","oldValue","isAliasMatched"],"mappings":";;;;AAiCA,SAAS,iBAAiB,KAAqC,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,CAAA,EAAGA,qCAAoB,CAAA,EAAGC,oCAAmB,UAAU,CAAA,CAAA;AACrE,EAAA,OAAO,KAAU,KAAA,KAAA;AACnB;AAEA,SAAS,mBAAmB,KAAqC,EAAA;AAC/D,EAAA,MAAM,KAAQ,GAAA,CAAA,EAAGD,qCAAoB,CAAA,EAAGC,oCAAmB,YAAY,CAAA,CAAA;AACvE,EAAA,OAAO,KAAU,KAAA,KAAA;AACnB;AAEA,SAAS,qBAIP,CAAA,MAAA,EACA,GACA,EAAA,SAAA,EACA,QAC4C,EAAA;AAC5C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,MAAA;AAAA;AAGT,EAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,GAAG,CAAC,CAAG,EAAA;AAC9B,IAAM,MAAA,SAAA,GAAY,OAAO,GAAG,CAAA;AAC5B,IAAA,MAAM,iBAAkC,EAAC;AACzC,IAAA,KAAA,MAAWC,aAAY,SAAW,EAAA;AAChC,MAAMC,MAAAA,eAAAA,GAAiB,UAAUD,SAAQ,CAAA;AACzC,MAAA,IAAIC,eAAgB,EAAA;AAClB,QAAA,MAAM,YAAY,KAAM,CAAA,OAAA,CAAQ,QAAQ,CAAI,GAAA,QAAA,GAAW,CAAC,QAAQ,CAAA;AAChE,QAAe,cAAA,CAAA,IAAA,CAAK,GAAG,SAAS,CAAA;AAAA,OAC3B,MAAA;AACL,QAAA,cAAA,CAAe,KAAKD,SAA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S,CAAA;AAAA,OACX;AAEA,MAAC,WAAiE,MAChE,GAAA,cAAA;AAAA;AACJ;AAEJ;;;;"}
1
+ {"version":3,"file":"alias-resolver.cjs.js","sources":["../../src/conditional-aliases/alias-resolver.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { BackstageUserInfo } from '@backstage/backend-plugin-api';\nimport type {\n PermissionCondition,\n PermissionCriteria,\n PermissionRuleParam,\n PermissionRuleParams,\n} from '@backstage/plugin-permission-common';\nimport type { JsonPrimitive } from '@backstage/types';\n\nimport {\n CONDITION_ALIAS_SIGN,\n ConditionalAliases,\n} from '@backstage-community/plugin-rbac-common';\n\ninterface Predicate<T> {\n (item: T): boolean;\n}\n\nfunction isOwnerRefsAlias(value: PermissionRuleParam): boolean {\n const alias = `${CONDITION_ALIAS_SIGN}${ConditionalAliases.OWNER_REFS}`;\n return value === alias;\n}\n\nfunction isCurrentUserAlias(value: PermissionRuleParam): boolean {\n const alias = `${CONDITION_ALIAS_SIGN}${ConditionalAliases.CURRENT_USER}`;\n return value === alias;\n}\n\nfunction replaceAliasWithValue<\n K extends string,\n V extends JsonPrimitive | JsonPrimitive[],\n>(\n params: Record<K, PermissionRuleParam>,\n key: K,\n predicate: Predicate<PermissionRuleParam>,\n newValue: V,\n): Record<K, PermissionRuleParam> {\n if (!params) {\n return params;\n }\n\n if (Array.isArray(params[key])) {\n const oldValues = params[key] as JsonPrimitive[];\n const nonAliasValues: JsonPrimitive[] = [];\n for (const oldValue of oldValues) {\n const isAliasMatched = predicate(oldValue);\n if (isAliasMatched) {\n const newValues = Array.isArray(newValue) ? newValue : [newValue];\n nonAliasValues.push(...newValues);\n } else {\n nonAliasValues.push(oldValue);\n }\n }\n return { ...params, [key]: nonAliasValues };\n }\n\n const oldValue = params[key] as JsonPrimitive;\n const isAliasMatched = predicate(oldValue);\n if (isAliasMatched && !Array.isArray(newValue)) {\n return { ...params, [key]: newValue };\n }\n\n return params;\n}\n\nexport function replaceAliases(\n conditions: PermissionCriteria<\n PermissionCondition<string, PermissionRuleParams>\n >,\n userInfo: BackstageUserInfo,\n) {\n if ('not' in conditions) {\n replaceAliases(conditions.not, userInfo);\n return;\n }\n if ('allOf' in conditions) {\n for (const condition of conditions.allOf) {\n replaceAliases(condition, userInfo);\n }\n return;\n }\n if ('anyOf' in conditions) {\n for (const condition of conditions.anyOf) {\n replaceAliases(condition, userInfo);\n }\n return;\n }\n\n if (conditions.params) {\n for (const key of Object.keys(conditions.params)) {\n let modifiedParams: PermissionRuleParams = replaceAliasWithValue(\n conditions.params,\n key,\n isCurrentUserAlias,\n userInfo.userEntityRef,\n );\n\n modifiedParams = replaceAliasWithValue(\n modifiedParams,\n key,\n isOwnerRefsAlias,\n userInfo.ownershipEntityRefs,\n );\n\n conditions.params = modifiedParams;\n }\n }\n}\n"],"names":["CONDITION_ALIAS_SIGN","ConditionalAliases","oldValue","isAliasMatched"],"mappings":";;;;AAiCA,SAAS,iBAAiB,KAAqC,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,CAAA,EAAGA,qCAAoB,CAAA,EAAGC,oCAAmB,UAAU,CAAA,CAAA;AACrE,EAAA,OAAO,KAAU,KAAA,KAAA;AACnB;AAEA,SAAS,mBAAmB,KAAqC,EAAA;AAC/D,EAAA,MAAM,KAAQ,GAAA,CAAA,EAAGD,qCAAoB,CAAA,EAAGC,oCAAmB,YAAY,CAAA,CAAA;AACvE,EAAA,OAAO,KAAU,KAAA,KAAA;AACnB;AAEA,SAAS,qBAIP,CAAA,MAAA,EACA,GACA,EAAA,SAAA,EACA,Q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AAe,WAAW,QAAQ,CAAA;AAAA;AAEpC,IAAA;AAAA;AAEF,EAAA,IAAI,WAAW,UAAY,EAAA;AACzB,IAAW,KAAA,MAAA,SAAA,IAAa,WAAW,KAAO,EAAA;AACxC,MAAA,cAAA,CAAe,WAAW,QAAQ,CAAA;AAAA;AAEpC,IAAA;AAAA;AAGF,EAAA,IAAI,WAAW,MAAQ,EAAA;AACrB,IAAA,KAAA,MAAW,GAAO,IAAA,MAAA,CAAO,IAAK,CAAA,UAAA,CAAW,MAAM,CAAG,EAAA;AAChD,MAAA,IAAI,cAAuC,GAAA,qBAAA;AAAA,QACzC,UAAW,CAAA,MAAA;AAAA,QACX,GAAA;AAAA,QACA,kBAAA;AAAA,QACA,QAAS,CAAA;AAAA,OACX;AAEA,MAAiB,cAAA,GAAA,qBAAA;AAAA,QACf,cAAA;AAAA,QACA,GAAA;AAAA,QACA,gBAAA;AAAA,QACA,QAAS,CAAA;AAAA,OACX;AAEA,MAAA,UAAA,CAAW,MAAS,GAAA,cAAA;AAAA;AACtB;AAEJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-rbac-backend",
3
- "version": "5.5.0",
3
+ "version": "5.5.1",
4
4
  "main": "dist/index.cjs.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",