Skip to content

Commit

Permalink
Merge branch 'dove-0.6' into dove
Browse files Browse the repository at this point in the history
  • Loading branch information
fratzinger committed Dec 16, 2021
2 parents 50a177a + 3c6d87f commit b3ffacd
Show file tree
Hide file tree
Showing 41 changed files with 2,254 additions and 1,834 deletions.
4 changes: 2 additions & 2 deletions lib/channels/channels.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ export const getAbility = (
};

export const getEventName = (
method: "find" | "get" | "create" | "update" | "patch" | "remove"
method: string
): EventName => {
if (method === "create") { return "created"; }
else if (method === "update") { return "updated"; }
else if (method === "patch") { return "patched"; }
else if (method === "remove") { return "removed"; }
return undefined;
};
};
2 changes: 2 additions & 0 deletions lib/hooks/authorize/authorize.hook.after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default async (
)
) { return context; }

//@ts-expect-error type error because feathers-hooks-common not on feathers@5
const itemOrItems = getItems(context);
if (!itemOrItems) { return context; }

Expand Down Expand Up @@ -126,6 +127,7 @@ export default async (
}
}

//@ts-expect-error type error because feathers-hooks-common not on feathers@5
replaceItems(context, result);

return context;
Expand Down
7 changes: 4 additions & 3 deletions lib/hooks/authorize/authorize.hook.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
markHookForSkip
} from "feathers-utils";

import type { AnyAbility } from "@casl/ability";
import type { AnyAbility, ForcedSubject } from "@casl/ability";
import type { Application, HookContext, Params } from "@feathersjs/feathers";

import type {
Expand Down Expand Up @@ -111,10 +111,10 @@ export const getAbility = (
throw new Forbidden(`You're not allowed to ${context.method} on '${context.path}'`);
};

export const throwUnlessCan = (
export const throwUnlessCan = <T extends ForcedSubject<string>>(
ability: AnyAbility,
method: string,
resource: string|Record<string, unknown>,
resource: string|T,
modelName: string,
options: Partial<ThrowUnlessCanOptions>
): boolean => {
Expand All @@ -133,6 +133,7 @@ export const refetchItems = async (
params?: Params
): Promise<unknown[] | undefined> => {
if (context.type !== "after") { return; }
//@ts-expect-error type error because feathers-hooks-common not on feathers@5
const itemOrItems = getItems(context);

const items = (!itemOrItems || Array.isArray(itemOrItems)) ? itemOrItems : [itemOrItems];
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const checkCreatePerItem = (
if (!checkCreateForData) { return context; }

// we have all information we need (maybe we need populated data?)
//@ts-expect-error type error because feathers-hooks-common not on feathers@5
let items = getItems(context);
items = (Array.isArray(items)) ? items : [items];

Expand Down
3 changes: 2 additions & 1 deletion lib/utils/checkCan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const checkCan = async <S>(
};
}

//@ts-expect-error _get is not exposed
const getMethod = (service._get) ? "_get" : "get";

const item = await service[getMethod](id, params);
Expand All @@ -63,4 +64,4 @@ const checkCan = async <S>(
return can;
};

export default checkCan;
export default checkCan;
9 changes: 5 additions & 4 deletions lib/utils/mergeQueryFromAbility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import hasRestrictingConditions from "./hasRestrictingConditions";
import simplifyQuery from "./simplifyQuery";

import type { AnyAbility } from "@casl/ability";
import type { Application, Query, Service } from "@feathersjs/feathers";
import type { Application, Query } from "@feathersjs/feathers";
import type { AdapterService } from "@feathersjs/adapter-commons";
import type { AuthorizeHookOptions } from "../types";

const adaptersFor$not = [
Expand All @@ -31,7 +32,7 @@ export default function mergeQueryFromAbility<T>(
method: string,
modelName: string,
originalQuery: Query,
service: Service<T>,
service: AdapterService<T>,
options: Pick<AuthorizeHookOptions, "adapter">
): Query {
if (hasRestrictingConditions(ability, method, modelName)) {
Expand Down Expand Up @@ -71,7 +72,7 @@ export default function mergeQueryFromAbility<T>(
$and.forEach(q => {
query = mergeQuery(query, q, {
defaultHandle: "intersect",
operators: service.operators,
operators: service.options?.whitelist,
useLogicalConjunction: true
});
});
Expand All @@ -98,4 +99,4 @@ export default function mergeQueryFromAbility<T>(
} else {
return originalQuery;
}
}
}
Loading

0 comments on commit b3ffacd

Please sign in to comment.