mirror of
https://github.com/outline/outline.git
synced 2026-06-14 03:45:00 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6146843845 | |||
| 26c5d5e4fe |
@@ -2,7 +2,9 @@
|
|||||||
import { CollectionUser, Collection } from "../models";
|
import { CollectionUser, Collection } from "../models";
|
||||||
import { buildUser, buildTeam, buildCollection } from "../test/factories";
|
import { buildUser, buildTeam, buildCollection } from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
import { serialize } from "./index";
|
|
||||||
|
import "./";
|
||||||
|
import serialize from "./serializer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
beforeEach(() => flushdb());
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import {
|
|||||||
buildCollection,
|
buildCollection,
|
||||||
} from "../test/factories";
|
} from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
import { serialize } from "./index";
|
|
||||||
|
import "./";
|
||||||
|
import serialize from "./serializer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
beforeEach(() => flushdb());
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { Attachment, Team, User, Collection, Document, Group } from "../models";
|
|
||||||
import policy from "./policy";
|
import policy from "./policy";
|
||||||
import "./apiKey";
|
import "./apiKey";
|
||||||
import "./attachment";
|
import "./attachment";
|
||||||
@@ -13,36 +12,4 @@ import "./user";
|
|||||||
import "./team";
|
import "./team";
|
||||||
import "./group";
|
import "./group";
|
||||||
|
|
||||||
const { can, abilities } = policy;
|
|
||||||
|
|
||||||
type Policy = {
|
|
||||||
[key: string]: boolean,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a user and a model – output an object which describes the actions the
|
|
||||||
* user may take against the model. This serialized policy is used for testing
|
|
||||||
* and sent in API responses to allow clients to adjust which UI is displayed.
|
|
||||||
*/
|
|
||||||
export function serialize(
|
|
||||||
model: User,
|
|
||||||
target: Attachment | Team | Collection | Document | Group
|
|
||||||
): Policy {
|
|
||||||
let output = {};
|
|
||||||
|
|
||||||
abilities.forEach((ability) => {
|
|
||||||
if (model instanceof ability.model && target instanceof ability.target) {
|
|
||||||
let response = true;
|
|
||||||
try {
|
|
||||||
response = can(model, ability.action, target);
|
|
||||||
} catch (err) {
|
|
||||||
response = false;
|
|
||||||
}
|
|
||||||
output[ability.action] = response;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default policy;
|
export default policy;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { buildUser, buildTeam } from "../test/factories";
|
import { buildUser, buildTeam } from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
import { serialize } from "./index";
|
|
||||||
|
import "./";
|
||||||
|
import serialize from "./serializer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
beforeEach(() => flushdb());
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// @flow
|
||||||
|
import policy from "./policy";
|
||||||
|
|
||||||
|
const { can, abilities } = policy;
|
||||||
|
|
||||||
|
type Policy = {
|
||||||
|
[key: string]: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Given a user and a model – output an object which describes the actions the
|
||||||
|
* user may take against the model. This serialized policy is used for testing
|
||||||
|
* and sent in API responses to allow clients to adjust which UI is displayed.
|
||||||
|
*/
|
||||||
|
export default function serialize(model: Object, target: Object): Policy {
|
||||||
|
let output = {};
|
||||||
|
|
||||||
|
abilities.forEach((ability) => {
|
||||||
|
if (model instanceof ability.model && target instanceof ability.target) {
|
||||||
|
let response = true;
|
||||||
|
try {
|
||||||
|
response = can(model, ability.action, target);
|
||||||
|
} catch (err) {
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
output[ability.action] = response;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { buildUser, buildTeam, buildAdmin } from "../test/factories";
|
import { buildUser, buildTeam, buildAdmin } from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
import { serialize } from "./index";
|
|
||||||
|
import "./";
|
||||||
|
import serialize from "./serializer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
beforeEach(() => flushdb());
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { User } from "../models";
|
import { User } from "../models";
|
||||||
|
import serialize from "../policies/serializer";
|
||||||
|
|
||||||
type Policy = { id: string, abilities: { [key: string]: boolean } };
|
type Policy = { id: string, abilities: { [key: string]: boolean } };
|
||||||
|
|
||||||
export default function present(user: User, objects: Object[]): Policy[] {
|
export default function present(user: User, objects: Object[]): Policy[] {
|
||||||
const { serialize } = require("../policies");
|
|
||||||
|
|
||||||
return objects.map((object) => ({
|
return objects.map((object) => ({
|
||||||
id: object.id,
|
id: object.id,
|
||||||
abilities: serialize(user, object),
|
abilities: serialize(user, object),
|
||||||
|
|||||||
Reference in New Issue
Block a user