@bunnarin/plugin-audit-log 2.0.0
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/README.md +4 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/AuditConfigPage.d.ts +2 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale.d.ts +10 -0
- package/dist/client/models/index.d.ts +11 -0
- package/dist/client/plugin.d.ts +5 -0
- package/dist/externalVersion.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/server/collections/auditChange.d.ts +2 -0
- package/dist/server/collections/auditChange.js +114 -0
- package/dist/server/collections/auditConfig.d.ts +2 -0
- package/dist/server/collections/auditConfig.js +70 -0
- package/dist/server/collections/auditLog.d.ts +2 -0
- package/dist/server/collections/auditLog.js +169 -0
- package/dist/server/collections/ipAddress.d.ts +2 -0
- package/dist/server/collections/ipAddress.js +65 -0
- package/dist/server/hooks/afterCreate.d.ts +1 -0
- package/dist/server/hooks/afterCreate.js +49 -0
- package/dist/server/hooks/afterDestroy.d.ts +1 -0
- package/dist/server/hooks/afterDestroy.js +49 -0
- package/dist/server/hooks/afterUpdate.d.ts +1 -0
- package/dist/server/hooks/afterUpdate.js +83 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +78 -0
- package/package.json +33 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
package/README.md
ADDED
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@nocobase/client"),require("antd")):"function"==typeof define&&define.amd?define("@bunnarin/plugin-audit-log",["react","@nocobase/client","antd"],t):"object"==typeof exports?exports["@bunnarin/plugin-audit-log"]=t(require("react"),require("@nocobase/client"),require("antd")):e["@bunnarin/plugin-audit-log"]=t(e.react,e["@nocobase/client"],e.antd)}(self,function(e,t,n){return function(){"use strict";var r={772:function(e){e.exports=t},721:function(e){e.exports=n},156:function(t){t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},i.d=function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return!function(){i.r(a),i.d(a,{default:function(){return k}});var e=i(772),t={},n=i(156),r=i.n(n),o=i(721);function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function c(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){l(i,r,o,a,u,"next",e)}function u(e){l(i,r,o,a,u,"throw",e)}a(void 0)})}}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){s(e,t,n[t])})}return e}function p(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,u=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(u)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){var l=[i,u];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}var b=function(){var t,i,a=(0,e.useCollectionManager)().getCollections(),u=(0,e.useAPIClient)(),l=d((0,n.useState)({}),2),b=l[0],h=l[1],v=d((0,n.useState)(!0),2),g=v[0],m=v[1],w=(t=c(function(){var e,t,n;return y(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,3,4]),m(!0),[4,u.resource("__auditConfig").list({paginate:!1})];case 1:return t=r.sent().data,n={},null==t||null==(e=t.data)||e.forEach(function(e){n[e.collectionName]=e}),h(n),[3,4];case 2:return console.error(r.sent()),o.message.error("Failed to fetch audit configs"),[3,4];case 3:return m(!1),[7];case 4:return[2]}})}),function(){return t.apply(this,arguments)});(0,n.useEffect)(function(){w()},[]);var O=(i=c(function(e,t){var n,r;return y(this,function(i){switch(i.label){case 0:if(i.trys.push([0,5,,6]),r=f({},n=b[e]||{},t),h(function(t){return p(f({},t),s({},e,r))}),n.collectionName)return[3,2];return[4,u.resource("__auditConfig").create({values:f({collectionName:e},t)}).then(function(t){return h(function(n){return p(f({},n),s({},e,Array.isArray(t.data.data)?t.data.data[0]:t.data.data))})})];case 1:return i.sent(),[3,4];case 2:return[4,u.resource("__auditConfig").update({filter:{collectionName:e},values:t}).then(function(t){return h(function(n){return p(f({},n),s({},e,Array.isArray(t.data.data)?t.data.data[0]:t.data.data))})})];case 3:i.sent(),i.label=4;case 4:return o.message.success("Config saved"),[3,6];case 5:return console.error(i.sent()),o.message.error("Failed to save config"),w(),[3,6];case 6:return[2]}})}),function(e,t){return i.apply(this,arguments)}),k=(0,n.useMemo)(function(){return a.filter(function(e){return!e.name.startsWith("__audit")&&"__ipAddress"!==e.name})},[a]),x=[{title:"Collection",dataIndex:"name",key:"name",render:function(e,t){return r().createElement("div",null,r().createElement(o.Typography.Text,{strong:!0},t.title||e),r().createElement("br",null),r().createElement(o.Typography.Text,{type:"secondary"},e))}},{title:"Skip IP",dataIndex:"skipIP",key:"skipIP",render:function(e,t){var n,i=(null==(n=b[t.name])?void 0:n.skipIP)||!1;return r().createElement(o.Switch,{checked:i,onChange:function(e){return O(t.name,{skipIP:e})}})}},{title:"Skip Create",dataIndex:"skipCreate",key:"skipCreate",render:function(e,t){var n,i=(null==(n=b[t.name])?void 0:n.skipCreate)||!1;return r().createElement(o.Switch,{checked:i,onChange:function(e){return O(t.name,{skipCreate:e})}})}},{title:"Skip Delete",dataIndex:"skipDelete",key:"skipDelete",render:function(e,t){var n,i=(null==(n=b[t.name])?void 0:n.skipDelete)||!1;return r().createElement(o.Switch,{checked:i,onChange:function(e){return O(t.name,{skipDelete:e})}})}},{title:"Update Listen Logic",dataIndex:"updateListenLogic",key:"updateListenLogic",render:function(e,t){var n,i,a=(null==(n=b[t.name])?void 0:n.updateListenLogic)||{},u=a.blacklist?"include":a.whitelist?"exclude":"none",l="include"===u?a.blacklist:"exclude"===u?a.whitelist:[],c=(null==(i=t.fields)?void 0:i.filter(function(e){return!["hasOne","hasMany","belongsTo","belongsToMany"].includes(e.type)}))||[];return r().createElement("div",{style:{display:"flex",flexDirection:"column",gap:"8px",minWidth:"250px"}},r().createElement(o.Select,{value:u,onChange:function(e){"none"===e?O(t.name,{updateListenLogic:null}):O(t.name,{updateListenLogic:s({},"include"===e?"blacklist":"whitelist",[])})},options:[{label:"Log nothing (Default)",value:"none"},{label:"blacklist",value:"include"},{label:"whitelist",value:"exclude"}]}),"none"!==u&&r().createElement(o.Select,{mode:"multiple",allowClear:!0,placeholder:"Select fields",value:l,onChange:function(e){O(t.name,{updateListenLogic:s({},"include"===u?"blacklist":"whitelist",e)})},options:c.map(function(e){return{label:e.title||e.name,value:e.name}})}))}}];return g&&0===Object.keys(b).length?r().createElement(o.Spin,{style:{margin:"20px"}}):r().createElement("div",{style:{padding:"24px"}},r().createElement("h2",null,"Audit Log Configuration"),r().createElement(o.Table,{dataSource:k,columns:x,rowKey:"name",pagination:!1,bordered:!0}))};function h(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function v(e,t,n){return(v=O()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&m(o,n.prototype),o}).apply(null,arguments)}function g(e){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function m(e,t){return(m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return v(e,arguments,g(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),m(n,e)})(e)}function O(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(O=function(){return!!e})()}var k=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=g(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,O()?Reflect.construct(e,t||[],g(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&m(r,e),n=[{key:"load",value:function(){var e,n=this;return(e=function(){var e,r;return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){var l=[i,u];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(o){return null==(r=n.flowEngine)||null==(e=r.registerModels)||e.call(r,t),n.app.pluginSettingsManager.add("audit-log",{title:"Audit Log Settings",icon:"SettingOutlined",Component:b}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){h(i,r,o,a,u,"next",e)}function u(e){h(i,r,o,a,u,"throw",e)}a(void 0)})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,n),r}(w(e.Plugin))}(),a}()});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useT(): (str: string) => any;
|
|
10
|
+
export declare function tExpr(key: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { ModelConstructor } from '@nocobase/flow-engine';
|
|
10
|
+
declare const _default: Record<string, ModelConstructor>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"react": "18.3.1",
|
|
12
|
+
"@nocobase/client": "2.0.61",
|
|
13
|
+
"antd": "5.24.2",
|
|
14
|
+
"@nocobase/flow-engine": "2.0.61",
|
|
15
|
+
"@nocobase/server": "2.0.61",
|
|
16
|
+
"@nocobase/database": "2.0.61"
|
|
17
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var src_exports = {};
|
|
39
|
+
__export(src_exports, {
|
|
40
|
+
default: () => import_server.default
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
44
|
+
var import_server = __toESM(require("./server"));
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
...require("./server")
|
|
48
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var auditChange_exports = {};
|
|
28
|
+
__export(auditChange_exports, {
|
|
29
|
+
default: () => auditChange_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(auditChange_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var auditChange_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "__auditChange",
|
|
35
|
+
title: "audit change",
|
|
36
|
+
uiManageable: true,
|
|
37
|
+
createdBy: false,
|
|
38
|
+
updatedBy: false,
|
|
39
|
+
createdAt: false,
|
|
40
|
+
updatedAt: false,
|
|
41
|
+
shared: true,
|
|
42
|
+
autoGenId: true,
|
|
43
|
+
fields: [
|
|
44
|
+
{
|
|
45
|
+
autoIncrement: true,
|
|
46
|
+
primaryKey: true,
|
|
47
|
+
interface: "integer",
|
|
48
|
+
name: "id",
|
|
49
|
+
type: "integer"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "string",
|
|
53
|
+
name: "fieldName",
|
|
54
|
+
allowNull: false,
|
|
55
|
+
interface: "input",
|
|
56
|
+
uiSchema: {
|
|
57
|
+
type: "string",
|
|
58
|
+
"x-component": "Input",
|
|
59
|
+
"title": "field"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "text",
|
|
64
|
+
length: "long",
|
|
65
|
+
name: "before",
|
|
66
|
+
allowNull: false,
|
|
67
|
+
interface: "textarea",
|
|
68
|
+
uiSchema: {
|
|
69
|
+
type: "string",
|
|
70
|
+
"x-component": "Input.TextArea",
|
|
71
|
+
"title": "before"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
length: "long",
|
|
77
|
+
name: "after",
|
|
78
|
+
interface: "textarea",
|
|
79
|
+
uiSchema: {
|
|
80
|
+
type: "string",
|
|
81
|
+
"x-component": "Input.TextArea",
|
|
82
|
+
"title": "after"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "integer",
|
|
87
|
+
name: "auditLogId",
|
|
88
|
+
allowNull: false,
|
|
89
|
+
interface: "integer",
|
|
90
|
+
isForeignKey: true,
|
|
91
|
+
uiSchema: {
|
|
92
|
+
"type": "number",
|
|
93
|
+
"title": "audit log id",
|
|
94
|
+
"x-component": "InputNumber",
|
|
95
|
+
"x-read-pretty": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: "belongsTo",
|
|
100
|
+
name: "log",
|
|
101
|
+
interface: "m2o",
|
|
102
|
+
target: "__auditLog",
|
|
103
|
+
targetKey: "id",
|
|
104
|
+
foreignKey: "auditLogId",
|
|
105
|
+
uiSchema: {
|
|
106
|
+
"x-component": "AssociationField",
|
|
107
|
+
"x-component-props": {
|
|
108
|
+
"multiple": false
|
|
109
|
+
},
|
|
110
|
+
title: "audit log"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var auditConfig_exports = {};
|
|
28
|
+
__export(auditConfig_exports, {
|
|
29
|
+
default: () => auditConfig_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(auditConfig_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var auditConfig_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "__auditConfig",
|
|
35
|
+
title: "audit config",
|
|
36
|
+
filterTargetKey: "collectionName",
|
|
37
|
+
fields: [
|
|
38
|
+
{
|
|
39
|
+
type: "string",
|
|
40
|
+
name: "collectionName",
|
|
41
|
+
primaryKey: true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "belongsTo",
|
|
45
|
+
name: "collection",
|
|
46
|
+
target: "collections",
|
|
47
|
+
targetKey: "name",
|
|
48
|
+
sourceKey: "id",
|
|
49
|
+
foreignKey: "collectionName",
|
|
50
|
+
constraints: false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "boolean",
|
|
54
|
+
name: "skipIP"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "boolean",
|
|
58
|
+
name: "skipCreate"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "boolean",
|
|
62
|
+
name: "skipDelete"
|
|
63
|
+
},
|
|
64
|
+
// key will be either include all except or whitelist and value will be array of field names
|
|
65
|
+
{
|
|
66
|
+
type: "json",
|
|
67
|
+
name: "updateListenLogic"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var auditLog_exports = {};
|
|
28
|
+
__export(auditLog_exports, {
|
|
29
|
+
default: () => auditLog_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(auditLog_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var auditLog_default = (0, import_database.defineCollection)({
|
|
34
|
+
migrationRules: ["schema-only", "skip"],
|
|
35
|
+
title: "audit log",
|
|
36
|
+
name: "__auditLog",
|
|
37
|
+
uiManageable: true,
|
|
38
|
+
createdAt: true,
|
|
39
|
+
createdBy: true,
|
|
40
|
+
updatedBy: false,
|
|
41
|
+
updatedAt: false,
|
|
42
|
+
shared: true,
|
|
43
|
+
autoGenId: true,
|
|
44
|
+
fields: [
|
|
45
|
+
{
|
|
46
|
+
autoIncrement: true,
|
|
47
|
+
primaryKey: true,
|
|
48
|
+
interface: "integer",
|
|
49
|
+
name: "id",
|
|
50
|
+
type: "integer"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "date",
|
|
54
|
+
name: "createdAt",
|
|
55
|
+
interface: "createdAt",
|
|
56
|
+
field: "createdAt",
|
|
57
|
+
uiSchema: {
|
|
58
|
+
type: "datetime",
|
|
59
|
+
title: "created at",
|
|
60
|
+
"x-component": "DatePicker",
|
|
61
|
+
"x-component-props": {},
|
|
62
|
+
"x-read-pretty": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "string",
|
|
67
|
+
name: "recordId",
|
|
68
|
+
allowNull: false,
|
|
69
|
+
interface: "input",
|
|
70
|
+
uiSchema: {
|
|
71
|
+
title: "record id",
|
|
72
|
+
type: "string",
|
|
73
|
+
"x-component": "Input",
|
|
74
|
+
required: true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: "boolean",
|
|
79
|
+
name: "isCreate",
|
|
80
|
+
interface: "checkbox",
|
|
81
|
+
uiSchema: {
|
|
82
|
+
title: "is create",
|
|
83
|
+
type: "boolean",
|
|
84
|
+
"x-component": "Checkbox"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: "boolean",
|
|
89
|
+
name: "isUpdate",
|
|
90
|
+
interface: "checkbox",
|
|
91
|
+
uiSchema: {
|
|
92
|
+
title: "is update",
|
|
93
|
+
type: "boolean",
|
|
94
|
+
"x-component": "Checkbox"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "boolean",
|
|
99
|
+
name: "isDelete",
|
|
100
|
+
interface: "checkbox",
|
|
101
|
+
uiSchema: {
|
|
102
|
+
title: "is delete",
|
|
103
|
+
type: "boolean",
|
|
104
|
+
"x-component": "Checkbox"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "string",
|
|
109
|
+
interface: "collection",
|
|
110
|
+
name: "collection",
|
|
111
|
+
allowNull: false,
|
|
112
|
+
uiSchema: {
|
|
113
|
+
title: "collection",
|
|
114
|
+
type: "string",
|
|
115
|
+
"x-component": "CollectionSelect",
|
|
116
|
+
"x-component-props": {
|
|
117
|
+
multiple: false
|
|
118
|
+
},
|
|
119
|
+
required: true
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "hasMany",
|
|
124
|
+
name: "changes",
|
|
125
|
+
interface: "o2m",
|
|
126
|
+
target: "__auditChange",
|
|
127
|
+
foreignKey: "auditLogId",
|
|
128
|
+
uiSchema: {
|
|
129
|
+
"x-component": "AssociationField",
|
|
130
|
+
"x-component-props": {
|
|
131
|
+
"multiple": true
|
|
132
|
+
},
|
|
133
|
+
"title": "changes"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: "integer",
|
|
138
|
+
name: "ipAddressId",
|
|
139
|
+
isForeignKey: true,
|
|
140
|
+
uiSchema: {
|
|
141
|
+
"type": "number",
|
|
142
|
+
"x-component": "InputNumber",
|
|
143
|
+
"x-component-props": {
|
|
144
|
+
"stringMode": true,
|
|
145
|
+
"step": "1"
|
|
146
|
+
},
|
|
147
|
+
"x-validator": "integer",
|
|
148
|
+
"title": "ip address id"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "belongsTo",
|
|
153
|
+
title: "ip address",
|
|
154
|
+
interface: "m2o",
|
|
155
|
+
name: "ipAddress",
|
|
156
|
+
target: "__ipAddress",
|
|
157
|
+
targetKey: "id",
|
|
158
|
+
sourceKey: "id",
|
|
159
|
+
foreignKey: "ipAddressId",
|
|
160
|
+
uiSchema: {
|
|
161
|
+
"x-component": "AssociationField",
|
|
162
|
+
"x-component-props": {
|
|
163
|
+
"multiple": false
|
|
164
|
+
},
|
|
165
|
+
title: "ip address"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var ipAddress_exports = {};
|
|
28
|
+
__export(ipAddress_exports, {
|
|
29
|
+
default: () => ipAddress_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(ipAddress_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var ipAddress_default = (0, import_database.defineCollection)({
|
|
34
|
+
migrationRules: ["schema-only", "skip"],
|
|
35
|
+
title: "IP Address",
|
|
36
|
+
name: "__ipAddress",
|
|
37
|
+
uiManageable: true,
|
|
38
|
+
createdBy: false,
|
|
39
|
+
updatedBy: false,
|
|
40
|
+
updatedAt: false,
|
|
41
|
+
shared: true,
|
|
42
|
+
autoGenId: true,
|
|
43
|
+
fields: [
|
|
44
|
+
{
|
|
45
|
+
autoIncrement: true,
|
|
46
|
+
primaryKey: true,
|
|
47
|
+
interface: "integer",
|
|
48
|
+
name: "id",
|
|
49
|
+
type: "integer"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "string",
|
|
53
|
+
name: "ip",
|
|
54
|
+
unique: true,
|
|
55
|
+
allowNull: false,
|
|
56
|
+
interface: "input",
|
|
57
|
+
uiSchema: {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"x-component": "Input",
|
|
60
|
+
"x-validator": "string",
|
|
61
|
+
"title": "IP Address"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterCreate(model: any, options: any, ipAddressId: any): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var afterCreate_exports = {};
|
|
28
|
+
__export(afterCreate_exports, {
|
|
29
|
+
afterCreate: () => afterCreate
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(afterCreate_exports);
|
|
32
|
+
async function afterCreate(model, options, ipAddressId) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const { database, collection } = model.constructor;
|
|
35
|
+
await database.getRepository("__auditLog").create({
|
|
36
|
+
values: {
|
|
37
|
+
isCreate: true,
|
|
38
|
+
collection: collection.name,
|
|
39
|
+
recordId: model[collection.filterTargetKey],
|
|
40
|
+
ipAddressId,
|
|
41
|
+
createdBy: (_b = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.state) == null ? void 0 : _b.currentUser
|
|
42
|
+
},
|
|
43
|
+
transaction: options.transaction
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
afterCreate
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterDestroy(model: any, options: any, ipAddressId: any): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var afterDestroy_exports = {};
|
|
28
|
+
__export(afterDestroy_exports, {
|
|
29
|
+
afterDestroy: () => afterDestroy
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(afterDestroy_exports);
|
|
32
|
+
async function afterDestroy(model, options, ipAddressId) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const { database, collection } = model.constructor;
|
|
35
|
+
await database.getRepository("__auditLog").create({
|
|
36
|
+
values: {
|
|
37
|
+
isDelete: true,
|
|
38
|
+
collection: collection.name,
|
|
39
|
+
recordId: model[collection.filterTargetKey],
|
|
40
|
+
ipAddressId,
|
|
41
|
+
createdBy: (_b = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.state) == null ? void 0 : _b.currentUser
|
|
42
|
+
},
|
|
43
|
+
transaction: options.transaction
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
afterDestroy
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterUpdate(model: any, options: any, ipAddressId: any, auditConfig: any): Promise<void>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var afterUpdate_exports = {};
|
|
28
|
+
__export(afterUpdate_exports, {
|
|
29
|
+
afterUpdate: () => afterUpdate
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(afterUpdate_exports);
|
|
32
|
+
async function afterUpdate(model, options, ipAddressId, auditConfig) {
|
|
33
|
+
var _a, _b, _c, _d;
|
|
34
|
+
const { collection, database } = model.constructor;
|
|
35
|
+
const changedFields = model.changed();
|
|
36
|
+
if (!changedFields) return;
|
|
37
|
+
const listenLogic = auditConfig.get("updateListenLogic");
|
|
38
|
+
let allowedFields = [];
|
|
39
|
+
if ((_a = listenLogic == null ? void 0 : listenLogic.blacklist) == null ? void 0 : _a.length)
|
|
40
|
+
allowedFields = changedFields.filter((f) => !listenLogic.blacklist.includes(f));
|
|
41
|
+
else if ((_b = listenLogic == null ? void 0 : listenLogic.whitelist) == null ? void 0 : _b.length)
|
|
42
|
+
allowedFields = changedFields.filter((f) => listenLogic.whitelist.includes(f));
|
|
43
|
+
else
|
|
44
|
+
allowedFields = changedFields;
|
|
45
|
+
if (allowedFields.length == 0) return;
|
|
46
|
+
const changes = [];
|
|
47
|
+
allowedFields.forEach((key) => {
|
|
48
|
+
const field = collection.findField((field2) => {
|
|
49
|
+
return field2.name === key || field2.options.field === key;
|
|
50
|
+
});
|
|
51
|
+
if (field && !field.options.hidden) {
|
|
52
|
+
changes.push({
|
|
53
|
+
fieldName: key,
|
|
54
|
+
before: stringifyValue(model.previous(key)),
|
|
55
|
+
after: stringifyValue(model.get(key))
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const transaction = options.transaction;
|
|
60
|
+
const auditLog = await database.getRepository("__auditLog").create({
|
|
61
|
+
values: {
|
|
62
|
+
recordId: model[collection.filterTargetKey],
|
|
63
|
+
isUpdate: true,
|
|
64
|
+
collection: collection.name,
|
|
65
|
+
ipAddressId,
|
|
66
|
+
createdBy: (_d = (_c = options == null ? void 0 : options.context) == null ? void 0 : _c.state) == null ? void 0 : _d.currentUser
|
|
67
|
+
},
|
|
68
|
+
transaction
|
|
69
|
+
});
|
|
70
|
+
await database.getRepository("__auditChange").createMany({
|
|
71
|
+
records: changes.map((c) => ({ ...c, auditLogId: auditLog.get("id") })),
|
|
72
|
+
transaction
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function stringifyValue(val) {
|
|
76
|
+
if (val === null || val === void 0) return "";
|
|
77
|
+
if (typeof val === "object") return JSON.stringify(val);
|
|
78
|
+
return String(val);
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
afterUpdate
|
|
83
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var server_exports = {};
|
|
28
|
+
__export(server_exports, {
|
|
29
|
+
PluginAuditLogServer: () => PluginAuditLogServer,
|
|
30
|
+
default: () => server_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_afterCreate = require("./hooks/afterCreate");
|
|
35
|
+
var import_afterUpdate = require("./hooks/afterUpdate");
|
|
36
|
+
var import_afterDestroy = require("./hooks/afterDestroy");
|
|
37
|
+
class PluginAuditLogServer extends import_server.Plugin {
|
|
38
|
+
async load() {
|
|
39
|
+
this.db.on("afterCreate", (model, options) => this.afterWrite(model, options, "create"));
|
|
40
|
+
this.db.on("afterUpdate", (model, options) => this.afterWrite(model, options, "update"));
|
|
41
|
+
this.db.on("afterDestroy", (model, options) => this.afterWrite(model, options, "delete"));
|
|
42
|
+
}
|
|
43
|
+
async afterWrite(model, options, type) {
|
|
44
|
+
var _a, _b, _c, _d, _e, _f;
|
|
45
|
+
const { collection } = model.constructor;
|
|
46
|
+
if (!collection) return;
|
|
47
|
+
console.log("filterTargetKey: ", collection.filterTargetKey);
|
|
48
|
+
console.log("primaryKeyAttribute: ", (_a = collection.model) == null ? void 0 : _a.primaryKeyAttribute);
|
|
49
|
+
const config = await this.db.getRepository("__auditConfig").findOne({
|
|
50
|
+
filter: {
|
|
51
|
+
collectionName: collection.name
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (!config) return;
|
|
55
|
+
if (type === "create" && config.get("skipCreate")) return;
|
|
56
|
+
if (type === "delete" && config.get("skipDelete")) return;
|
|
57
|
+
const ip = (_f = (_e = (_d = (_c = (_b = options.context) == null ? void 0 : _b.request) == null ? void 0 : _c.headers) == null ? void 0 : _d["x-forwarded-for"]) == null ? void 0 : _e.split(", ")) == null ? void 0 : _f[0];
|
|
58
|
+
let ipRecord;
|
|
59
|
+
if (ip && !config.get("skipIP"))
|
|
60
|
+
ipRecord = await this.db.getRepository("__ipAddress").firstOrCreate({
|
|
61
|
+
filterKeys: ["ip"],
|
|
62
|
+
values: {
|
|
63
|
+
ip
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (type === "create")
|
|
67
|
+
await (0, import_afterCreate.afterCreate)(model, options, ipRecord.get("id"));
|
|
68
|
+
else if (type === "update")
|
|
69
|
+
await (0, import_afterUpdate.afterUpdate)(model, options, ipRecord.get("id"), config);
|
|
70
|
+
else if (type === "delete")
|
|
71
|
+
await (0, import_afterDestroy.afterDestroy)(model, options, ipRecord.get("id"));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var server_default = PluginAuditLogServer;
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
PluginAuditLogServer
|
|
78
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bunnarin/plugin-audit-log",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"displayName": "Audit logs",
|
|
5
|
+
"displayName.ru-RU": "Журнал аудита",
|
|
6
|
+
"displayName.zh-CN": "审计日志",
|
|
7
|
+
"main": "dist/server/index.js",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@ant-design/icons": "5.x",
|
|
11
|
+
"@formily/antd-v5": "1.x",
|
|
12
|
+
"@formily/react": "2.x",
|
|
13
|
+
"@formily/shared": "2.x",
|
|
14
|
+
"react": "^18.2.0",
|
|
15
|
+
"react-i18next": "^11.15.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@nocobase/client": "2.x",
|
|
19
|
+
"@nocobase/database": "2.x",
|
|
20
|
+
"@nocobase/server": "2.x",
|
|
21
|
+
"@nocobase/test": "2.x"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"System & security"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/bunnarin/plugin-audit-log"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|