@iredium/butterfly
Version:
Express API Framework
51 lines (50 loc) • 1.78 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var base_policy_1 = require("../../policies/base_policy");
var ApiPolicy = /** @class */ (function (_super) {
__extends(ApiPolicy, _super);
function ApiPolicy() {
return _super !== null && _super.apply(this, arguments) || this;
}
ApiPolicy.prototype.index = function () {
return true;
};
ApiPolicy.prototype.show = function () {
return true;
};
ApiPolicy.prototype.create = function () {
return true;
};
ApiPolicy.prototype.update = function () {
return this.allowedUser();
};
ApiPolicy.prototype.destroy = function () {
return this.allowedUser();
};
ApiPolicy.prototype.restore = function () {
return this.user.admin();
};
ApiPolicy.prototype.allowedUser = function () {
try {
return this.user && ((String(this.user._id) === String(this.record.user._id ? this.record.user._id : this.record.user)) || this.user.admin());
}
catch (e) {
return false;
}
};
return ApiPolicy;
}(base_policy_1.BasePolicy));
exports.ApiPolicy = ApiPolicy;