var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import DatabaseRequestType from "../../BaseDatabase/DatabaseRequestType";
import AccessControlUtil from "./AccessControlPermission";
import BasePermission from "./BasePermission";
import ColumnPermissions from "./ColumnPermission";
import TablePermission from "./TablePermission";
import CaptureSpan from "../../../Utils/Telemetry/CaptureSpan";
export default class UpdatePermission {
    static async checkUpdatePermissionByModel(data) {
        await AccessControlUtil.checkAccessControlBlockPermissionByModel(Object.assign(Object.assign({}, data), { type: DatabaseRequestType.Update }));
        await AccessControlUtil.checkAccessControlPermissionByModel(Object.assign(Object.assign({}, data), { type: DatabaseRequestType.Update }));
    }
    static async checkUpdatePermissions(modelType, query, data, props) {
        if (props.isRoot || props.isMasterAdmin) {
            // If system is making this query then let the query run!
            return query;
        }
        TablePermission.checkTableLevelPermissions(modelType, props, DatabaseRequestType.Update);
        const checkBasePermission = await BasePermission.checkPermissions(modelType, query, null, props, DatabaseRequestType.Update);
        query = checkBasePermission.query;
        ColumnPermissions.checkDataColumnPermissions(modelType, data, props, DatabaseRequestType.Update);
        return query;
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], UpdatePermission, "checkUpdatePermissionByModel", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object, Object, Object]),
    __metadata("design:returntype", Promise)
], UpdatePermission, "checkUpdatePermissions", null);
//# sourceMappingURL=UpdatePermission.js.map