diff --git a/pandora_console/api/documentation/swagger-ui-bundle.js b/pandora_console/api/documentation/swagger-ui-bundle.js index 69d6da74a6..c7d16e44f4 100644 --- a/pandora_console/api/documentation/swagger-ui-bundle.js +++ b/pandora_console/api/documentation/swagger-ui-bundle.js @@ -4675,8 +4675,9 @@ return ( "function" == typeof _ && "function" == typeof Symbol && - "symbol" == typeof _("foo") && - "symbol" == typeof Symbol("bar") && w() + "symbol" == typeof _("foo") && + "symbol" == typeof Symbol("bar") && + w() ); }; }, @@ -13386,7 +13387,9 @@ null != s && !w(s) ) || - j.test(s) || !x.test(s) || (null != i && s in Object(i)) + j.test(s) || + !x.test(s) || + (null != i && s in Object(i)) ); }; }, @@ -20230,7 +20233,8 @@ var i = s.memoizedState; if ( (null === i && - null !== (s = s.alternate) && (i = s.memoizedState), + null !== (s = s.alternate) && + (i = s.memoizedState), null !== i) ) return i.dehydrated; @@ -21697,7 +21701,8 @@ null !== ae && ((Z = ae), null !== X && - null != (ae = Kb(ee, X)) && U.push(tf(ee, ae, Z))), + null != (ae = Kb(ee, X)) && + U.push(tf(ee, ae, Z))), Y) ) break; @@ -21894,9 +21899,9 @@ } })(s, u)) && 0 < (_ = oe(_, "onBeforeInput")).length && - ((w = new fr("onBeforeInput", "beforeinput", null, u, w)), - j.push({ event: w, listeners: _ }), - (w.data = ce)); + ((w = new fr("onBeforeInput", "beforeinput", null, u, w)), + j.push({ event: w, listeners: _ }), + (w.data = ce)); } se(j, i); }); @@ -22535,8 +22540,8 @@ var U = s.alternate; null !== U && (P = (U = U.updateQueue).lastBaseUpdate) !== j && - (null === P ? (U.firstBaseUpdate = $) : (P.next = $), - (U.lastBaseUpdate = B)); + (null === P ? (U.firstBaseUpdate = $) : (P.next = $), + (U.lastBaseUpdate = B)); } if (null !== x) { var Y = w.baseState; @@ -22675,7 +22680,8 @@ ? s.shouldComponentUpdate(_, x, j) : !i.prototype || !i.prototype.isPureReactComponent || - !Ie(u, _) || !Ie(w, x); + !Ie(u, _) || + !Ie(w, x); } function ph(s, i, u) { var _ = !1, @@ -25167,11 +25173,11 @@ (s.sibling = null), 5 === s.tag && null !== (i = s.stateNode) && - (delete i[gn], - delete i[yn], - delete i[vn], - delete i[_n], - delete i[wn]), + (delete i[gn], + delete i[yn], + delete i[vn], + delete i[_n], + delete i[wn]), (s.stateNode = null), (s.return = null), (s.dependencies = null), @@ -25282,7 +25288,8 @@ case 15: if ( !Po && - null !== (_ = u.updateQueue) && null !== (_ = _.lastEffect) + null !== (_ = u.updateQueue) && + null !== (_ = _.lastEffect) ) { w = _ = _.next; do { @@ -26026,7 +26033,8 @@ return !0; })(w) && (2 === (i = Jk(s, _)) && - 0 !== (x = xc(s)) && ((_ = x), (i = Ok(s, x))), + 0 !== (x = xc(s)) && + ((_ = x), (i = Ok(s, x))), 1 === i)) ) throw ((u = Go), Lk(s, 0), Dk(s, _), Ek(s, yt()), u); @@ -28469,7 +28477,8 @@ return ( void 0 !== this._readableState && void 0 !== this._writableState && - this._readableState.destroyed && this._writableState.destroyed + this._readableState.destroyed && + this._writableState.destroyed ); }, set: function set(s) { @@ -29506,7 +29515,8 @@ return ( !!$.call(this, s) || (this === Writable && - s && s._writableState instanceof WritableState) + s && + s._writableState instanceof WritableState) ); } })) @@ -33989,7 +33999,8 @@ j = s; if ( "object" == typeof s && - (j = s[(_ = Object.keys(s)[0])]) && j._elem + (j = s[(_ = Object.keys(s)[0])]) && + j._elem ) return ( (j._elem.name = _), @@ -46937,10 +46948,11 @@ !!Jl(s) || (!!s && "object" == typeof s && - !_isString(s) && - (0 === s.length || - (s.length > 0 && - s.hasOwnProperty(0) && s.hasOwnProperty(s.length - 1)))) + !_isString(s) && + (0 === s.length || + (s.length > 0 && + s.hasOwnProperty(0) && + s.hasOwnProperty(s.length - 1)))) ); }); var sc = "undefined" != typeof Symbol ? Symbol.iterator : "@@iterator"; @@ -48536,10 +48548,10 @@ ? !(!s || "object" != typeof s || "string" != typeof s.uri) : ("undefined" != typeof File && s instanceof File) || ("undefined" != typeof Blob && s instanceof Blob) || - !!ArrayBuffer.isView(s) || - (null !== s && - "object" == typeof s && - "function" == typeof s.pipe) + !!ArrayBuffer.isView(s) || + (null !== s && + "object" == typeof s && + "function" == typeof s.pipe) ); } function isArrayOfFile(s, i) { @@ -49050,7 +49062,8 @@ "object" == typeof i && null !== i && "primitive" in i && - "function" == typeof i.primitive && i.primitive() === s, + "function" == typeof i.primitive && + i.primitive() === s, hasClass = (s, i) => "object" == typeof i && null !== i && @@ -58899,13 +58912,12 @@ const parameterEquals = (i, u) => !!s.isParameterElement(i) && !!s.isParameterElement(u) && - !!s.isStringElement(i.name) && - !!s.isStringElement(i.in) && - !!s.isStringElement(u.name) && - !!s.isStringElement(u.in) && - serializers_value(i.name) === - serializers_value(u.name) && - serializers_value(i.in) === serializers_value(u.in), + !!s.isStringElement(i.name) && + !!s.isStringElement(i.in) && + !!s.isStringElement(u.name) && + !!s.isStringElement(u.in) && + serializers_value(i.name) === serializers_value(u.name) && + serializers_value(i.in) === serializers_value(u.in), i = []; return { visitor: { @@ -62689,20 +62701,18 @@ He.createElement( "div", { className: "modal-ux-content" }, - j - .valueSeq() - .map((j, B) => - He.createElement(P, { - key: B, - AST: x, - definitions: j, - getComponent: u, - errSelectors: _, - authSelectors: s, - authActions: i, - specSelectors: w - }) - ) + j.valueSeq().map((j, B) => + He.createElement(P, { + key: B, + AST: x, + definitions: j, + getComponent: u, + errSelectors: _, + authSelectors: s, + authActions: i, + specSelectors: w + }) + ) ) ) ) @@ -65124,15 +65134,13 @@ He.createElement( "tbody", null, - s - .entrySeq() - .map(([s, i]) => - He.createElement(u, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + s.entrySeq().map(([s, i]) => + He.createElement(u, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) ) ) ) @@ -65560,15 +65568,13 @@ He.createElement(_e, { source: _.get("description") }) ), ie && le.size - ? le - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + ? le.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) : null, ae && _.get("content") ? He.createElement( @@ -66472,26 +66478,22 @@ ")" ), Z && et.size - ? et - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + ? et.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) : null, X && tt.size - ? tt - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + ? tt.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) : null ), He.createElement( @@ -68903,16 +68905,14 @@ He.createElement("span", { className: "brace-close" }, "}") ), ye.size - ? ye - .entrySeq() - .map(([s, i]) => - He.createElement(Re, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: "property" - }) - ) + ? ye.entrySeq().map(([s, i]) => + He.createElement(Re, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: "property" + }) + ) : null ); } @@ -69093,28 +69093,24 @@ ")" ), ae.size - ? ae - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: eI - }) - ) + ? ae.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: eI + }) + ) : null, P && ee.size - ? ee - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: eI - }) - ) + ? ee.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: eI + }) + ) : null, Z ? He.createElement(ce, { source: Z }) : null, ie && @@ -69448,12 +69444,13 @@ return ( !(s >= 55296 && s <= 57343) && !(s >= 64976 && s <= 65007) && - 65535 != (65535 & s) && - 65534 != (65535 & s) && - !(s >= 0 && s <= 8) && - 11 !== s && - !(s >= 14 && s <= 31) && - !(s >= 127 && s <= 159) && !(s > 1114111) + 65535 != (65535 & s) && + 65534 != (65535 & s) && + !(s >= 0 && s <= 8) && + 11 !== s && + !(s >= 14 && s <= 31) && + !(s >= 127 && s <= 159) && + !(s > 1114111) ); } function fromCodePoint(s) { @@ -71014,37 +71011,37 @@ return ( P !== $ + 2 && !(P + 1 >= U || 58 !== s.src.charCodeAt(++P)) && - (_ || - (P++, - s.env.footnotes || (s.env.footnotes = {}), - s.env.footnotes.refs || (s.env.footnotes.refs = {}), - (B = s.src.slice($ + 2, P - 2)), - (s.env.footnotes.refs[":" + B] = -1), - s.tokens.push({ - type: "footnote_reference_open", - label: B, - level: s.level++ - }), - (w = s.bMarks[i]), - (x = s.tShift[i]), - (j = s.parentType), - (s.tShift[i] = s.skipSpaces(P) - P), - (s.bMarks[i] = P), - (s.blkIndent += 4), - (s.parentType = "footnote"), - s.tShift[i] < s.blkIndent && - ((s.tShift[i] += s.blkIndent), - (s.bMarks[i] -= s.blkIndent)), - s.parser.tokenize(s, i, u, !0), - (s.parentType = j), - (s.blkIndent -= 4), - (s.tShift[i] = x), - (s.bMarks[i] = w), - s.tokens.push({ - type: "footnote_reference_close", - level: --s.level - })), - !0) + (_ || + (P++, + s.env.footnotes || (s.env.footnotes = {}), + s.env.footnotes.refs || (s.env.footnotes.refs = {}), + (B = s.src.slice($ + 2, P - 2)), + (s.env.footnotes.refs[":" + B] = -1), + s.tokens.push({ + type: "footnote_reference_open", + label: B, + level: s.level++ + }), + (w = s.bMarks[i]), + (x = s.tShift[i]), + (j = s.parentType), + (s.tShift[i] = s.skipSpaces(P) - P), + (s.bMarks[i] = P), + (s.blkIndent += 4), + (s.parentType = "footnote"), + s.tShift[i] < s.blkIndent && + ((s.tShift[i] += s.blkIndent), + (s.bMarks[i] -= s.blkIndent)), + s.parser.tokenize(s, i, u, !0), + (s.parentType = j), + (s.blkIndent -= 4), + (s.tShift[i] = x), + (s.bMarks[i] = w), + s.tokens.push({ + type: "footnote_reference_close", + level: --s.level + })), + !0) ); }, ["paragraph"] @@ -71107,32 +71104,32 @@ return ( !(j >= u) && !(s.tShift[j] < s.blkIndent) && - !(s.tShift[j] - s.blkIndent > 3) && - !((w = s.bMarks[j] + s.tShift[j]) >= (x = s.eMarks[j])) && - (45 === (_ = s.src.charCodeAt(w)) || 61 === _) && - ((w = s.skipChars(w, _)), - !((w = s.skipSpaces(w)) < x) && - ((w = s.bMarks[i] + s.tShift[i]), - (s.line = j + 1), - s.tokens.push({ - type: "heading_open", - hLevel: 61 === _ ? 1 : 2, - lines: [i, s.line], - level: s.level - }), - s.tokens.push({ - type: "inline", - content: s.src.slice(w, s.eMarks[i]).trim(), - level: s.level + 1, - lines: [i, s.line - 1], - children: [] - }), - s.tokens.push({ - type: "heading_close", - hLevel: 61 === _ ? 1 : 2, - level: s.level - }), - !0)) + !(s.tShift[j] - s.blkIndent > 3) && + !((w = s.bMarks[j] + s.tShift[j]) >= (x = s.eMarks[j])) && + (45 === (_ = s.src.charCodeAt(w)) || 61 === _) && + ((w = s.skipChars(w, _)), + !((w = s.skipSpaces(w)) < x) && + ((w = s.bMarks[i] + s.tShift[i]), + (s.line = j + 1), + s.tokens.push({ + type: "heading_open", + hLevel: 61 === _ ? 1 : 2, + lines: [i, s.line], + level: s.level + }), + s.tokens.push({ + type: "inline", + content: s.src.slice(w, s.eMarks[i]).trim(), + level: s.level + 1, + lines: [i, s.line - 1], + children: [] + }), + s.tokens.push({ + type: "heading_close", + hLevel: 61 === _ ? 1 : 2, + level: s.level + }), + !0)) ); } ], @@ -72276,31 +72273,31 @@ return ( !(P + 2 >= j) && 94 === s.src.charCodeAt(P) && - 91 === s.src.charCodeAt(P + 1) && - !(s.level >= s.options.maxNesting) && - ((u = P + 2), - !((_ = parseLinkLabel(s, P + 1)) < 0) && - (i || - (s.env.footnotes || (s.env.footnotes = {}), - s.env.footnotes.list || (s.env.footnotes.list = []), - (w = s.env.footnotes.list.length), - (s.pos = u), - (s.posMax = _), - s.push({ - type: "footnote_ref", - id: w, - level: s.level - }), - s.linkLevel++, - (x = s.tokens.length), - s.parser.tokenize(s), - (s.env.footnotes.list[w] = { - tokens: s.tokens.splice(x) - }), - s.linkLevel--), - (s.pos = _ + 1), - (s.posMax = j), - !0)) + 91 === s.src.charCodeAt(P + 1) && + !(s.level >= s.options.maxNesting) && + ((u = P + 2), + !((_ = parseLinkLabel(s, P + 1)) < 0) && + (i || + (s.env.footnotes || (s.env.footnotes = {}), + s.env.footnotes.list || (s.env.footnotes.list = []), + (w = s.env.footnotes.list.length), + (s.pos = u), + (s.posMax = _), + s.push({ + type: "footnote_ref", + id: w, + level: s.level + }), + s.linkLevel++, + (x = s.tokens.length), + s.parser.tokenize(s), + (s.env.footnotes.list[w] = { + tokens: s.tokens.splice(x) + }), + s.linkLevel--), + (s.pos = _ + 1), + (s.posMax = j), + !0)) ); } ], @@ -72326,27 +72323,27 @@ return ( _ !== P + 2 && !(_ >= j) && - (_++, - (u = s.src.slice(P + 2, _ - 1)), - void 0 !== s.env.footnotes.refs[":" + u] && - (i || - (s.env.footnotes.list || (s.env.footnotes.list = []), - s.env.footnotes.refs[":" + u] < 0 - ? ((w = s.env.footnotes.list.length), - (s.env.footnotes.list[w] = { label: u, count: 0 }), - (s.env.footnotes.refs[":" + u] = w)) - : (w = s.env.footnotes.refs[":" + u]), - (x = s.env.footnotes.list[w].count), - s.env.footnotes.list[w].count++, - s.push({ - type: "footnote_ref", - id: w, - subId: x, - level: s.level - })), - (s.pos = _), - (s.posMax = j), - !0)) + (_++, + (u = s.src.slice(P + 2, _ - 1)), + void 0 !== s.env.footnotes.refs[":" + u] && + (i || + (s.env.footnotes.list || (s.env.footnotes.list = []), + s.env.footnotes.refs[":" + u] < 0 + ? ((w = s.env.footnotes.list.length), + (s.env.footnotes.list[w] = { label: u, count: 0 }), + (s.env.footnotes.refs[":" + u] = w)) + : (w = s.env.footnotes.refs[":" + u]), + (x = s.env.footnotes.list[w].count), + s.env.footnotes.list[w].count++, + s.push({ + type: "footnote_ref", + id: w, + subId: x, + level: s.level + })), + (s.pos = _), + (s.posMax = j), + !0)) ); } ], @@ -72362,41 +72359,41 @@ return ( 60 === s.src.charCodeAt(P) && !((u = s.src.slice(P)).indexOf(">") < 0) && - ((_ = u.match(NI)) - ? !(II.indexOf(_[1].toLowerCase()) < 0) && - ((j = normalizeLink((x = _[0].slice(1, -1)))), - !!s.parser.validateLink(x) && - (i || - (s.push({ - type: "link_open", - href: j, - level: s.level - }), - s.push({ - type: "text", - content: x, - level: s.level + 1 - }), - s.push({ type: "link_close", level: s.level })), - (s.pos += _[0].length), - !0)) - : !!(w = u.match(PI)) && - ((j = normalizeLink("mailto:" + (x = w[0].slice(1, -1)))), - !!s.parser.validateLink(j) && - (i || - (s.push({ - type: "link_open", - href: j, - level: s.level - }), - s.push({ - type: "text", - content: x, - level: s.level + 1 - }), - s.push({ type: "link_close", level: s.level })), - (s.pos += w[0].length), - !0))) + ((_ = u.match(NI)) + ? !(II.indexOf(_[1].toLowerCase()) < 0) && + ((j = normalizeLink((x = _[0].slice(1, -1)))), + !!s.parser.validateLink(x) && + (i || + (s.push({ + type: "link_open", + href: j, + level: s.level + }), + s.push({ + type: "text", + content: x, + level: s.level + 1 + }), + s.push({ type: "link_close", level: s.level })), + (s.pos += _[0].length), + !0)) + : !!(w = u.match(PI)) && + ((j = normalizeLink("mailto:" + (x = w[0].slice(1, -1)))), + !!s.parser.validateLink(j) && + (i || + (s.push({ + type: "link_open", + href: j, + level: s.level + }), + s.push({ + type: "text", + content: x, + level: s.level + 1 + }), + s.push({ type: "link_close", level: s.level })), + (s.pos += w[0].length), + !0))) ); } ], @@ -72420,15 +72417,15 @@ return i >= 97 && i <= 122; })(u) ) && - !!(_ = s.src.slice(x).match(DI)) && - (i || - s.push({ - type: "htmltag", - content: s.src.slice(x, x + _[0].length), - level: s.level - }), - (s.pos += _[0].length), - !0)) + !!(_ = s.src.slice(x).match(DI)) && + (i || + s.push({ + type: "htmltag", + content: s.src.slice(x, x + _[0].length), + level: s.level + }), + (s.pos += _[0].length), + !0)) ); } ], @@ -73554,7 +73551,7 @@ return ( !(!s || !i) && !this.hasFullProtocolRegex.test(i) && - !this.hasWordCharAfterProtocolRegex.test(s) + !this.hasWordCharAfterProtocolRegex.test(s) ); }), (UrlMatchValidator.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//), @@ -75977,19 +75974,17 @@ ? He.createElement( "select", { "data-variable": s, onChange: $ }, - u - .get("enum") - .map(u => - He.createElement( - "option", - { - selected: u === w(i, s), - key: u, - value: u - }, - u - ) + u.get("enum").map(u => + He.createElement( + "option", + { + selected: u === w(i, s), + key: u, + value: u + }, + u ) + ) ) : He.createElement("input", { type: "text", @@ -80766,7 +80761,8 @@ const { examples: i, example: u, default: _ } = s; return ( !!(Array.isArray(i) && i.length >= 1) || - void 0 !== _ || void 0 !== u + void 0 !== _ || + void 0 !== u ); }, extractExample = s => { diff --git a/pandora_console/api/documentation/swagger-ui-es-bundle-core.js b/pandora_console/api/documentation/swagger-ui-es-bundle-core.js index a0770fdc9b..0897eadaf3 100644 --- a/pandora_console/api/documentation/swagger-ui-es-bundle-core.js +++ b/pandora_console/api/documentation/swagger-ui-es-bundle-core.js @@ -2323,7 +2323,8 @@ var ve = { return ( void 0 !== this._readableState && void 0 !== this._writableState && - this._readableState.destroyed && this._writableState.destroyed + this._readableState.destroyed && + this._writableState.destroyed ); }, set: function set(e) { @@ -3336,7 +3337,8 @@ var ve = { return ( !!c.call(this, e) || (this === Writable && - e && e._writableState instanceof WritableState) + e && + e._writableState instanceof WritableState) ); } })) @@ -10833,20 +10835,18 @@ var we = {}; Ke.default.createElement( "div", { className: "modal-ux-content" }, - s - .valueSeq() - .map((s, i) => - Ke.default.createElement(l, { - key: i, - AST: o, - definitions: s, - getComponent: r, - errSelectors: n, - authSelectors: e, - authActions: t, - specSelectors: a - }) - ) + s.valueSeq().map((s, i) => + Ke.default.createElement(l, { + key: i, + AST: o, + definitions: s, + getComponent: r, + errSelectors: n, + authSelectors: e, + authActions: t, + specSelectors: a + }) + ) ) ) ) @@ -13194,15 +13194,13 @@ var we = {}; Ke.default.createElement( "tbody", null, - e - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(r, { - key: `${e}-${t}`, - xKey: e, - xVal: t - }) - ) + e.entrySeq().map(([e, t]) => + Ke.default.createElement(r, { + key: `${e}-${t}`, + xKey: e, + xVal: t + }) + ) ) ) ) @@ -13627,15 +13625,13 @@ var we = {}; Ke.default.createElement(x, { source: n.get("description") }) ), g && y.size - ? y - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(v, { - key: `${e}-${t}`, - xKey: e, - xVal: t - }) - ) + ? y.entrySeq().map(([e, t]) => + Ke.default.createElement(v, { + key: `${e}-${t}`, + xKey: e, + xVal: t + }) + ) : null, h && n.get("content") ? Ke.default.createElement( @@ -16688,16 +16684,14 @@ var we = {}; Ke.default.createElement("span", { className: "brace-close" }, "}") ), w.size - ? w - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(R, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: "property" - }) - ) + ? w.entrySeq().map(([e, t]) => + Ke.default.createElement(R, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: "property" + }) + ) : null ); } @@ -16748,16 +16742,14 @@ var we = {}; { title: _, expanded: n <= a, collapsedContent: "[...]" }, "[", d.size - ? d - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(y, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: "property" - }) - ) + ? d.entrySeq().map(([e, t]) => + Ke.default.createElement(y, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: "property" + }) + ) : null, i ? Ke.default.createElement(f, { source: i }) @@ -16874,28 +16866,24 @@ var we = {}; ")" ), h.size - ? h - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(v, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: ka - }) - ) + ? h.entrySeq().map(([e, t]) => + Ke.default.createElement(v, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: ka + }) + ) : null, l && f.size - ? f - .entrySeq() - .map(([e, t]) => - Ke.default.createElement(v, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: ka - }) - ) + ? f.entrySeq().map(([e, t]) => + Ke.default.createElement(v, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: ka + }) + ) : null, m ? Ke.default.createElement(S, { source: m }) : null, g && @@ -18263,15 +18251,13 @@ var we = {}; ")" ), x && c.size - ? c - .entrySeq() - .map(([e, r]) => - Ke.default.createElement(t, { - key: `${e}-${r}`, - xKey: e, - xVal: r - }) - ) + ? c.entrySeq().map(([e, r]) => + Ke.default.createElement(t, { + key: `${e}-${r}`, + xKey: e, + xVal: r + }) + ) : null ), Ke.default.createElement( @@ -20384,10 +20370,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !c - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !c + } + ) }, c && Ke.default.createElement( @@ -20577,10 +20565,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !c - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !c + } + ) }, c && Ke.default.createElement( @@ -20661,10 +20651,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !c - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !c + } + ) }, c && Ke.default.createElement( @@ -21224,10 +21216,12 @@ var we = {}; "li", { key: e, - className: (0, - ha.default)("json-schema-2020-12-$vocabulary-uri", { - "json-schema-2020-12-$vocabulary-uri--disabled": !t - }) + className: (0, ha.default)( + "json-schema-2020-12-$vocabulary-uri", + { + "json-schema-2020-12-$vocabulary-uri--disabled": !t + } + ) }, Ke.default.createElement( "span", @@ -21422,10 +21416,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !n - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !n + } + ) }, n && Ke.default.createElement( @@ -21512,10 +21508,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !a - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !a + } + ) }, a && Ke.default.createElement( @@ -21583,10 +21581,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !a - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !a + } + ) }, a && Ke.default.createElement( @@ -21654,10 +21654,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !a - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !a + } + ) }, a && Ke.default.createElement( @@ -21813,10 +21815,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !n - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !n + } + ) }, n && Ke.default.createElement( @@ -21877,10 +21881,12 @@ var we = {}; Ke.default.createElement( "ul", { - className: (0, - ha.default)("json-schema-2020-12-keyword__children", { - "json-schema-2020-12-keyword__children--collapsed": !a - }) + className: (0, ha.default)( + "json-schema-2020-12-keyword__children", + { + "json-schema-2020-12-keyword__children--collapsed": !a + } + ) }, a && Ke.default.createElement( diff --git a/pandora_console/api/documentation/swagger-ui-es-bundle.js b/pandora_console/api/documentation/swagger-ui-es-bundle.js index 53039891ad..d0cbef7112 100644 --- a/pandora_console/api/documentation/swagger-ui-es-bundle.js +++ b/pandora_console/api/documentation/swagger-ui-es-bundle.js @@ -4587,8 +4587,9 @@ return ( "function" == typeof _ && "function" == typeof Symbol && - "symbol" == typeof _("foo") && - "symbol" == typeof Symbol("bar") && w() + "symbol" == typeof _("foo") && + "symbol" == typeof Symbol("bar") && + w() ); }; }, @@ -13205,7 +13206,9 @@ null != s && !w(s) ) || - j.test(s) || !x.test(s) || (null != i && s in Object(i)) + j.test(s) || + !x.test(s) || + (null != i && s in Object(i)) ); }; }, @@ -19958,7 +19961,8 @@ var i = s.memoizedState; if ( (null === i && - null !== (s = s.alternate) && (i = s.memoizedState), + null !== (s = s.alternate) && + (i = s.memoizedState), null !== i) ) return i.dehydrated; @@ -21407,7 +21411,8 @@ null !== ae && ((Z = ae), null !== X && - null != (ae = Kb(ee, X)) && U.push(tf(ee, ae, Z))), + null != (ae = Kb(ee, X)) && + U.push(tf(ee, ae, Z))), Y) ) break; @@ -21603,9 +21608,9 @@ } })(s, u)) && 0 < (_ = oe(_, "onBeforeInput")).length && - ((w = new fr("onBeforeInput", "beforeinput", null, u, w)), - j.push({ event: w, listeners: _ }), - (w.data = ce)); + ((w = new fr("onBeforeInput", "beforeinput", null, u, w)), + j.push({ event: w, listeners: _ }), + (w.data = ce)); } se(j, i); }); @@ -22232,8 +22237,8 @@ var U = s.alternate; null !== U && (P = (U = U.updateQueue).lastBaseUpdate) !== j && - (null === P ? (U.firstBaseUpdate = $) : (P.next = $), - (U.lastBaseUpdate = B)); + (null === P ? (U.firstBaseUpdate = $) : (P.next = $), + (U.lastBaseUpdate = B)); } if (null !== x) { var Y = w.baseState; @@ -22372,7 +22377,8 @@ ? s.shouldComponentUpdate(_, x, j) : !i.prototype || !i.prototype.isPureReactComponent || - !Ie(u, _) || !Ie(w, x); + !Ie(u, _) || + !Ie(w, x); } function ph(s, i, u) { var _ = !1, @@ -24842,11 +24848,11 @@ (s.sibling = null), 5 === s.tag && null !== (i = s.stateNode) && - (delete i[gn], - delete i[yn], - delete i[vn], - delete i[_n], - delete i[wn]), + (delete i[gn], + delete i[yn], + delete i[vn], + delete i[_n], + delete i[wn]), (s.stateNode = null), (s.return = null), (s.dependencies = null), @@ -24957,7 +24963,8 @@ case 15: if ( !Po && - null !== (_ = u.updateQueue) && null !== (_ = _.lastEffect) + null !== (_ = u.updateQueue) && + null !== (_ = _.lastEffect) ) { w = _ = _.next; do { @@ -25693,7 +25700,8 @@ return !0; })(w) && (2 === (i = Jk(s, _)) && - 0 !== (x = xc(s)) && ((_ = x), (i = Ok(s, x))), + 0 !== (x = xc(s)) && + ((_ = x), (i = Ok(s, x))), 1 === i)) ) throw ((u = Go), Lk(s, 0), Dk(s, _), Ek(s, yt()), u); @@ -28109,7 +28117,8 @@ return ( void 0 !== this._readableState && void 0 !== this._writableState && - this._readableState.destroyed && this._writableState.destroyed + this._readableState.destroyed && + this._writableState.destroyed ); }, set: function set(s) { @@ -29135,7 +29144,8 @@ return ( !!$.call(this, s) || (this === Writable && - s && s._writableState instanceof WritableState) + s && + s._writableState instanceof WritableState) ); } })) @@ -33559,7 +33569,8 @@ j = s; if ( "object" == typeof s && - (j = s[(_ = Object.keys(s)[0])]) && j._elem + (j = s[(_ = Object.keys(s)[0])]) && + j._elem ) return ( (j._elem.name = _), @@ -46143,10 +46154,11 @@ !!Jl(s) || (!!s && "object" == typeof s && - !_isString(s) && - (0 === s.length || - (s.length > 0 && - s.hasOwnProperty(0) && s.hasOwnProperty(s.length - 1)))) + !_isString(s) && + (0 === s.length || + (s.length > 0 && + s.hasOwnProperty(0) && + s.hasOwnProperty(s.length - 1)))) ); }); var sc = "undefined" != typeof Symbol ? Symbol.iterator : "@@iterator"; @@ -47695,10 +47707,8 @@ ? !(!s || "object" != typeof s || "string" != typeof s.uri) : ("undefined" != typeof File && s instanceof File) || ("undefined" != typeof Blob && s instanceof Blob) || - !!ArrayBuffer.isView(s) || - (null !== s && - "object" == typeof s && - "function" == typeof s.pipe) + !!ArrayBuffer.isView(s) || + (null !== s && "object" == typeof s && "function" == typeof s.pipe) ); } function isArrayOfFile(s, i) { @@ -48197,7 +48207,8 @@ "object" == typeof i && null !== i && "primitive" in i && - "function" == typeof i.primitive && i.primitive() === s, + "function" == typeof i.primitive && + i.primitive() === s, hasClass = (s, i) => "object" == typeof i && null !== i && @@ -57589,12 +57600,12 @@ const parameterEquals = (i, u) => !!s.isParameterElement(i) && !!s.isParameterElement(u) && - !!s.isStringElement(i.name) && - !!s.isStringElement(i.in) && - !!s.isStringElement(u.name) && - !!s.isStringElement(u.in) && - serializers_value(i.name) === serializers_value(u.name) && - serializers_value(i.in) === serializers_value(u.in), + !!s.isStringElement(i.name) && + !!s.isStringElement(i.in) && + !!s.isStringElement(u.name) && + !!s.isStringElement(u.in) && + serializers_value(i.name) === serializers_value(u.name) && + serializers_value(i.in) === serializers_value(u.in), i = []; return { visitor: { @@ -61244,20 +61255,18 @@ He.createElement( "div", { className: "modal-ux-content" }, - j - .valueSeq() - .map((j, B) => - He.createElement(P, { - key: B, - AST: x, - definitions: j, - getComponent: u, - errSelectors: _, - authSelectors: s, - authActions: i, - specSelectors: w - }) - ) + j.valueSeq().map((j, B) => + He.createElement(P, { + key: B, + AST: x, + definitions: j, + getComponent: u, + errSelectors: _, + authSelectors: s, + authActions: i, + specSelectors: w + }) + ) ) ) ) @@ -64919,26 +64928,22 @@ ")" ), Z && et.size - ? et - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + ? et.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) : null, X && tt.size - ? tt - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - xKey: s, - xVal: i - }) - ) + ? tt.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + xKey: s, + xVal: i + }) + ) : null ), He.createElement( @@ -67252,16 +67257,14 @@ He.createElement("span", { className: "brace-close" }, "}") ), ye.size - ? ye - .entrySeq() - .map(([s, i]) => - He.createElement(Re, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: "property" - }) - ) + ? ye.entrySeq().map(([s, i]) => + He.createElement(Re, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: "property" + }) + ) : null ); } @@ -67430,28 +67433,24 @@ ")" ), ae.size - ? ae - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: eI - }) - ) + ? ae.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: eI + }) + ) : null, P && ee.size - ? ee - .entrySeq() - .map(([s, i]) => - He.createElement(de, { - key: `${s}-${i}`, - propKey: s, - propVal: i, - propClass: eI - }) - ) + ? ee.entrySeq().map(([s, i]) => + He.createElement(de, { + key: `${s}-${i}`, + propKey: s, + propVal: i, + propClass: eI + }) + ) : null, Z ? He.createElement(ce, { source: Z }) : null, ie && @@ -67779,12 +67778,13 @@ return ( !(s >= 55296 && s <= 57343) && !(s >= 64976 && s <= 65007) && - 65535 != (65535 & s) && - 65534 != (65535 & s) && - !(s >= 0 && s <= 8) && - 11 !== s && - !(s >= 14 && s <= 31) && - !(s >= 127 && s <= 159) && !(s > 1114111) + 65535 != (65535 & s) && + 65534 != (65535 & s) && + !(s >= 0 && s <= 8) && + 11 !== s && + !(s >= 14 && s <= 31) && + !(s >= 127 && s <= 159) && + !(s > 1114111) ); } function fromCodePoint(s) { @@ -69288,36 +69288,36 @@ return ( P !== $ + 2 && !(P + 1 >= U || 58 !== s.src.charCodeAt(++P)) && - (_ || - (P++, - s.env.footnotes || (s.env.footnotes = {}), - s.env.footnotes.refs || (s.env.footnotes.refs = {}), - (B = s.src.slice($ + 2, P - 2)), - (s.env.footnotes.refs[":" + B] = -1), - s.tokens.push({ - type: "footnote_reference_open", - label: B, - level: s.level++ - }), - (w = s.bMarks[i]), - (x = s.tShift[i]), - (j = s.parentType), - (s.tShift[i] = s.skipSpaces(P) - P), - (s.bMarks[i] = P), - (s.blkIndent += 4), - (s.parentType = "footnote"), - s.tShift[i] < s.blkIndent && - ((s.tShift[i] += s.blkIndent), (s.bMarks[i] -= s.blkIndent)), - s.parser.tokenize(s, i, u, !0), - (s.parentType = j), - (s.blkIndent -= 4), - (s.tShift[i] = x), - (s.bMarks[i] = w), - s.tokens.push({ - type: "footnote_reference_close", - level: --s.level - })), - !0) + (_ || + (P++, + s.env.footnotes || (s.env.footnotes = {}), + s.env.footnotes.refs || (s.env.footnotes.refs = {}), + (B = s.src.slice($ + 2, P - 2)), + (s.env.footnotes.refs[":" + B] = -1), + s.tokens.push({ + type: "footnote_reference_open", + label: B, + level: s.level++ + }), + (w = s.bMarks[i]), + (x = s.tShift[i]), + (j = s.parentType), + (s.tShift[i] = s.skipSpaces(P) - P), + (s.bMarks[i] = P), + (s.blkIndent += 4), + (s.parentType = "footnote"), + s.tShift[i] < s.blkIndent && + ((s.tShift[i] += s.blkIndent), (s.bMarks[i] -= s.blkIndent)), + s.parser.tokenize(s, i, u, !0), + (s.parentType = j), + (s.blkIndent -= 4), + (s.tShift[i] = x), + (s.bMarks[i] = w), + s.tokens.push({ + type: "footnote_reference_close", + level: --s.level + })), + !0) ); }, ["paragraph"] @@ -69376,32 +69376,32 @@ return ( !(j >= u) && !(s.tShift[j] < s.blkIndent) && - !(s.tShift[j] - s.blkIndent > 3) && - !((w = s.bMarks[j] + s.tShift[j]) >= (x = s.eMarks[j])) && - (45 === (_ = s.src.charCodeAt(w)) || 61 === _) && - ((w = s.skipChars(w, _)), - !((w = s.skipSpaces(w)) < x) && - ((w = s.bMarks[i] + s.tShift[i]), - (s.line = j + 1), - s.tokens.push({ - type: "heading_open", - hLevel: 61 === _ ? 1 : 2, - lines: [i, s.line], - level: s.level - }), - s.tokens.push({ - type: "inline", - content: s.src.slice(w, s.eMarks[i]).trim(), - level: s.level + 1, - lines: [i, s.line - 1], - children: [] - }), - s.tokens.push({ - type: "heading_close", - hLevel: 61 === _ ? 1 : 2, - level: s.level - }), - !0)) + !(s.tShift[j] - s.blkIndent > 3) && + !((w = s.bMarks[j] + s.tShift[j]) >= (x = s.eMarks[j])) && + (45 === (_ = s.src.charCodeAt(w)) || 61 === _) && + ((w = s.skipChars(w, _)), + !((w = s.skipSpaces(w)) < x) && + ((w = s.bMarks[i] + s.tShift[i]), + (s.line = j + 1), + s.tokens.push({ + type: "heading_open", + hLevel: 61 === _ ? 1 : 2, + lines: [i, s.line], + level: s.level + }), + s.tokens.push({ + type: "inline", + content: s.src.slice(w, s.eMarks[i]).trim(), + level: s.level + 1, + lines: [i, s.line - 1], + children: [] + }), + s.tokens.push({ + type: "heading_close", + hLevel: 61 === _ ? 1 : 2, + level: s.level + }), + !0)) ); } ], @@ -70516,27 +70516,27 @@ return ( !(P + 2 >= j) && 94 === s.src.charCodeAt(P) && - 91 === s.src.charCodeAt(P + 1) && - !(s.level >= s.options.maxNesting) && - ((u = P + 2), - !((_ = parseLinkLabel(s, P + 1)) < 0) && - (i || - (s.env.footnotes || (s.env.footnotes = {}), - s.env.footnotes.list || (s.env.footnotes.list = []), - (w = s.env.footnotes.list.length), - (s.pos = u), - (s.posMax = _), - s.push({ type: "footnote_ref", id: w, level: s.level }), - s.linkLevel++, - (x = s.tokens.length), - s.parser.tokenize(s), - (s.env.footnotes.list[w] = { - tokens: s.tokens.splice(x) - }), - s.linkLevel--), - (s.pos = _ + 1), - (s.posMax = j), - !0)) + 91 === s.src.charCodeAt(P + 1) && + !(s.level >= s.options.maxNesting) && + ((u = P + 2), + !((_ = parseLinkLabel(s, P + 1)) < 0) && + (i || + (s.env.footnotes || (s.env.footnotes = {}), + s.env.footnotes.list || (s.env.footnotes.list = []), + (w = s.env.footnotes.list.length), + (s.pos = u), + (s.posMax = _), + s.push({ type: "footnote_ref", id: w, level: s.level }), + s.linkLevel++, + (x = s.tokens.length), + s.parser.tokenize(s), + (s.env.footnotes.list[w] = { + tokens: s.tokens.splice(x) + }), + s.linkLevel--), + (s.pos = _ + 1), + (s.posMax = j), + !0)) ); } ], @@ -70562,27 +70562,27 @@ return ( _ !== P + 2 && !(_ >= j) && - (_++, - (u = s.src.slice(P + 2, _ - 1)), - void 0 !== s.env.footnotes.refs[":" + u] && - (i || - (s.env.footnotes.list || (s.env.footnotes.list = []), - s.env.footnotes.refs[":" + u] < 0 - ? ((w = s.env.footnotes.list.length), - (s.env.footnotes.list[w] = { label: u, count: 0 }), - (s.env.footnotes.refs[":" + u] = w)) - : (w = s.env.footnotes.refs[":" + u]), - (x = s.env.footnotes.list[w].count), - s.env.footnotes.list[w].count++, - s.push({ - type: "footnote_ref", - id: w, - subId: x, - level: s.level - })), - (s.pos = _), - (s.posMax = j), - !0)) + (_++, + (u = s.src.slice(P + 2, _ - 1)), + void 0 !== s.env.footnotes.refs[":" + u] && + (i || + (s.env.footnotes.list || (s.env.footnotes.list = []), + s.env.footnotes.refs[":" + u] < 0 + ? ((w = s.env.footnotes.list.length), + (s.env.footnotes.list[w] = { label: u, count: 0 }), + (s.env.footnotes.refs[":" + u] = w)) + : (w = s.env.footnotes.refs[":" + u]), + (x = s.env.footnotes.list[w].count), + s.env.footnotes.list[w].count++, + s.push({ + type: "footnote_ref", + id: w, + subId: x, + level: s.level + })), + (s.pos = _), + (s.posMax = j), + !0)) ); } ], @@ -70598,25 +70598,25 @@ return ( 60 === s.src.charCodeAt(P) && !((u = s.src.slice(P)).indexOf(">") < 0) && - ((_ = u.match(NI)) - ? !(II.indexOf(_[1].toLowerCase()) < 0) && - ((j = normalizeLink((x = _[0].slice(1, -1)))), - !!s.parser.validateLink(x) && - (i || - (s.push({ type: "link_open", href: j, level: s.level }), - s.push({ type: "text", content: x, level: s.level + 1 }), - s.push({ type: "link_close", level: s.level })), - (s.pos += _[0].length), - !0)) - : !!(w = u.match(PI)) && - ((j = normalizeLink("mailto:" + (x = w[0].slice(1, -1)))), - !!s.parser.validateLink(j) && - (i || - (s.push({ type: "link_open", href: j, level: s.level }), - s.push({ type: "text", content: x, level: s.level + 1 }), - s.push({ type: "link_close", level: s.level })), - (s.pos += w[0].length), - !0))) + ((_ = u.match(NI)) + ? !(II.indexOf(_[1].toLowerCase()) < 0) && + ((j = normalizeLink((x = _[0].slice(1, -1)))), + !!s.parser.validateLink(x) && + (i || + (s.push({ type: "link_open", href: j, level: s.level }), + s.push({ type: "text", content: x, level: s.level + 1 }), + s.push({ type: "link_close", level: s.level })), + (s.pos += _[0].length), + !0)) + : !!(w = u.match(PI)) && + ((j = normalizeLink("mailto:" + (x = w[0].slice(1, -1)))), + !!s.parser.validateLink(j) && + (i || + (s.push({ type: "link_open", href: j, level: s.level }), + s.push({ type: "text", content: x, level: s.level + 1 }), + s.push({ type: "link_close", level: s.level })), + (s.pos += w[0].length), + !0))) ); } ], @@ -70640,15 +70640,15 @@ return i >= 97 && i <= 122; })(u) ) && - !!(_ = s.src.slice(x).match(DI)) && - (i || - s.push({ - type: "htmltag", - content: s.src.slice(x, x + _[0].length), - level: s.level - }), - (s.pos += _[0].length), - !0)) + !!(_ = s.src.slice(x).match(DI)) && + (i || + s.push({ + type: "htmltag", + content: s.src.slice(x, x + _[0].length), + level: s.level + }), + (s.pos += _[0].length), + !0)) ); } ], @@ -71740,7 +71740,7 @@ return ( !(!s || !i) && !this.hasFullProtocolRegex.test(i) && - !this.hasWordCharAfterProtocolRegex.test(s) + !this.hasWordCharAfterProtocolRegex.test(s) ); }), (UrlMatchValidator.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//), @@ -74095,19 +74095,17 @@ ? He.createElement( "select", { "data-variable": s, onChange: $ }, - u - .get("enum") - .map(u => - He.createElement( - "option", - { - selected: u === w(i, s), - key: u, - value: u - }, - u - ) + u.get("enum").map(u => + He.createElement( + "option", + { + selected: u === w(i, s), + key: u, + value: u + }, + u ) + ) ) : He.createElement("input", { type: "text", diff --git a/pandora_console/api/documentation/swagger-ui-standalone-preset.js b/pandora_console/api/documentation/swagger-ui-standalone-preset.js index 5a7d464c49..0c1f324ddd 100644 --- a/pandora_console/api/documentation/swagger-ui-standalone-preset.js +++ b/pandora_console/api/documentation/swagger-ui-standalone-preset.js @@ -6859,7 +6859,9 @@ null != e && !i(e) ) || - a.test(e) || !o.test(e) || (null != t && e in Object(t)) + a.test(e) || + !o.test(e) || + (null != t && e in Object(t)) ); }; }, diff --git a/pandora_console/api/documentation/swagger-ui.js b/pandora_console/api/documentation/swagger-ui.js index c72fd6d40e..ae78269ee4 100644 --- a/pandora_console/api/documentation/swagger-ui.js +++ b/pandora_console/api/documentation/swagger-ui.js @@ -4819,20 +4819,18 @@ k().createElement( "div", { className: "modal-ux-content" }, - o - .valueSeq() - .map((o, c) => - k().createElement(l, { - key: c, - AST: s, - definitions: o, - getComponent: r, - errSelectors: a, - authSelectors: e, - authActions: t, - specSelectors: n - }) - ) + o.valueSeq().map((o, c) => + k().createElement(l, { + key: c, + AST: s, + definitions: o, + getComponent: r, + errSelectors: a, + authSelectors: e, + authActions: t, + specSelectors: n + }) + ) ) ) ) @@ -7258,15 +7256,13 @@ k().createElement( "tbody", null, - e - .entrySeq() - .map(([e, t]) => - k().createElement(r, { - key: `${e}-${t}`, - xKey: e, - xVal: t - }) - ) + e.entrySeq().map(([e, t]) => + k().createElement(r, { + key: `${e}-${t}`, + xKey: e, + xVal: t + }) + ) ) ) ) @@ -7698,15 +7694,13 @@ k().createElement(C, { source: a.get("description") }) ), y && f.size - ? f - .entrySeq() - .map(([e, t]) => - k().createElement(_, { - key: `${e}-${t}`, - xKey: e, - xVal: t - }) - ) + ? f.entrySeq().map(([e, t]) => + k().createElement(_, { + key: `${e}-${t}`, + xKey: e, + xVal: t + }) + ) : null, g && a.get("content") ? k().createElement( @@ -10816,16 +10810,14 @@ k().createElement("span", { className: "brace-close" }, "}") ), w.size - ? w - .entrySeq() - .map(([e, t]) => - k().createElement(j, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: "property" - }) - ) + ? w.entrySeq().map(([e, t]) => + k().createElement(j, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: "property" + }) + ) : null ); } @@ -10882,16 +10874,14 @@ { title: E, expanded: a <= n, collapsedContent: "[...]" }, "[", m.size - ? m - .entrySeq() - .map(([e, t]) => - k().createElement(f, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: "property" - }) - ) + ? m.entrySeq().map(([e, t]) => + k().createElement(f, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: "property" + }) + ) : null, c ? k().createElement(h, { source: c }) @@ -11008,28 +10998,24 @@ ")" ), g.size - ? g - .entrySeq() - .map(([e, t]) => - k().createElement(_, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: ln - }) - ) + ? g.entrySeq().map(([e, t]) => + k().createElement(_, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: ln + }) + ) : null, l && h.size - ? h - .entrySeq() - .map(([e, t]) => - k().createElement(_, { - key: `${e}-${t}`, - propKey: e, - propVal: t, - propClass: ln - }) - ) + ? h.entrySeq().map(([e, t]) => + k().createElement(_, { + key: `${e}-${t}`, + propKey: e, + propVal: t, + propClass: ln + }) + ) : null, d ? k().createElement(S, { source: d }) : null, y && @@ -12452,15 +12438,13 @@ ")" ), C && i.size - ? i - .entrySeq() - .map(([e, r]) => - k().createElement(t, { - key: `${e}-${r}`, - xKey: e, - xVal: r - }) - ) + ? i.entrySeq().map(([e, r]) => + k().createElement(t, { + key: `${e}-${r}`, + xKey: e, + xVal: r + }) + ) : null ), k().createElement( @@ -12703,19 +12687,17 @@ ? k().createElement( "select", { "data-variable": e, onChange: i }, - r - .get("enum") - .map(r => - k().createElement( - "option", - { - selected: r === n(t, e), - key: r, - value: r - }, - r - ) + r.get("enum").map(r => + k().createElement( + "option", + { + selected: r === n(t, e), + key: r, + value: r + }, + r ) + ) ) : k().createElement("input", { type: "text", @@ -17499,7 +17481,8 @@ const { examples: t, example: r, default: a } = e; return ( !!(Array.isArray(t) && t.length >= 1) || - void 0 !== a || void 0 !== r + void 0 !== a || + void 0 !== r ); }, extractExample = e => { diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index f4aefb957a..300d72d9cb 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -558,7 +558,7 @@ if ($broker === false) { $tableAgent->data['caption_interval'][0] = __('Interval').ui_print_help_tip(__('Time that elapses when updating data in the agent. Remote modules have their own interval, but this time is used to find out if an agent stopped responding (unknown state). When twice the time interval defined in an agent goes by, it is considered to be in unknown state (or also if all its remote modules are in unknown state). An agent may be in unknown state if all of its local (software agent-based) modules have a last contact time longer than twice the agent interval, even if it has updated remote modules.'), true); // $tableAgent->rowstyle['interval'] = 'width: 260px'; $tableAgent->rowclass['interval'] = 'w540px'; - $tableAgent->data['interval'][0] = html_print_extended_select_for_time( + $tableAgent->data['interval'][0] = html_print_select_agentmodule_interval( 'intervalo', $intervalo, '', diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index f98567d948..065e2303c2 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1501,6 +1501,11 @@ if ($update_module === true || $create_module === true) { $min = (int) get_parameter('min'); $max = (int) get_parameter('max'); $interval = (int) get_parameter('module_interval', $intervalo); + // Limit module interval to at least 60 secs. + if ($interval > 0) { + $interval = max($interval, 60); + } + $ff_interval = (int) get_parameter('module_ff_interval'); $quiet_module = (int) get_parameter('quiet_module'); $cps_module = (int) get_parameter('cps_module'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index fda655f314..3b858f23a3 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -705,7 +705,19 @@ if ((int) $moduletype === MODULE_DATA) { // be taken the agent interval (this code is at configurar_agente.php). } else { $interval = ($interval === '') ? '300' : $interval; - $outputExecutionInterval = html_print_extended_select_for_time('module_interval', $interval, '', '', '0', false, true, false, false, $classdisabledBecauseInPolicy, $disabledBecauseInPolicy); + $outputExecutionInterval = html_print_select_agentmodule_interval( + 'module_interval', + $interval, + '', + '', + '0', + false, + true, + false, + false, + $classdisabledBecauseInPolicy, + $disabledBecauseInPolicy + ); } $module_id_policy_module = 0; diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 4bed6d4f35..8cb5da658b 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -131,6 +131,10 @@ if ($update_agents) { ) { if (get_parameter('interval') != -2) { $values['intervalo'] = get_parameter('interval'); + + if ($values['intervalo'] < 60) { + $values['intervalo'] = 60; + } } } @@ -753,7 +757,7 @@ $table->data[1][0] = html_print_label_input_block( $table->data[1][1] = html_print_label_input_block( __('Interval'), - html_print_extended_select_for_time( + html_print_select_agentmodule_interval( 'interval', -2, '', diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 672c59276c..8e2a450a71 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -865,7 +865,7 @@ $table->data[15][0] = html_print_label_input_block( $table->data[16][0] = html_print_label_input_block( __('Interval'), - html_print_extended_select_for_time( + html_print_select_agentmodule_interval( 'module_interval', 0, '', @@ -2444,6 +2444,10 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' case 'module_interval': if ($value != 0) { $values[$field] = $value; + + if ($values[$field] < 60) { + $values[$field] = 60; + } } break; diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index c04a66b549..7e72262bdf 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -82,6 +82,11 @@ $snmp_oid = (string) get_parameter('snmp_oid'); $snmp_community = (string) get_parameter('snmp_community'); $id_module_group = (int) get_parameter('id_module_group'); $module_interval = (int) get_parameter('module_interval'); +// Limit module interval to at least 60 secs. +if ($module_interval > 0) { + $module_interval = max($module_interval, 60); +} + $id_group = (int) get_parameter('id_group'); $plugin_user = (string) get_parameter('plugin_user'); $plugin_pass = io_input_password((string) get_parameter('plugin_pass')); diff --git a/pandora_console/godmode/modules/manage_network_components_form_common.php b/pandora_console/godmode/modules/manage_network_components_form_common.php index 3f573ec2c8..7a016d7a91 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_common.php +++ b/pandora_console/godmode/modules/manage_network_components_form_common.php @@ -154,7 +154,7 @@ $table->data[2][0] = html_print_label_input_block( $table->data[2][1] = html_print_label_input_block( __('Interval'), - html_print_extended_select_for_time('module_interval', $module_interval, '', '', '0', false, true) + html_print_select_agentmodule_interval('module_interval', $module_interval, '', '', '0', false, true) ); $dynamic_interval_img = ''.html_print_image( diff --git a/pandora_console/include/functions_clippy.php b/pandora_console/include/functions_clippy.php index a20cbef290..eb494e2b30 100644 --- a/pandora_console/include/functions_clippy.php +++ b/pandora_console/include/functions_clippy.php @@ -322,6 +322,11 @@ function clippy_context_help($help=null) $title = $clippy_modules_not_learning_mode['tours']['modules_not_learning_mode']['steps'][0]['title']; $intro = $clippy_modules_not_learning_mode['tours']['modules_not_learning_mode']['steps'][0]['intro']; $img = $clippy_modules_not_learning_mode['tours']['modules_not_learning_mode']['steps'][0]['img']; + } else if ($help === 'agent_module_interval') { + $clippy_agent_module_interval = clippy_agent_module_interval(); + $title = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['title']; + $intro = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['intro']; + $img = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['img']; } else { $img = html_print_image( 'images/info-warning.svg', diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 3b36b75f6d..09424ac021 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2587,7 +2587,7 @@ function html_print_extended_select_for_time( echo ''; - echo '
'; + echo '
'; html_print_input_text($uniq_name.'_text', $selected, '', $size, 255, false, $readonly, false, '', $class, $script_input); html_print_input_hidden($name, $selected, false, $uniq_name); @@ -2614,7 +2614,7 @@ function html_print_extended_select_for_time( false, false ); - echo ' '.html_print_image( + echo '  '.html_print_image( 'images/logs@svg.svg', true, [ @@ -2655,6 +2655,174 @@ function html_print_extended_select_for_time( } +/** + * Render agent/module interval-specific time selection set of inputs + * from html_print_extended_select_for_time with additional structure and + * behavior associated (establishes a limit of at least 60 seconds to be + * selected and displays notice when this limit is actively selected). + * + * @param string $name Select form name. + * @param mixed $selected Current selected value. Can be a single value or an array of selected values (in combination with multiple). + * @param string $script Javascript onChange (select) code. + * @param string $nothing Label when nothing is selected. + * @param mixed $nothing_value Value when nothing is selected. + * @param integer $size Size of the input. + * @param boolean $return Whether to return an output string or echo now (optional, echo by default). + * @param boolean $select_style Wherter to assign to combo a unique name (to have more than one on same page, like dashboard). + * @param boolean $unique_name Uunique name value. + * @param string $class Class value. + * @param boolean $readonly Readonly value. + * @param string $custom_fields Custom fields value. + * @param string $style_icon Style icon value. + * @param boolean $no_change No change value. + * @param boolean $allow_zero Allow the use of the value zero. + + * @return string HTML code if return parameter is true. + */ +function html_print_select_agentmodule_interval( + $name, + $selected='', + $script='', + $nothing='', + $nothing_value='0', + $size=false, + $return=false, + $select_style=false, + $unique_name=true, + $class='', + $readonly=false, + $custom_fields=false, + $style_icon='', + $no_change=false, + $allow_zero=0, + $units=null, + $script_input='' +) { + global $config; + + include_once $config['homedir'].'/include/functions_clippy.php'; + + $output = '
'; + $output .= html_print_extended_select_for_time( + $name, + $selected, + $script, + $nothing, + $nothing_value, + $size, + $return, + $select_style, + $unique_name, + $class, + $readonly + ); + + $unique_id = ''; + + if ($unique_name === true) { + $pattern = '/'.$name.'([a-fA-F0-9]+)_default/'; + + if (preg_match($pattern, $output, $matches)) { + // Obtain the unique ID of the generated input. + $unique_id = $matches[1]; + $name .= $unique_id; + } + } + + $output .= html_print_div( + [ + 'id' => 'agent_module_interval_clippy'.$unique_id, + 'class' => 'invisible flex align-self-center', + 'content' => clippy_context_help('agent_module_interval'), + ], + true + ); + + $output .= ""; + $output .= '
'; + return $output; +} + + /** * Print selects to configure the cron of a module. * diff --git a/pandora_console/include/help/clippy/agent_module_interval.php b/pandora_console/include/help/clippy/agent_module_interval.php new file mode 100644 index 0000000000..d5f29ac32e --- /dev/null +++ b/pandora_console/include/help/clippy/agent_module_interval.php @@ -0,0 +1,49 @@ + true, + 'intro' => __('Pandora FMS has been designed to monitor thousands of elements. It is possible to use very low sampling intervals by using specific items for that purpose (Satellite Server), but doing so in a centralized way may negatively affect performance. That is why it is limited to 60-second intervals. Even so, 60-second interval sampling should only take place in very specific modules. The impact on your infrastructure may be severe, leading to event storms and monitoring delays. Should you use 60-second intervals, it is recommended to disable unknown detection monitoring to avoid undesired events and use the FlipFlop protection setup'), + 'title' => __('Notice'), + 'img' => html_print_image( + 'images/info-warning.svg', + true, + [ + 'class' => 'main_menu_icon invert_filter', + 'style' => 'margin-left: 5px;', + ] + ), + ]; + $return_tours['tours']['agent_module_interval']['conf'] = []; + $return_tours['tours']['agent_module_interval']['conf']['autostart'] = false; + $return_tours['tours']['agent_module_interval']['conf']['show_bullets'] = 0; + $return_tours['tours']['agent_module_interval']['conf']['show_step_numbers'] = 0; + + return $return_tours; +} diff --git a/pandora_console/include/help/clippy/data_configuration_module.php b/pandora_console/include/help/clippy/data_configuration_module.php index 4e5d33efaa..fd28262da4 100644 --- a/pandora_console/include/help/clippy/data_configuration_module.php +++ b/pandora_console/include/help/clippy/data_configuration_module.php @@ -32,7 +32,7 @@ function clippy_data_configuration_module() $return_tours['tours']['data_configuration_module']['steps'] = []; $return_tours['tours']['data_configuration_module']['steps'][] = [ 'init_step_context' => true, - 'intro' => __('Please note that information provided here affects how the agent collect information and generate the data XML. Any data/configuration reported by the agent, different from data or description is discarded, and the configuration shown in the console prevails over any configuration coming from the agent, this applies for example for crit/warn thresholds, interval, module group, min/max value, tags, etc.').__('Information imported FIRST time from the XML will fill the information you can see in the console, but after the first import, system will ignore any update coming from the XML/Agent.'), + 'intro' => __('Please note that information provided here affects how the agent collects information and generate the data XML. Any data/configuration reported by the agent, different from data or description is discarded, and the configuration shown in the console prevails over any configuration coming from the agent, this applies for example to crit/warn thresholds, interval, module group, min/max value, tags, etc.').' '.__('Information imported FIRST time from the XML will fill the information you can see in the console, but after the first import, system will ignore any update coming from the XML/Agent.'), 'title' => __('Data Configuration Module.'), 'img' => html_print_image( 'images/info-warning.svg', diff --git a/pandora_console/include/lib/Modules/Authentication/Actions/CreateTokenAction.php b/pandora_console/include/lib/Modules/Authentication/Actions/CreateTokenAction.php index b8122ade9b..76a90203fa 100644 --- a/pandora_console/include/lib/Modules/Authentication/Actions/CreateTokenAction.php +++ b/pandora_console/include/lib/Modules/Authentication/Actions/CreateTokenAction.php @@ -8,15 +8,20 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; final class CreateTokenAction { + + public function __construct( private CreateTokenService $createTokenService, private ValidateAclSystem $acl, ) { } + public function __invoke(Token $token): Token { $this->acl->validateAclToken($token); return $this->createTokenService->__invoke($token); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Actions/DeleteTokenAction.php b/pandora_console/include/lib/Modules/Authentication/Actions/DeleteTokenAction.php index aafd458474..8bf2b28850 100644 --- a/pandora_console/include/lib/Modules/Authentication/Actions/DeleteTokenAction.php +++ b/pandora_console/include/lib/Modules/Authentication/Actions/DeleteTokenAction.php @@ -8,15 +8,20 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; final class DeleteTokenAction { + + public function __construct( private DeleteTokenService $deleteTokenService, private ValidateAclSystem $acl, ) { } + public function __invoke(Token $token): void { $this->acl->validateAclToken($token); $this->deleteTokenService->__invoke($token); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Actions/GetTokenAction.php b/pandora_console/include/lib/Modules/Authentication/Actions/GetTokenAction.php index 9090a2d1c9..5c5f536333 100644 --- a/pandora_console/include/lib/Modules/Authentication/Actions/GetTokenAction.php +++ b/pandora_console/include/lib/Modules/Authentication/Actions/GetTokenAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Authentication\Services\GetTokenService; final class GetTokenAction { + + public function __construct( private GetTokenService $getTokenService ) { } + public function __invoke(int $idToken): Token { return $this->getTokenService->__invoke($idToken); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Actions/ListTokenAction.php b/pandora_console/include/lib/Modules/Authentication/Actions/ListTokenAction.php index 82bb84e871..4ce244d8ef 100644 --- a/pandora_console/include/lib/Modules/Authentication/Actions/ListTokenAction.php +++ b/pandora_console/include/lib/Modules/Authentication/Actions/ListTokenAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListTokenAction { + + public function __construct( private ListTokenService $listTokenService, private CountTokenService $countTokenService ) { } + public function __invoke(TokenFilter $tokenFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListTokenAction $this->listTokenService->__invoke($tokenFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Actions/UpdateTokenAction.php b/pandora_console/include/lib/Modules/Authentication/Actions/UpdateTokenAction.php index ecd081548b..97281e00ea 100644 --- a/pandora_console/include/lib/Modules/Authentication/Actions/UpdateTokenAction.php +++ b/pandora_console/include/lib/Modules/Authentication/Actions/UpdateTokenAction.php @@ -8,15 +8,20 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; final class UpdateTokenAction { + + public function __construct( private UpdateTokenService $updateTokenService, private ValidateAclSystem $acl, ) { } + public function __invoke(Token $token, Token $oldToken): Token { $this->acl->validateAclToken($token); return $this->updateTokenService->__invoke($token, $oldToken); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/CreateTokenController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/CreateTokenController.php index 30609763b8..e6b005408c 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/CreateTokenController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/CreateTokenController.php @@ -11,24 +11,27 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateTokenController extends Controller { + + public function __construct( private CreateTokenAction $createTokenAction ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Authentication"}, * path="/token", * summary="Creates a new tokens", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyToken"), - * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyToken"), + * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -40,4 +43,6 @@ final class CreateTokenController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/DeleteTokenController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/DeleteTokenController.php index 4598d52ea6..285d5624db 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/DeleteTokenController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/DeleteTokenController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteTokenController extends Controller { + + public function __construct( private DeleteTokenAction $deleteTokenAction, private GetTokenAction $getTokenAction ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Authentication"}, * path="/token/{id}", * summary="Deletes an token object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdToken"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdToken"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -40,4 +43,6 @@ final class DeleteTokenController extends Controller $result = $this->deleteTokenAction->__invoke($token); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/GetTokenController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/GetTokenController.php index 7a324b0600..6067c57877 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/GetTokenController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/GetTokenController.php @@ -10,24 +10,27 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetTokenController extends Controller { + + public function __construct( private GetTokenAction $getTokenAction ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/token/{id}", * tags={"Authentication"}, * summary="show tokens", - * @OA\Parameter(ref="#/components/parameters/parameterIdToken"), - * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdToken"), + * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -37,4 +40,6 @@ final class GetTokenController extends Controller $result = $this->getTokenAction->__invoke($idToken); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/ListTokenController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/ListTokenController.php index c6868c4c95..d4b0ee3af0 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/ListTokenController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/ListTokenController.php @@ -10,11 +10,14 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListTokenController extends Controller { + + public function __construct( private ListTokenAction $listTokenAction ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, @@ -30,19 +33,19 @@ final class ListTokenController extends Controller * response="200", * description="List Incidence object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/Token", * description="Array of Token objects" * ) @@ -51,11 +54,11 @@ final class ListTokenController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -66,4 +69,6 @@ final class ListTokenController extends Controller $result = $this->listTokenAction->__invoke($tokenFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/PingController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/PingController.php index fd69919c80..4a1e52cb41 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/PingController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/PingController.php @@ -9,31 +9,34 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class PingController extends Controller { - public function __construct( - ) { + + + public function __construct() + { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/ping", * tags={"Authentication"}, * summary="ping", - * @OA\Response(response=200, ref="#/components/responses/ResponsePing"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponsePing"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) * - * @OA\Response( + * @OA\Response( * response="ResponsePing", * description="Ping", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Property( + * @OA\Property( * property="valid", * type="bool", * nullable=false, @@ -48,4 +51,6 @@ final class PingController extends Controller { return $this->getResponse($response, ['valid' => true]); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Controllers/UpdateTokenController.php b/pandora_console/include/lib/Modules/Authentication/Controllers/UpdateTokenController.php index f97e84ee78..714e05f1de 100644 --- a/pandora_console/include/lib/Modules/Authentication/Controllers/UpdateTokenController.php +++ b/pandora_console/include/lib/Modules/Authentication/Controllers/UpdateTokenController.php @@ -18,22 +18,25 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an token", * @OA\Parameter(ref="#/components/parameters/parameterIdToken"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyToken"), - * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseToken"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateTokenController extends Controller { + + public function __construct( private UpdateTokenAction $updateTokenAction, private GetTokenAction $getTokenAction ) { } + public function __invoke(Request $request, Response $response): Response { $idToken = $this->getParam($request, 'id'); @@ -46,4 +49,6 @@ final class UpdateTokenController extends Controller $result = $this->updateTokenAction->__invoke($token, $oldToken); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Entities/Token.php b/pandora_console/include/lib/Modules/Authentication/Entities/Token.php index 4c9baf730c..eb02c4903f 100644 --- a/pandora_console/include/lib/Modules/Authentication/Entities/Token.php +++ b/pandora_console/include/lib/Modules/Authentication/Entities/Token.php @@ -95,20 +95,29 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class Token extends Entity { + private ?int $idToken = null; + private ?string $label = null; + private ?string $uuid = null; + private ?string $challenge = null; + private ?string $idUser = null; + private ?string $validity = null; + private ?string $lastUsage = null; private ?string $token = null; + public function __construct() { } + public function fieldsReadOnly(): array { return [ @@ -120,6 +129,7 @@ final class Token extends Entity ]; } + public function jsonSerialize(): mixed { return [ @@ -133,10 +143,11 @@ final class Token extends Entity ]; } + public function getValidations(): array { return [ - 'idToken' => [ + 'idToken' => [ Validator::INTEGER, Validator::GREATERTHAN, ], @@ -149,11 +160,13 @@ final class Token extends Entity ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of idToken. * @@ -164,11 +177,11 @@ final class Token extends Entity return $this->idToken; } + /** * Set the value of idToken. * - * @param ?int $idToken - * + * @param integer $idToken */ public function setIdToken(?int $idToken): self { @@ -188,11 +201,11 @@ final class Token extends Entity return $this->label; } + /** * Set the value of label. * - * @param ?string $label - * + * @param string $label */ public function setLabel(?string $label): self { @@ -201,6 +214,7 @@ final class Token extends Entity return $this; } + /** * Get the value of uuid. * @@ -211,11 +225,11 @@ final class Token extends Entity return $this->uuid; } + /** * Set the value of uuid. * - * @param ?string $uuid - * + * @param string $uuid */ public function setUuid(?string $uuid): self { @@ -224,6 +238,7 @@ final class Token extends Entity return $this; } + /** * Get the value of challenge. * @@ -234,11 +249,11 @@ final class Token extends Entity return $this->challenge; } + /** * Set the value of challenge. * - * @param ?string $challenge - * + * @param string $challenge */ public function setChallenge(?string $challenge): self { @@ -247,6 +262,7 @@ final class Token extends Entity return $this; } + /** * Get the value of idUser. * @@ -257,11 +273,11 @@ final class Token extends Entity return $this->idUser; } + /** * Set the value of idUser. * - * @param ?string $idUser - * + * @param string $idUser */ public function setIdUser(?string $idUser): self { @@ -270,6 +286,7 @@ final class Token extends Entity return $this; } + /** * Get the value of validity. * @@ -280,11 +297,11 @@ final class Token extends Entity return $this->validity; } + /** * Set the value of validity. * - * @param ?string $validity - * + * @param string $validity */ public function setValidity(?string $validity): self { @@ -293,6 +310,7 @@ final class Token extends Entity return $this; } + /** * Get the value of lastUsage. * @@ -303,11 +321,11 @@ final class Token extends Entity return $this->lastUsage; } + /** * Set the value of lastUsage. * - * @param ?string $lastUsage - * + * @param string $lastUsage */ public function setLastUsage(?string $lastUsage): self { @@ -316,6 +334,7 @@ final class Token extends Entity return $this; } + /** * Get the value of token. * @@ -326,11 +345,11 @@ final class Token extends Entity return $this->token; } + /** * Set the value of token. * - * @param ?string $token - * + * @param string $token */ public function setToken(?string $token): self { @@ -338,4 +357,6 @@ final class Token extends Entity return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Entities/TokenDataMapper.php b/pandora_console/include/lib/Modules/Authentication/Entities/TokenDataMapper.php index 9303f3eeef..93958cad55 100644 --- a/pandora_console/include/lib/Modules/Authentication/Entities/TokenDataMapper.php +++ b/pandora_console/include/lib/Modules/Authentication/Entities/TokenDataMapper.php @@ -18,6 +18,7 @@ final class TokenDataMapper extends DataMapperAbstract public const VALIDITY = 'validity'; public const LAST_USAGE = 'last_usage'; + public function __construct( private Repository $repository, private Builder $builder, @@ -28,27 +29,35 @@ final class TokenDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return Token::class; } + public function fromDatabase(array $data): Token { - return $this->builder->build(new Token(), [ - 'idToken' => $data[self::ID_TOKEN], - 'label' => $this->repository->safeOutput($data[self::LABEL]), - 'uuid' => $data[self::UUID], - 'challenge' => $data[self::CHALLENGE], - 'idUser' => $data[self::ID_USER], - 'validity' => $data[self::VALIDITY], - 'lastUsage' => $data[self::LAST_USAGE], - ]); + return $this->builder->build( + new Token(), + [ + 'idToken' => $data[self::ID_TOKEN], + 'label' => $this->repository->safeOutput($data[self::LABEL]), + 'uuid' => $data[self::UUID], + 'challenge' => $data[self::CHALLENGE], + 'idUser' => $data[self::ID_USER], + 'validity' => $data[self::VALIDITY], + 'lastUsage' => $data[self::LAST_USAGE], + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var Token $data */ + /* + @var Token $data + */ return [ self::ID_TOKEN => $data->getIdToken(), self::LABEL => $this->repository->safeInput($data->getLabel()), @@ -59,4 +68,6 @@ final class TokenDataMapper extends DataMapperAbstract self::LAST_USAGE => $data->getLastUsage(), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Entities/TokenFilter.php b/pandora_console/include/lib/Modules/Authentication/Entities/TokenFilter.php index 42191cc140..e91a12be2e 100644 --- a/pandora_console/include/lib/Modules/Authentication/Entities/TokenFilter.php +++ b/pandora_console/include/lib/Modules/Authentication/Entities/TokenFilter.php @@ -39,8 +39,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class TokenFilter extends FilterAbstract { + private ?string $freeSearch = null; + public function __construct() { $this->setDefaultFieldOrder(TokenDataMapper::LABEL); @@ -48,6 +50,7 @@ final class TokenFilter extends FilterAbstract $this->setEntityFilter(new Token()); } + public function fieldsTranslate(): array { return [ @@ -58,11 +61,13 @@ final class TokenFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return []; } + public function jsonSerialize(): mixed { return [ @@ -70,6 +75,7 @@ final class TokenFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; @@ -80,24 +86,30 @@ final class TokenFilter extends FilterAbstract return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getFreeSearch(): ?string { return $this->freeSearch; } + public function setFreeSearch(?string $freeSearch): self { $this->freeSearch = $freeSearch; return $this; } + public function getFieldsFreeSearch(): ?array { return [TokenDataMapper::TABLE_NAME.'.'.TokenDataMapper::LABEL]; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Repositories/TokenRepository.php b/pandora_console/include/lib/Modules/Authentication/Repositories/TokenRepository.php index 501977927d..c126eada72 100644 --- a/pandora_console/include/lib/Modules/Authentication/Repositories/TokenRepository.php +++ b/pandora_console/include/lib/Modules/Authentication/Repositories/TokenRepository.php @@ -7,20 +7,30 @@ use PandoraFMS\Modules\Authentication\Entities\TokenFilter; interface TokenRepository { + + /** * @return Token[], */ public function list(TokenFilter $tokenFilter): array; + public function count(TokenFilter $tokenFilter): int; + public function getOne(TokenFilter $tokenFilter): Token; + public function create(Token $token): Token; + public function update(Token $token): Token; + public function delete(int $id): void; + public function getExistToken(string $label): Token; + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/CountTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/CountTokenService.php index ea6a024255..97828418d6 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/CountTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/CountTokenService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Authentication\Repositories\TokenRepository; final class CountTokenService { + + public function __construct( private TokenRepository $tokenRepository, ) { } + public function __invoke(TokenFilter $tokenFilter): int { return $this->tokenRepository->count($tokenFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/CreateTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/CreateTokenService.php index f97aa2496f..d19caf57d1 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/CreateTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/CreateTokenService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateTokenService { + + public function __construct( private Audit $audit, private TokenRepository $tokenRepository, @@ -19,6 +21,7 @@ final class CreateTokenService ) { } + public function __invoke(Token $token): Token { $this->tokenValidation->__invoke($token); @@ -40,4 +43,6 @@ final class CreateTokenService return $token; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/DeleteTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/DeleteTokenService.php index 78b6263527..0df23abae6 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/DeleteTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/DeleteTokenService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class DeleteTokenService { + + public function __construct( private Audit $audit, private TokenRepository $tokenRepository, ) { } + public function __invoke(Token $token): void { $idToken = $token->getIdToken(); @@ -27,4 +30,6 @@ final class DeleteTokenService json_encode($token->toArray()) ); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/ExistLabelTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/ExistLabelTokenService.php index 5ad1d10a76..876a11fccb 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/ExistLabelTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/ExistLabelTokenService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistLabelTokenService { + + public function __construct( private TokenRepository $tokenRepository, ) { } + public function __invoke(string $label): bool { $tokenFilter = new TokenFilter(); - /** @var Token $entityFilter */ + /* + @var Token $entityFilter + */ $entityFilter = $tokenFilter->getEntityFilter(); $entityFilter->setLabel($label); @@ -28,4 +33,6 @@ final class ExistLabelTokenService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserTokenService.php index 0ca78e3502..eb2e774981 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserTokenService.php @@ -4,14 +4,19 @@ namespace PandoraFMS\Modules\Authentication\Services; final class GenerateUserTokenService { - public function __construct( - ) { + + + public function __construct() + { } + public function __invoke(): string { $base = preg_replace( - '/[^a-zA-Z0-9]/', '', base64_encode(random_bytes(100)), + '/[^a-zA-Z0-9]/', + '', + base64_encode(random_bytes(100)), ); $token = substr($base, 0, 8); @@ -19,4 +24,6 @@ final class GenerateUserTokenService return $token; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserUUIDService.php b/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserUUIDService.php index 2da3c1a115..cb99cd21b5 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserUUIDService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/GenerateUserUUIDService.php @@ -6,12 +6,17 @@ use Ramsey\Uuid\Uuid; final class GenerateUserUUIDService { - public function __construct( - ) { + + + public function __construct() + { } + public function __invoke(): string { return Uuid::uuid4()->toString(); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/GetTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/GetTokenService.php index a235acb52d..4cc6845356 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/GetTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/GetTokenService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Authentication\Repositories\TokenRepository; final class GetTokenService { + + public function __construct( private TokenRepository $tokenRepository, ) { } + public function __invoke(int $idToken): Token { $tokenFilter = new TokenFilter(); - /** @var Token $entityFilter */ + /* + @var Token $entityFilter + */ $entityFilter = $tokenFilter->getEntityFilter(); $entityFilter->setIdToken($idToken); return $this->tokenRepository->getOne($tokenFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/GetUserTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/GetUserTokenService.php index 1169f99dff..9ba5766ef5 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/GetUserTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/GetUserTokenService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Authentication\Repositories\TokenRepository; final class GetUserTokenService { + + public function __construct( private TokenRepository $tokenRepository, ) { } + public function __invoke(string $uuid): Token { $tokenFilter = new TokenFilter(); - /** @var Token $entityFilter */ + /* + @var Token $entityFilter + */ $entityFilter = $tokenFilter->getEntityFilter(); $entityFilter->setUuid($uuid); return $this->tokenRepository->getOne($tokenFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/ListTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/ListTokenService.php index c3cbf07aae..0850f2a039 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/ListTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/ListTokenService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Authentication\Repositories\TokenRepository; final class ListTokenService { + + public function __construct( private TokenRepository $tokenRepository, ) { } + public function __invoke(TokenFilter $tokenFilter): array { return $this->tokenRepository->list($tokenFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/PrepareUserTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/PrepareUserTokenService.php index cca16ede44..4ebbbf6c51 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/PrepareUserTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/PrepareUserTokenService.php @@ -4,12 +4,17 @@ namespace PandoraFMS\Modules\Authentication\Services; final class PrepareUserTokenService { - public function __construct( - ) { + + + public function __construct() + { } + public function __invoke(string $plainToken): string { return password_hash($plainToken, PASSWORD_DEFAULT); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/UpdateTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/UpdateTokenService.php index 0ea456b5f9..3659cd8914 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/UpdateTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/UpdateTokenService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateTokenService { + + public function __construct( private Audit $audit, private TokenRepository $tokenRepository, @@ -16,6 +18,7 @@ final class UpdateTokenService ) { } + public function __invoke(Token $token, Token $oldToken): Token { $this->tokenValidation->__invoke($token, $oldToken); @@ -30,4 +33,6 @@ final class UpdateTokenService return $token; } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/ValidateServerIdentifierTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/ValidateServerIdentifierTokenService.php index 2177d45be3..03cd0a6102 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/ValidateServerIdentifierTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/ValidateServerIdentifierTokenService.php @@ -6,16 +6,22 @@ use PandoraFMS\Modules\Shared\Services\Config; final class ValidateServerIdentifierTokenService { + + public function __construct( private readonly Config $config, ) { } - public function __invoke(string $token): bool { + + public function __invoke(string $token): bool + { $serverUniqueIdentifier = $this->config->get('server_unique_identifier'); $apiPassword = $this->config->get('api_password'); $tokenUniqueServerIdentifier = md5($serverUniqueIdentifier).md5($apiPassword); return ($tokenUniqueServerIdentifier === $token); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Services/ValidateUserTokenService.php b/pandora_console/include/lib/Modules/Authentication/Services/ValidateUserTokenService.php index 992079b52b..162d91f38f 100644 --- a/pandora_console/include/lib/Modules/Authentication/Services/ValidateUserTokenService.php +++ b/pandora_console/include/lib/Modules/Authentication/Services/ValidateUserTokenService.php @@ -4,11 +4,14 @@ namespace PandoraFMS\Modules\Authentication\Services; final class ValidateUserTokenService { + + public function __construct( private readonly GetUserTokenService $getUserTokenService, ) { } + public function __invoke( string $uuid, string $strToken, @@ -28,4 +31,6 @@ final class ValidateUserTokenService $challenge ); } + + } diff --git a/pandora_console/include/lib/Modules/Authentication/Validations/TokenValidation.php b/pandora_console/include/lib/Modules/Authentication/Validations/TokenValidation.php index b741d9db77..a602aea80b 100644 --- a/pandora_console/include/lib/Modules/Authentication/Validations/TokenValidation.php +++ b/pandora_console/include/lib/Modules/Authentication/Validations/TokenValidation.php @@ -11,6 +11,8 @@ use PandoraFMS\Modules\Users\Services\GetUserService; final class TokenValidation { + + public function __construct( private Config $config, private Timestamp $timestamp, @@ -19,7 +21,8 @@ final class TokenValidation ) { } - public function __invoke(Token $token, ?Token $oldToken = null): void + + public function __invoke(Token $token, ?Token $oldToken=null): void { if (!$token->getLabel()) { throw new BadRequestException(__('Label is missing')); @@ -34,7 +37,7 @@ final class TokenValidation } if (is_user_admin($this->config->get('id_user')) === false - || empty($token->getIdUser()) === true + || empty($token->getIdUser()) === true ) { $token->setIdUser($this->config->get('id_user')); } else { @@ -42,13 +45,17 @@ final class TokenValidation } } + protected function getCurrentTimestamp(): string { return $this->timestamp->getMysqlCurrentTimestamp(0); } + private function validateUser(string $idUser): void { $this->getUserService->__invoke($idUser); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Actions/CreateEventAction.php b/pandora_console/include/lib/Modules/Events/Actions/CreateEventAction.php index 17fbcc3960..635efc1e94 100644 --- a/pandora_console/include/lib/Modules/Events/Actions/CreateEventAction.php +++ b/pandora_console/include/lib/Modules/Events/Actions/CreateEventAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Services\CreateEventService; final class CreateEventAction { + + public function __construct( private CreateEventService $createEventService ) { } + public function __invoke(Event $event): Event { return $this->createEventService->__invoke($event); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Actions/DeleteEventAction.php b/pandora_console/include/lib/Modules/Events/Actions/DeleteEventAction.php index 90ca0edf12..2e4f67944f 100644 --- a/pandora_console/include/lib/Modules/Events/Actions/DeleteEventAction.php +++ b/pandora_console/include/lib/Modules/Events/Actions/DeleteEventAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Services\DeleteEventService; final class DeleteEventAction { + + public function __construct( private DeleteEventService $deleteEventService ) { } + public function __invoke(Event $event): void { $this->deleteEventService->__invoke($event); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Actions/GetEventAction.php b/pandora_console/include/lib/Modules/Events/Actions/GetEventAction.php index 6864873d63..ab54231b29 100644 --- a/pandora_console/include/lib/Modules/Events/Actions/GetEventAction.php +++ b/pandora_console/include/lib/Modules/Events/Actions/GetEventAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Services\GetEventService; final class GetEventAction { + + public function __construct( private GetEventService $getEventService ) { } + public function __invoke(int $idEvent): Event { return $this->getEventService->__invoke($idEvent); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Actions/ListEventAction.php b/pandora_console/include/lib/Modules/Events/Actions/ListEventAction.php index a8d4f45d84..7cba939443 100644 --- a/pandora_console/include/lib/Modules/Events/Actions/ListEventAction.php +++ b/pandora_console/include/lib/Modules/Events/Actions/ListEventAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListEventAction { + + public function __construct( private ListEventService $listEventService, private CountEventService $countEventService ) { } + public function __invoke(EventFilter $eventFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListEventAction $this->listEventService->__invoke($eventFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Actions/UpdateEventAction.php b/pandora_console/include/lib/Modules/Events/Actions/UpdateEventAction.php index 31e5f77770..a6335bc760 100644 --- a/pandora_console/include/lib/Modules/Events/Actions/UpdateEventAction.php +++ b/pandora_console/include/lib/Modules/Events/Actions/UpdateEventAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Services\UpdateEventService; final class UpdateEventAction { + + public function __construct( private UpdateEventService $updateEventService ) { } + public function __invoke(Event $event, Event $oldEvent): Event { return $this->updateEventService->__invoke($event, $oldEvent); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Actions/CreateEventCommentAction.php b/pandora_console/include/lib/Modules/Events/Comments/Actions/CreateEventCommentAction.php index 16204d5862..19ea9657da 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Actions/CreateEventCommentAction.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Actions/CreateEventCommentAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Services\CreateEventCommentService; final class CreateEventCommentAction { + + public function __construct( private CreateEventCommentService $createEventCommentService ) { } + public function __invoke(EventComment $eventComment): EventComment { return $this->createEventCommentService->__invoke($eventComment); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Actions/DeleteEventCommentAction.php b/pandora_console/include/lib/Modules/Events/Comments/Actions/DeleteEventCommentAction.php index 0157cf144a..92f3f76730 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Actions/DeleteEventCommentAction.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Actions/DeleteEventCommentAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Services\DeleteEventCommentService; final class DeleteEventCommentAction { + + public function __construct( private DeleteEventCommentService $deleteEventCommentService ) { } + public function __invoke(EventComment $eventComment): void { $this->deleteEventCommentService->__invoke($eventComment); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Actions/GetEventCommentAction.php b/pandora_console/include/lib/Modules/Events/Comments/Actions/GetEventCommentAction.php index 6af283cd52..d2b6c56f33 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Actions/GetEventCommentAction.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Actions/GetEventCommentAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Services\GetEventCommentService; final class GetEventCommentAction { + + public function __construct( private GetEventCommentService $getEventCommentService ) { } + public function __invoke(int $idTypeField, int $idComment): EventComment { return $this->getEventCommentService->__invoke($idTypeField, $idComment); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Actions/ListEventCommentAction.php b/pandora_console/include/lib/Modules/Events/Comments/Actions/ListEventCommentAction.php index 40380401be..1b7052d21a 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Actions/ListEventCommentAction.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Actions/ListEventCommentAction.php @@ -10,6 +10,8 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListEventCommentAction { + + public function __construct( private ListEventCommentService $listEventCommentService, private CountEventCommentService $countEventCommentService @@ -26,4 +28,6 @@ final class ListEventCommentAction $this->listEventCommentService->__invoke($eventCommentFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Actions/UpdateEventCommentAction.php b/pandora_console/include/lib/Modules/Events/Comments/Actions/UpdateEventCommentAction.php index abda7ae513..cf7d173214 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Actions/UpdateEventCommentAction.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Actions/UpdateEventCommentAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Services\UpdateEventCommentService; final class UpdateEventCommentAction { + + public function __construct( private UpdateEventCommentService $updateEventCommentService ) { } + public function __invoke(EventComment $eventComment, EventComment $oldEventComment): EventComment { return $this->updateEventCommentService->__invoke($eventComment, $oldEventComment); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Controllers/CreateEventCommentController.php b/pandora_console/include/lib/Modules/Events/Comments/Controllers/CreateEventCommentController.php index 037de37d3c..5e8189c06f 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Controllers/CreateEventCommentController.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Controllers/CreateEventCommentController.php @@ -14,6 +14,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateEventCommentController extends Controller { + + public function __construct( private CreateEventCommentAction $createEventCommentAction, private ValidateAclSystem $acl, @@ -21,20 +23,21 @@ final class CreateEventCommentController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/{idEvent}/comment", * summary="Creates a new field into events comments", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventComment"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventComment"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -56,4 +59,6 @@ final class CreateEventCommentController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Controllers/DeleteEventCommentController.php b/pandora_console/include/lib/Modules/Events/Comments/Controllers/DeleteEventCommentController.php index 5319673223..dbafc03753 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Controllers/DeleteEventCommentController.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Controllers/DeleteEventCommentController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteEventCommentController extends Controller { + + public function __construct( private DeleteEventCommentAction $deleteEventCommentAction, private ValidateAclSystem $acl, @@ -21,20 +23,21 @@ final class DeleteEventCommentController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/{idEvent}/comment/{idComment}", * summary="Delete comment for event type object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\Parameter(ref="#/components/parameters/parameterIdEventComment"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\Parameter(ref="#/components/parameters/parameterIdEventComment"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -55,4 +58,6 @@ final class DeleteEventCommentController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Controllers/GetEventCommentController.php b/pandora_console/include/lib/Modules/Events/Comments/Controllers/GetEventCommentController.php index ecaee0fbf1..2f1ef72ae0 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Controllers/GetEventCommentController.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Controllers/GetEventCommentController.php @@ -12,6 +12,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetEventCommentController extends Controller { + + public function __construct( private GetEventAction $getEventAction, private GetEventCommentAction $getEventCommentAction, @@ -19,25 +21,25 @@ final class GetEventCommentController extends Controller ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/event/{idEvent}/comment/{idComment}", * tags={"Events"}, * summary="show field events comments", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\Parameter(ref="#/components/parameters/parameterIdEventComment"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\Parameter(ref="#/components/parameters/parameterIdEventComment"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response { - $idEvent = $this->getParam($request, 'idEvent'); $event = $this->getEventAction->__invoke($idEvent); @@ -53,4 +55,6 @@ final class GetEventCommentController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Controllers/ListEventCommentController.php b/pandora_console/include/lib/Modules/Events/Comments/Controllers/ListEventCommentController.php index 8cdf3b1777..368a00f09e 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Controllers/ListEventCommentController.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Controllers/ListEventCommentController.php @@ -14,6 +14,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListEventCommentController extends Controller { + + public function __construct( private ListEventCommentAction $listEventCommentAction, private GetEventAction $getEventAction, @@ -21,35 +23,36 @@ final class ListEventCommentController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/{idEvent}/comment/list", * summary="List comments event", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventCommentFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventCommentFilter"), + * @OA\Response( * response="200", * description="List Comments event object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/EventComment", * description="Array of fields for comments event object" * ) @@ -58,15 +61,14 @@ final class ListEventCommentController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response { - $idEvent = $this->getParam($request, 'idEvent'); $event = $this->getEventAction->__invoke($idEvent); @@ -84,4 +86,6 @@ final class ListEventCommentController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Controllers/UpdateEventCommentController.php b/pandora_console/include/lib/Modules/Events/Comments/Controllers/UpdateEventCommentController.php index 9dc0524d01..ca27516e50 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Controllers/UpdateEventCommentController.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Controllers/UpdateEventCommentController.php @@ -21,16 +21,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), * @OA\Parameter(ref="#/components/parameters/parameterIdEventComment"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventComment"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateEventCommentController extends Controller { + + public function __construct( private UpdateEventCommentAction $updateEventCommentAction, private ValidateAclSystem $acl, @@ -39,6 +41,7 @@ final class UpdateEventCommentController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idEvent = $this->getParam($request, 'idEvent'); @@ -62,4 +65,6 @@ final class UpdateEventCommentController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventComment.php b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventComment.php index 4ca911500e..b9b30a7307 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventComment.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventComment.php @@ -94,17 +94,25 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class EventComment extends Entity { + private ?int $idEventComment = null; + private ?int $idEvent = null; + private ?int $utimestamp = null; + private ?string $comment = null; + private ?string $idUser = null; + private ?string $action = null; + public function __construct() { } + public function fieldsReadOnly(): array { return [ @@ -115,6 +123,7 @@ final class EventComment extends Entity ]; } + public function jsonSerialize(): mixed { return [ @@ -127,6 +136,7 @@ final class EventComment extends Entity ]; } + public function getValidations(): array { return [ @@ -134,82 +144,103 @@ final class EventComment extends Entity Validator::INTEGER, Validator::GREATERTHAN, ], - 'idEvent' => [ + 'idEvent' => [ Validator::INTEGER, Validator::GREATERTHAN, ], - 'utimestamp' => [ + 'utimestamp' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'comment' => Validator::STRING, - 'idUser' => Validator::STRING, - 'action' => Validator::STRING, + 'comment' => Validator::STRING, + 'idUser' => Validator::STRING, + 'action' => Validator::STRING, ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getIdEventComment(): ?int { return $this->idEventComment; } + + public function setIdEventComment(?int $idEventComment): self { $this->idEventComment = $idEventComment; return $this; } + public function getIdEvent(): ?int { return $this->idEvent; } + + public function setIdEvent(?int $idEvent): self { $this->idEvent = $idEvent; return $this; } + public function getUtimestamp(): ?int { return $this->utimestamp; } + + public function setUtimestamp(?int $utimestamp): self { $this->utimestamp = $utimestamp; return $this; } + public function getComment(): ?string { return $this->comment; } + + public function setComment(?string $comment): self { $this->comment = $comment; return $this; } + public function getIdUser(): ?string { return $this->idUser; } + + public function setIdUser(?string $idUser): self { $this->idUser = $idUser; return $this; } + public function getAction(): ?string { return $this->action; } + + public function setAction(?string $action): self { $this->action = $action; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentDataMapper.php b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentDataMapper.php index e9e304c078..1eb4720bb8 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentDataMapper.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentDataMapper.php @@ -17,6 +17,7 @@ final class EventCommentDataMapper extends DataMapperAbstract public const ID_USER = 'id_user'; public const ACTION = 'action'; + public function __construct( private Repository $repository, private Builder $builder, @@ -27,26 +28,34 @@ final class EventCommentDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return EventComment::class; } + public function fromDatabase(array $data): EventComment { - return $this->builder->build(new EventComment(), [ - 'idEventComment' => $data[self::ID_EVENT_COMMENT], - 'idEvent' => $data[self::ID_EVENT], - 'utimestamp' => $data[self::UTIMESTAMP], - 'comment' => $this->repository->safeOutput($data[self::COMMENT]), - 'idUser' => $this->repository->safeOutput($data[self::ID_USER]), - 'action' => $this->repository->safeOutput($data[self::ACTION]), - ]); + return $this->builder->build( + new EventComment(), + [ + 'idEventComment' => $data[self::ID_EVENT_COMMENT], + 'idEvent' => $data[self::ID_EVENT], + 'utimestamp' => $data[self::UTIMESTAMP], + 'comment' => $this->repository->safeOutput($data[self::COMMENT]), + 'idUser' => $this->repository->safeOutput($data[self::ID_USER]), + 'action' => $this->repository->safeOutput($data[self::ACTION]), + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var EventComment $data */ + /* + @var EventComment $data + */ return [ self::ID_EVENT_COMMENT => $data->getIdEventComment(), self::ID_EVENT => $data->getIdEvent(), @@ -56,4 +65,6 @@ final class EventCommentDataMapper extends DataMapperAbstract self::ACTION => $this->repository->safeInput($data->getAction()), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentFilter.php b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentFilter.php index 6fe89725dc..d9c8eb2b07 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentFilter.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Entities/EventCommentFilter.php @@ -39,8 +39,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class EventCommentFilter extends FilterAbstract { + private ?string $freeSearch = null; + public function __construct() { $this->setDefaultFieldOrder(EventCommentDataMapper::UTIMESTAMP); @@ -48,6 +50,7 @@ final class EventCommentFilter extends FilterAbstract $this->setEntityFilter(new EventComment()); } + public function fieldsTranslate(): array { return [ @@ -60,11 +63,13 @@ final class EventCommentFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return []; } + public function jsonSerialize(): mixed { return [ @@ -72,21 +77,25 @@ final class EventCommentFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; - if($this->getEntityFilter() !== null) { + if ($this->getEntityFilter() !== null) { $validations = $this->getEntityFilter()->getValidations(); } + $validations['freeSearch'] = Validator::STRING; return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of freeSearch. * @@ -97,11 +106,11 @@ final class EventCommentFilter extends FilterAbstract return $this->freeSearch; } + /** * Set the value of freeSearch. * - * @param ?string $freeSearch - * + * @param string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -109,6 +118,7 @@ final class EventCommentFilter extends FilterAbstract return $this; } + /** * Get the value of fieldsFreeSearch. * @@ -119,4 +129,5 @@ final class EventCommentFilter extends FilterAbstract return [EventCommentDataMapper::COMMENT]; } + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Repositories/EventCommentRepository.php b/pandora_console/include/lib/Modules/Events/Comments/Repositories/EventCommentRepository.php index d960c9e923..2f8118b9c7 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Repositories/EventCommentRepository.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Repositories/EventCommentRepository.php @@ -9,15 +9,18 @@ use PandoraFMS\Modules\Shared\Repositories\Repository; class EventCommentRepository { + + public function __construct( private Repository $repository, private EventCommentDataMapper $eventCommentDataMapper ) { } + /** * @return EventComments[], - */ + */ public function list(EventCommentFilter $eventCommentFilter): array { return $this->repository->__list( @@ -26,6 +29,7 @@ class EventCommentRepository ); } + public function count(EventCommentFilter $eventCommentFilter): int { return $this->repository->__count( @@ -34,6 +38,7 @@ class EventCommentRepository ); } + public function getOne(EventCommentFilter $eventCommentFilter): EventComment { return $this->repository->__getOne( @@ -42,12 +47,14 @@ class EventCommentRepository ); } + public function create(EventComment $eventComment): EventComment { $id = $this->repository->__create($eventComment, $this->eventCommentDataMapper); return $eventComment->setIdEventComment($id); } + public function update(EventComment $eventComment): EventComment { return $this->repository->__update( @@ -57,9 +64,11 @@ class EventCommentRepository ); } + public function delete(int $id): void { $this->repository->__delete($id, $this->eventCommentDataMapper); } + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/CountEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/CountEventCommentService.php index 4b6bdd980b..e56a058791 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/CountEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/CountEventCommentService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Repositories\EventCommentRepository; final class CountEventCommentService { + + public function __construct( private EventCommentRepository $eventCommentRepository, ) { } + public function __invoke(EventCommentFilter $eventCommentFilter): int { return $this->eventCommentRepository->count($eventCommentFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/CreateEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/CreateEventCommentService.php index 2e70da5b66..0a097a864e 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/CreateEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/CreateEventCommentService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateEventCommentService { + + public function __construct( private EventCommentRepository $eventCommentRepository, private EventCommentValidation $eventCommentValidation, @@ -16,17 +18,19 @@ final class CreateEventCommentService ) { } + public function __invoke(EventComment $eventComment): EventComment { $this->eventCommentValidation->__invoke($eventComment); $eventComment = $this->eventCommentRepository->create($eventComment); - //$this->audit->write( - // 'Incidence Management', - // ' Create Field #'.$eventComment->getIdEventComment().'in a incidence type #'.$eventComment->getIdEvent() - //); - + // $this->audit->write( + // 'Incidence Management', + // ' Create Field #'.$eventComment->getIdEventComment().'in a incidence type #'.$eventComment->getIdEvent() + // ); return $eventComment; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/DeleteEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/DeleteEventCommentService.php index 498a199df7..88f90f1942 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/DeleteEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/DeleteEventCommentService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Config; final class DeleteEventCommentService { + + public function __construct( private Config $config, private Audit $audit, @@ -24,9 +26,11 @@ final class DeleteEventCommentService $this->eventCommentRepository->delete($idEventComment); // Audit. - //$this->audit->write( - // 'Incidence Management', - // ' Deleted field incidence type #'.$idEventComment - //); + // $this->audit->write( + // 'Incidence Management', + // ' Deleted field incidence type #'.$idEventComment + // ); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/GetEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/GetEventCommentService.php index 173d8a08c7..bdcad9cfd0 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/GetEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/GetEventCommentService.php @@ -8,19 +8,26 @@ use PandoraFMS\Modules\Events\Comments\Repositories\EventCommentRepository; final class GetEventCommentService { + + public function __construct( private EventCommentRepository $eventCommentRepository, ) { } + public function __invoke(int $idEvent, int $idEventComment): EventComment { $eventCommentFilter = new EventCommentFilter(); - /** @var EventComment $entityFilter */ + /* + @var EventComment $entityFilter + */ $entityFilter = $eventCommentFilter->getEntityFilter(); $entityFilter->setIdEvent($idEvent); $entityFilter->setIdEventComment($idEventComment); return $this->eventCommentRepository->getOne($eventCommentFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/ListEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/ListEventCommentService.php index d91086c3a0..b185eddb0e 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/ListEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/ListEventCommentService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Comments\Repositories\EventCommentRepository; final class ListEventCommentService { + + public function __construct( private EventCommentRepository $eventCommentRepository, ) { } + public function __invoke(EventCommentFilter $eventCommentFilter): array { return $this->eventCommentRepository->list($eventCommentFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Services/UpdateEventCommentService.php b/pandora_console/include/lib/Modules/Events/Comments/Services/UpdateEventCommentService.php index c6226f82e1..9d87b38ab5 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Services/UpdateEventCommentService.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Services/UpdateEventCommentService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateEventCommentService { + + public function __construct( private Audit $audit, private EventCommentRepository $eventCommentRepository, @@ -16,17 +18,19 @@ final class UpdateEventCommentService ) { } + public function __invoke(EventComment $eventComment, EventComment $oldEventComment): EventComment { $this->eventCommentValidation->__invoke($eventComment, $oldEventComment); $eventComment = $this->eventCommentRepository->update($eventComment); - //$this->audit->write( - // 'Incidence Management', - // ' Update Field #'.$eventComment->getIdEventComment().' in a incidence type #'.$eventComment->getIdEvent() - //); - + // $this->audit->write( + // 'Incidence Management', + // ' Update Field #'.$eventComment->getIdEventComment().' in a incidence type #'.$eventComment->getIdEvent() + // ); return $eventComment; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Comments/Validations/EventCommentValidation.php b/pandora_console/include/lib/Modules/Events/Comments/Validations/EventCommentValidation.php index 18e5f1091b..8ac64dd30a 100644 --- a/pandora_console/include/lib/Modules/Events/Comments/Validations/EventCommentValidation.php +++ b/pandora_console/include/lib/Modules/Events/Comments/Validations/EventCommentValidation.php @@ -10,6 +10,8 @@ use PandoraFMS\Modules\Shared\Services\Timestamp; final class EventCommentValidation { + + public function __construct( private Config $config, private Timestamp $timestamp, @@ -17,7 +19,8 @@ final class EventCommentValidation ) { } - public function __invoke(EventComment $eventComment, ?EventComment $oldEventComment = null): void + + public function __invoke(EventComment $eventComment, ?EventComment $oldEventComment=null): void { if (!$eventComment->getComment()) { throw new BadRequestException(__('Comment is missing')); @@ -33,8 +36,11 @@ final class EventCommentValidation } } + protected function getCurrentUtimestamp(): int { return $this->timestamp->getMysqlSystemUtimestamp(); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Controllers/CreateEventController.php b/pandora_console/include/lib/Modules/Events/Controllers/CreateEventController.php index acadd568e3..e2a8736094 100644 --- a/pandora_console/include/lib/Modules/Events/Controllers/CreateEventController.php +++ b/pandora_console/include/lib/Modules/Events/Controllers/CreateEventController.php @@ -12,25 +12,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateEventController extends Controller { + + public function __construct( private CreateEventAction $createEventAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event", * summary="Creates a new events", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEvent"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEvent"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -44,4 +47,6 @@ final class CreateEventController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Controllers/DeleteEventController.php b/pandora_console/include/lib/Modules/Events/Controllers/DeleteEventController.php index dfcd3103d8..cf93c54892 100644 --- a/pandora_console/include/lib/Modules/Events/Controllers/DeleteEventController.php +++ b/pandora_console/include/lib/Modules/Events/Controllers/DeleteEventController.php @@ -12,6 +12,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteEventController extends Controller { + + public function __construct( private DeleteEventAction $deleteEventAction, private ValidateAclSystem $acl, @@ -19,19 +21,20 @@ final class DeleteEventController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/{idEvent}", * summary="Deletes an event object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -44,4 +47,6 @@ final class DeleteEventController extends Controller $result = $this->deleteEventAction->__invoke($event); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Controllers/GetEventController.php b/pandora_console/include/lib/Modules/Events/Controllers/GetEventController.php index cf26c067c9..81b1fe34f6 100644 --- a/pandora_console/include/lib/Modules/Events/Controllers/GetEventController.php +++ b/pandora_console/include/lib/Modules/Events/Controllers/GetEventController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetEventController extends Controller { + + public function __construct( private GetEventAction $getEventAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/event/{idEvent}", * tags={"Events"}, * summary="Show event", - * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -41,4 +44,6 @@ final class GetEventController extends Controller $result = $this->getEventAction->__invoke($idEvent); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Controllers/ListEventController.php b/pandora_console/include/lib/Modules/Events/Controllers/ListEventController.php index a439c3a8a7..39a946b112 100644 --- a/pandora_console/include/lib/Modules/Events/Controllers/ListEventController.php +++ b/pandora_console/include/lib/Modules/Events/Controllers/ListEventController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListEventController extends Controller { + + public function __construct( private ListEventAction $listEventAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/list", * summary="List events", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), + * @OA\Response( * response="200", * description="List Events Object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/Event", * description="Array of event objects" * ) @@ -54,11 +57,11 @@ final class ListEventController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -71,4 +74,6 @@ final class ListEventController extends Controller $result = $this->listEventAction->__invoke($eventFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Controllers/UpdateEventController.php b/pandora_console/include/lib/Modules/Events/Controllers/UpdateEventController.php index dd2828653a..207098621e 100644 --- a/pandora_console/include/lib/Modules/Events/Controllers/UpdateEventController.php +++ b/pandora_console/include/lib/Modules/Events/Controllers/UpdateEventController.php @@ -18,16 +18,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an event", * @OA\Parameter(ref="#/components/parameters/parameterIdEvent"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEvent"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseEvent"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateEventController extends Controller { + + public function __construct( private UpdateEventAction $updateEventAction, private ValidateAclSystem $acl, @@ -35,6 +37,7 @@ final class UpdateEventController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idEvent = $this->getParam($request, 'idEvent'); @@ -49,4 +52,6 @@ final class UpdateEventController extends Controller $result = $this->updateEventAction->__invoke($event, $oldEvent); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Entities/EventDataMapper.php b/pandora_console/include/lib/Modules/Events/Entities/EventDataMapper.php index 72169989f5..1f56686ea6 100644 --- a/pandora_console/include/lib/Modules/Events/Entities/EventDataMapper.php +++ b/pandora_console/include/lib/Modules/Events/Entities/EventDataMapper.php @@ -38,6 +38,7 @@ final class EventDataMapper extends DataMapperAbstract public const MODULE_STATUS = 'module_status'; public const EVENT_CUSTOM_ID = 'event_custom_id'; + public function __construct( private Repository $repository, private Builder $builder, @@ -48,44 +49,52 @@ final class EventDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return Event::class; } + public function fromDatabase(array $data): Event { - return $this->builder->build(new Event(), [ - 'idEvent' => $data[self::ID_EVENT], - 'idAgent' => $data[self::ID_AGENT], - 'idUser' => $data[self::ID_USER], - 'idGroup' => $data[self::ID_GROUP], - 'status' => EventStatusEnum::get($data[self::STATUS]), - 'timestamp' => $data[self::TIMESTAMP], - 'event' => $this->repository->safeOutput($data[self::EVENT]), - 'utimestamp' => $data[self::UTIMESTAMP], - 'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]), - 'idAgentModule' => $data[self::ID_AGENTMODULE], - 'idAlertAm' => $data[self::ID_ALERT_AM], - 'severity' => EventSeverityEnum::get($data[self::SEVERITY]), - 'tags' => $data[self::TAGS], - 'source' => $data[self::SOURCE], - 'idExtra' => $data[self::ID_EXTRA], - 'criticalInstructions' => $this->repository->safeOutput($data[self::CRITICAL_INSTRUCTIONS]), - 'warningInstructions' => $this->repository->safeOutput($data[self::WARNING_INSTRUCTIONS]), - 'unknownInstructions' => $this->repository->safeOutput($data[self::UNKNOWN_INSTRUCTIONS]), - 'ownerUser' => $data[self::OWNER_USER], - 'ackUtimestamp' => $data[self::ACK_UTIMESTAMP], - 'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]), - 'data' => $this->repository->safeOutput($data[self::DATA]), - 'moduleStatus' => $data[self::MODULE_STATUS], - 'eventCustomId' => $this->repository->safeOutput($data[self::EVENT_CUSTOM_ID]), - ]); + return $this->builder->build( + new Event(), + [ + 'idEvent' => $data[self::ID_EVENT], + 'idAgent' => $data[self::ID_AGENT], + 'idUser' => $data[self::ID_USER], + 'idGroup' => $data[self::ID_GROUP], + 'status' => EventStatusEnum::get($data[self::STATUS]), + 'timestamp' => $data[self::TIMESTAMP], + 'event' => $this->repository->safeOutput($data[self::EVENT]), + 'utimestamp' => $data[self::UTIMESTAMP], + 'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]), + 'idAgentModule' => $data[self::ID_AGENTMODULE], + 'idAlertAm' => $data[self::ID_ALERT_AM], + 'severity' => EventSeverityEnum::get($data[self::SEVERITY]), + 'tags' => $data[self::TAGS], + 'source' => $data[self::SOURCE], + 'idExtra' => $data[self::ID_EXTRA], + 'criticalInstructions' => $this->repository->safeOutput($data[self::CRITICAL_INSTRUCTIONS]), + 'warningInstructions' => $this->repository->safeOutput($data[self::WARNING_INSTRUCTIONS]), + 'unknownInstructions' => $this->repository->safeOutput($data[self::UNKNOWN_INSTRUCTIONS]), + 'ownerUser' => $data[self::OWNER_USER], + 'ackUtimestamp' => $data[self::ACK_UTIMESTAMP], + 'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]), + 'data' => $this->repository->safeOutput($data[self::DATA]), + 'moduleStatus' => $data[self::MODULE_STATUS], + 'eventCustomId' => $this->repository->safeOutput($data[self::EVENT_CUSTOM_ID]), + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var Event $data */ + /* + @var Event $data + */ return [ self::ID_EVENT => $data->getIdEvent(), self::ID_AGENT => $data->getIdAgent(), @@ -113,4 +122,6 @@ final class EventDataMapper extends DataMapperAbstract self::EVENT_CUSTOM_ID => $this->repository->safeInput($data->getEventCustomId()), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Enums/EventSeverityEnum.php b/pandora_console/include/lib/Modules/Events/Enums/EventSeverityEnum.php index ac5f29110b..acee77081f 100644 --- a/pandora_console/include/lib/Modules/Events/Enums/EventSeverityEnum.php +++ b/pandora_console/include/lib/Modules/Events/Enums/EventSeverityEnum.php @@ -8,11 +8,11 @@ enum EventSeverityEnum: int { use EnumTrait; - case MAINTENANCE = 0; - case INFORMATIONAL = 1; - case NORMAL = 2; - case WARNING = 3; - case CRITICAL = 4; - case MINOR = 5; - case MAJOR = 6; -} +case MAINTENANCE = 0; +case INFORMATIONAL = 1; +case NORMAL = 2; +case WARNING = 3; +case CRITICAL = 4; +case MINOR = 5; +case MAJOR = 6; + } diff --git a/pandora_console/include/lib/Modules/Events/Enums/EventStatusEnum.php b/pandora_console/include/lib/Modules/Events/Enums/EventStatusEnum.php index b102e3d3da..985fa11c6a 100644 --- a/pandora_console/include/lib/Modules/Events/Enums/EventStatusEnum.php +++ b/pandora_console/include/lib/Modules/Events/Enums/EventStatusEnum.php @@ -8,7 +8,7 @@ enum EventStatusEnum: int { use EnumTrait; - case NEW = 0; - case VALIDATED = 1; - case INPROCESS = 2; -} +case new = 0; +case VALIDATED = 1; +case INPROCESS = 2; + } diff --git a/pandora_console/include/lib/Modules/Events/Enums/EventTypeEnum.php b/pandora_console/include/lib/Modules/Events/Enums/EventTypeEnum.php index f1b7e965ab..0f01a6161e 100644 --- a/pandora_console/include/lib/Modules/Events/Enums/EventTypeEnum.php +++ b/pandora_console/include/lib/Modules/Events/Enums/EventTypeEnum.php @@ -8,22 +8,22 @@ enum EventTypeEnum: string { use EnumTrait; - case GOING_UNKNOWN = 'going_unknown'; - case UNKNOWN = 'unknown'; - case ALERT_FIRED = 'alert_fired'; - case ALERT_RECOVERED = 'alert_recovered'; - case ALERT_CEASED = 'alert_ceased'; - case ALERT_MANUAL_VALIDATION = 'alert_manual_validation'; - case RECON_HOST_DETECTED = 'recon_host_detected'; - case SYSTEM = 'system'; - case ERROR = 'error'; - case NEW_AGENT = 'new_agent'; - case GOING_UP_WARNING = 'going_up_warning'; - case GOING_DOWN_WARNING = 'going_down_warning'; - case GOING_UP_CRITICAL = 'going_up_critical'; - case GOING_DOWN_CRITICAL = 'going_down_critical'; - case GOING_UP_NORMAL = 'going_up_normal'; - case GOING_DOWN_NORMAL = 'going_down_normal'; - case CONFIGURATION_CHANGE = 'configuration_change'; - case NCM = 'ncm'; -} +case GOING_UNKNOWN = 'going_unknown'; +case UNKNOWN = 'unknown'; +case ALERT_FIRED = 'alert_fired'; +case ALERT_RECOVERED = 'alert_recovered'; +case ALERT_CEASED = 'alert_ceased'; +case ALERT_MANUAL_VALIDATION = 'alert_manual_validation'; +case RECON_HOST_DETECTED = 'recon_host_detected'; +case SYSTEM = 'system'; +case ERROR = 'error'; +case NEW_AGENT = 'new_agent'; +case GOING_UP_WARNING = 'going_up_warning'; +case GOING_DOWN_WARNING = 'going_down_warning'; +case GOING_UP_CRITICAL = 'going_up_critical'; +case GOING_DOWN_CRITICAL = 'going_down_critical'; +case GOING_UP_NORMAL = 'going_up_normal'; +case GOING_DOWN_NORMAL = 'going_down_normal'; +case CONFIGURATION_CHANGE = 'configuration_change'; +case NCM = 'ncm'; + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Actions/CreateEventFilterAction.php b/pandora_console/include/lib/Modules/Events/Filters/Actions/CreateEventFilterAction.php index 528ab1d1d0..6d45c1fc81 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Actions/CreateEventFilterAction.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Actions/CreateEventFilterAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Services\CreateEventFilterService; final class CreateEventFilterAction { + + public function __construct( private CreateEventFilterService $createEventFilterService ) { } + public function __invoke(EventFilter $eventFilter): EventFilter { return $this->createEventFilterService->__invoke($eventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Actions/DeleteEventFilterAction.php b/pandora_console/include/lib/Modules/Events/Filters/Actions/DeleteEventFilterAction.php index e15fc460d6..18efac217a 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Actions/DeleteEventFilterAction.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Actions/DeleteEventFilterAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Services\DeleteEventFilterService; final class DeleteEventFilterAction { + + public function __construct( private DeleteEventFilterService $deleteEventFilterService ) { } + public function __invoke(EventFilter $eventFilter): void { $this->deleteEventFilterService->__invoke($eventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Actions/GetEventFilterAction.php b/pandora_console/include/lib/Modules/Events/Filters/Actions/GetEventFilterAction.php index 9dcec6e935..21a8263e22 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Actions/GetEventFilterAction.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Actions/GetEventFilterAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Services\GetEventFilterService; final class GetEventFilterAction { + + public function __construct( private GetEventFilterService $getEventFilterService ) { } + public function __invoke(int $idEventFilter): EventFilter { return $this->getEventFilterService->__invoke($idEventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Actions/ListEventFilterAction.php b/pandora_console/include/lib/Modules/Events/Filters/Actions/ListEventFilterAction.php index 0dd70d49eb..e24455d4b9 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Actions/ListEventFilterAction.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Actions/ListEventFilterAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListEventFilterAction { + + public function __construct( private ListEventFilterService $listEventFilterService, private CountEventFilterService $countEventFilterService ) { } + public function __invoke(EventFilterFilter $eventFilterFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListEventFilterAction $this->listEventFilterService->__invoke($eventFilterFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Actions/UpdateEventFilterAction.php b/pandora_console/include/lib/Modules/Events/Filters/Actions/UpdateEventFilterAction.php index f84eba6d50..00e533a46e 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Actions/UpdateEventFilterAction.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Actions/UpdateEventFilterAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Services\UpdateEventFilterService; final class UpdateEventFilterAction { + + public function __construct( private UpdateEventFilterService $updateEventFilterService ) { } + public function __invoke(EventFilter $eventFilter, EventFilter $oldEventFilter): EventFilter { return $this->updateEventFilterService->__invoke($eventFilter, $oldEventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Controllers/CreateEventFilterController.php b/pandora_console/include/lib/Modules/Events/Filters/Controllers/CreateEventFilterController.php index 002a7e1110..7ffe00f12b 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Controllers/CreateEventFilterController.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Controllers/CreateEventFilterController.php @@ -12,25 +12,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateEventFilterController extends Controller { + + public function __construct( private CreateEventFilterAction $createEventFilterAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/filter", * summary="Creates a new event filter", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -44,4 +47,6 @@ final class CreateEventFilterController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Controllers/DeleteEventFilterController.php b/pandora_console/include/lib/Modules/Events/Filters/Controllers/DeleteEventFilterController.php index 87261b3116..6fa7379f0f 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Controllers/DeleteEventFilterController.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Controllers/DeleteEventFilterController.php @@ -12,6 +12,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteEventFilterController extends Controller { + + public function __construct( private DeleteEventFilterAction $deleteEventFilterAction, private ValidateAclSystem $acl, @@ -19,19 +21,20 @@ final class DeleteEventFilterController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/filter/{idEventFilter}", * summary="Deletes an eventFilter object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -44,4 +47,6 @@ final class DeleteEventFilterController extends Controller $result = $this->deleteEventFilterAction->__invoke($eventFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Controllers/GetEventFilterController.php b/pandora_console/include/lib/Modules/Events/Filters/Controllers/GetEventFilterController.php index ac62d90860..7dc602b358 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Controllers/GetEventFilterController.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Controllers/GetEventFilterController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetEventFilterController extends Controller { + + public function __construct( private GetEventFilterAction $getEventFilterAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/event/filter/{idEventFilter}", * tags={"Events"}, * summary="Show eventFilter", - * @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"), + * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -41,4 +44,6 @@ final class GetEventFilterController extends Controller $result = $this->getEventFilterAction->__invoke($idEventFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Controllers/ListEventFilterController.php b/pandora_console/include/lib/Modules/Events/Filters/Controllers/ListEventFilterController.php index bae057fba9..c95fa22832 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Controllers/ListEventFilterController.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Controllers/ListEventFilterController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListEventFilterController extends Controller { + + public function __construct( private ListEventFilterAction $listEventFilterAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Events"}, * path="/event/filter/list", * summary="List event filter", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), + * @OA\Response( * response="200", * description="List Incidence object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/EventFilter", * description="Array of incidences Type objects" * ) @@ -54,11 +57,11 @@ final class ListEventFilterController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -71,4 +74,6 @@ final class ListEventFilterController extends Controller $result = $this->listEventFilterAction->__invoke($eventFilterFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Controllers/UpdateEventFilterController.php b/pandora_console/include/lib/Modules/Events/Filters/Controllers/UpdateEventFilterController.php index 7a562686c2..7c9dd6227d 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Controllers/UpdateEventFilterController.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Controllers/UpdateEventFilterController.php @@ -18,16 +18,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an eventFilter", * @OA\Parameter(ref="#/components/parameters/parameterIdEventFilter"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventFilter"), - * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseEventFilter"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateEventFilterController extends Controller { + + public function __construct( private UpdateEventFilterAction $updateEventFilterAction, private ValidateAclSystem $acl, @@ -35,6 +37,7 @@ final class UpdateEventFilterController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idEventFilter = $this->getParam($request, 'idEventFilter'); @@ -49,4 +52,6 @@ final class UpdateEventFilterController extends Controller $result = $this->updateEventFilterAction->__invoke($eventFilter, $oldEventFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilter.php b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilter.php index aaabab645e..c513327059 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilter.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilter.php @@ -402,50 +402,87 @@ final class EventFilter extends Entity private ?int $idEvent = null; private ?int $idEventFilter = null; + private ?int $idGroupFilter = null; + private ?string $name = null; + private ?int $idGroup = null; + private ?EventTypeEnum $eventType = null; + private ?array $severity = null; + private ?EventFilterStatusEnum $status = null; + private ?string $search = null; + private ?bool $isNotSearch = null; + private ?string $textAgent = null; + private ?int $idAgent = null; + private ?int $idAgentModule = null; + private ?int $pagination = null; + private ?int $slice = null; + private ?string $idUserAck = null; + private ?EventFilterGroupByEnum $groupBy = null; + private ?array $tagWith = null; + private ?array $tagWithout = null; + private ?EventFilterAlertEnum $filterOnlyAlert = null; + private ?bool $searchSecondaryGroups = null; + private ?bool $searchRecursiveGroups = null; + private ?string $dateFrom = null; + private ?string $dateTo = null; + private ?string $source = null; + private ?string $idExtra = null; + private ?string $userComment = null; + private ?int $idSourceEvent = null; + private ?array $serverId = null; + private ?string $timeFrom = null; + private ?string $timeTo = null; + private ?string $customData = null; + private ?EventFilterCustomDataEnum $customDataFilterType = null; + private ?string $ownerUser = null; + private ?string $privateFilterUser = null; + private ?string $regex = null; + public function __construct() { } + public function fieldsReadOnly(): array { return ['idEventFilter' => 1]; } + public function toTranslateFilters(): array { $eventFilterFilter = new EventFilterFilter(); @@ -463,6 +500,7 @@ final class EventFilter extends Entity return $result; } + public function jsonSerialize(): mixed { return [ @@ -505,45 +543,46 @@ final class EventFilter extends Entity ]; } + public function getValidations(): array { return [ - 'idEventFilter' => [ + 'idEventFilter' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATERTHAN, ], - 'idEvent' => [ + 'idEvent' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATERTHAN, ], - 'idGroupFilter' => [ + 'idGroupFilter' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'name' => EventFilterValidator::STRING, - 'idGroup' => [ + 'name' => EventFilterValidator::STRING, + 'idGroup' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'eventType' => EventFilterValidator::VALIDFILTERTYPE, - 'severity' => EventFilterValidator::ARRAY, - 'status' => EventFilterValidator::VALIDFILTERSTATUS, - 'search' => EventFilterValidator::STRING, - 'isNotSearch' => EventFilterValidator::BOOLEAN, - 'textAgent' => EventFilterValidator::STRING, - 'idAgent' => [ + 'eventType' => EventFilterValidator::VALIDFILTERTYPE, + 'severity' => EventFilterValidator::ARRAY, + 'status' => EventFilterValidator::VALIDFILTERSTATUS, + 'search' => EventFilterValidator::STRING, + 'isNotSearch' => EventFilterValidator::BOOLEAN, + 'textAgent' => EventFilterValidator::STRING, + 'idAgent' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'idAgentModule' => [ + 'idAgentModule' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'pagination' => [ + 'pagination' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'slice' => [ + 'slice' => [ EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], @@ -563,66 +602,82 @@ final class EventFilter extends Entity EventFilterValidator::INTEGER, EventFilterValidator::GREATEREQUALTHAN, ], - 'serverId' => EventFilterValidator::ARRAY, - 'timeFrom' => EventFilterValidator::TIME, - 'timeTo' => EventFilterValidator::TIME, - 'customData' => EventFilterValidator::STRING, - 'customDataFilterType' => EventFilterValidator::VALIDFILTERCUSTOMDATA, - 'ownerUser' => EventFilterValidator::STRING, - 'privateFilterUser' => EventFilterValidator::STRING, - 'regex' => EventFilterValidator::STRING, + 'serverId' => EventFilterValidator::ARRAY, + 'timeFrom' => EventFilterValidator::TIME, + 'timeTo' => EventFilterValidator::TIME, + 'customData' => EventFilterValidator::STRING, + 'customDataFilterType' => EventFilterValidator::VALIDFILTERCUSTOMDATA, + 'ownerUser' => EventFilterValidator::STRING, + 'privateFilterUser' => EventFilterValidator::STRING, + 'regex' => EventFilterValidator::STRING, ]; } + public function validateFields(array $filters): array { return (new EventFilterValidator())->validate($filters); } + public function getIdEventFilter(): ?int { return $this->idEventFilter; } + + public function setIdEventFilter(?int $idEventFilter): self { $this->idEventFilter = $idEventFilter; return $this; } + public function getIdGroupFilter(): ?int { return $this->idGroupFilter; } + + public function setIdGroupFilter(?int $idGroupFilter): self { $this->idGroupFilter = $idGroupFilter; return $this; } + public function getName(): ?string { return $this->name; } + + public function setName(?string $name): self { $this->name = $name; return $this; } + public function getIdGroup(): ?int { return $this->idGroup; } + + public function setIdGroup(?int $idGroup): self { $this->idGroup = $idGroup; return $this; } + public function getEventType(): ?EventTypeEnum { return $this->eventType; } + + public function setEventType(null|string|EventTypeEnum $eventType): self { if (is_string($eventType) === true) { @@ -630,23 +685,30 @@ final class EventFilter extends Entity } else { $this->eventType = $eventType; } + return $this; } + public function getSeverity(): ?array { return $this->severity; } + + public function setSeverity(?array $severity): self { $this->severity = $severity; return $this; } + public function getStatus(): ?EventFilterStatusEnum { return $this->status; } + + public function setStatus(null|string|EventFilterStatusEnum $status): self { if (is_string($status) === true) { @@ -658,90 +720,117 @@ final class EventFilter extends Entity return $this; } + public function getSearch(): ?string { return $this->search; } + + public function setSearch(?string $search): self { $this->search = $search; return $this; } + public function getIsNotSearch(): ?bool { return $this->isNotSearch; } + + public function setIsNotSearch(?bool $isNotSearch): self { $this->isNotSearch = $isNotSearch; return $this; } + public function getTextAgent(): ?string { return $this->textAgent; } + + public function setTextAgent(?string $textAgent): self { $this->textAgent = $textAgent; return $this; } + public function getIdAgent(): ?int { return $this->idAgent; } + + public function setIdAgent(?int $idAgent): self { $this->idAgent = $idAgent; return $this; } + public function getIdAgentModule(): ?int { return $this->idAgentModule; } + + public function setIdAgentModule(?int $idAgentModule): self { $this->idAgentModule = $idAgentModule; return $this; } + public function getPagination(): ?int { return $this->pagination; } + + public function setPagination(?int $pagination): self { $this->pagination = $pagination; return $this; } + public function getSlice(): ?int { return $this->slice; } + + public function setSlice(?int $slice): self { $this->slice = $slice; return $this; } + public function getIdUserAck(): ?string { return $this->idUserAck; } + + public function setIdUserAck(?string $idUserAck): self { $this->idUserAck = $idUserAck; return $this; } + public function getGroupBy(): ?EventFilterGroupByEnum { return $this->groupBy; } + + public function setGroupBy(null|string|EventFilterGroupByEnum $groupBy): self { if (is_string($groupBy) === true) { @@ -753,30 +842,39 @@ final class EventFilter extends Entity return $this; } + public function getTagWith(): ?array { return $this->tagWith; } + + public function setTagWith(?array $tagWith): self { $this->tagWith = $tagWith; return $this; } + public function getTagWithout(): ?array { return $this->tagWithout; } + + public function setTagWithout(?array $tagWithout): self { $this->tagWithout = $tagWithout; return $this; } + public function getFilterOnlyAlert(): ?EventFilterAlertEnum { return $this->filterOnlyAlert; } + + public function setFilterOnlyAlert(null|string|EventFilterAlertEnum $filterOnlyAlert): self { if (is_string($filterOnlyAlert) === true) { @@ -788,130 +886,169 @@ final class EventFilter extends Entity return $this; } + public function getSearchSecondaryGroups(): ?bool { return $this->searchSecondaryGroups; } + + public function setSearchSecondaryGroups(?bool $searchSecondaryGroups): self { $this->searchSecondaryGroups = $searchSecondaryGroups; return $this; } + public function getSearchRecursiveGroups(): ?bool { return $this->searchRecursiveGroups; } + + public function setSearchRecursiveGroups(?bool $searchRecursiveGroups): self { $this->searchRecursiveGroups = $searchRecursiveGroups; return $this; } + public function getDateFrom(): ?string { return $this->dateFrom; } + + public function setDateFrom(?string $dateFrom): self { $this->dateFrom = $dateFrom; return $this; } + public function getDateTo(): ?string { return $this->dateTo; } + + public function setDateTo(?string $dateTo): self { $this->dateTo = $dateTo; return $this; } + public function getSource(): ?string { return $this->source; } + + public function setSource(?string $source): self { $this->source = $source; return $this; } + public function getIdExtra(): ?string { return $this->idExtra; } + + public function setIdExtra(?string $idExtra): self { $this->idExtra = $idExtra; return $this; } + public function getUserComment(): ?string { return $this->userComment; } + + public function setUserComment(?string $userComment): self { $this->userComment = $userComment; return $this; } + public function getIdSourceEvent(): ?int { return $this->idSourceEvent; } + + public function setIdSourceEvent(?int $idSourceEvent): self { $this->idSourceEvent = $idSourceEvent; return $this; } + public function getServerId(): ?array { return $this->serverId; } + + public function setServerId(?array $serverId): self { $this->serverId = $serverId; return $this; } + public function getTimeFrom(): ?string { return $this->timeFrom; } + + public function setTimeFrom(?string $timeFrom): self { $this->timeFrom = $timeFrom; return $this; } + public function getTimeTo(): ?string { return $this->timeTo; } + + public function setTimeTo(?string $timeTo): self { $this->timeTo = $timeTo; return $this; } + public function getCustomData(): ?string { return $this->customData; } + + public function setCustomData(?string $customData): self { $this->customData = $customData; return $this; } + public function getCustomDataFilterType(): ?EventFilterCustomDataEnum { return $this->customDataFilterType; } + + public function setCustomDataFilterType(null|string|EventFilterCustomDataEnum $customDataFilterType): self { if (is_string($customDataFilterType) === true) { @@ -923,43 +1060,57 @@ final class EventFilter extends Entity return $this; } + public function getOwnerUser(): ?string { return $this->ownerUser; } + + public function setOwnerUser(?string $ownerUser): self { $this->ownerUser = $ownerUser; return $this; } + public function getPrivateFilterUser(): ?string { return $this->privateFilterUser; } + + public function setPrivateFilterUser(?string $privateFilterUser): self { $this->privateFilterUser = $privateFilterUser; return $this; } + public function getRegex(): ?string { return $this->regex; } + + public function setRegex(?string $regex): self { $this->regex = $regex; return $this; } + public function getIdEvent(): ?int { return $this->idEvent; } + + public function setIdEvent(?int $idEvent): self { $this->idEvent = $idEvent; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterDataMapper.php b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterDataMapper.php index abf5fcf83c..8f1971a86b 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterDataMapper.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterDataMapper.php @@ -52,6 +52,7 @@ final class EventFilterDataMapper extends DataMapperAbstract public const PRIVATE_FILTER_USER = 'private_filter_user'; public const REGEX = 'regex'; + public function __construct( private Repository $repository, private Builder $builder, @@ -62,69 +63,78 @@ final class EventFilterDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return EventFilter::class; } + public function fromDatabase(array $data): EventFilter { $severity = null; - if(empty($data[self::SEVERITY]) === false) { + if (empty($data[self::SEVERITY]) === false) { $severities = explode(',', $data[self::SEVERITY]); foreach ($severities as $value) { $severity[] = EventSeverityEnum::get($value, 'value')?->name; } } - return $this->builder->build(new EventFilter(), [ - 'idEventFilter' => $data[self::ID_FILTER], - 'idGroupFilter' => $data[self::ID_GROUP_FILTER], - 'name' => $this->repository->safeOutput($data[self::NAME]), - 'idGroup' => $data[self::ID_GROUP], - 'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]), - 'severity' => $severity, - 'status' => EventFilterStatusEnum::get($data[self::STATUS]), - 'search' => $this->repository->safeOutput($data[self::SEARCH]), - 'isNotSearch' => $data[self::NOT_SEARCH], - 'textAgent' => $this->repository->safeOutput($data[self::TEXT_AGENT]), - 'idAgent' => $data[self::ID_AGENT], - 'idAgentModule' => $data[self::ID_AGENT_MODULE], - 'pagination' => $data[self::PAGINATION], - 'slice' => $data[self::SLICE], - 'idUserAck' => $data[self::ID_USER_ACK], - 'groupBy' => EventFilterGroupByEnum::get($data[self::ORDER_BY]), - 'tagWith' => (empty($data[self::TAG_WITH]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITH])) : null, - 'tagWithout' => (empty($data[self::TAG_WITHOUT]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITHOUT])) : null, - 'filterOnlyAlert' => EventFilterAlertEnum::get($data[self::FILTER_ONLY_ALERT]), - 'searchSecondaryGroups' => $data[self::SEARCH_SECONDARY_GROUPS], - 'searchRecursiveGroups' => $data[self::SEARCH_RECURSIVE_GROUPS], - 'dateFrom' => $data[self::DATE_FROM], - 'dateTo' => $data[self::DATE_TO], - 'source' => $this->repository->safeOutput($this->repository->safeOutput($data[self::SOURCE])), - 'idExtra' => $this->repository->safeOutput($data[self::ID_EXTRA]), - 'userComment' => $this->repository->safeOutput($data[self::USER_COMMENT]), - 'idSourceEvent' => $data[self::ID_SOURCE_EVENT], - 'serverId' => (empty($data[self::SERVER_ID]) === false) ? explode(',', $data[self::SERVER_ID]) : null, - 'timeFrom' => $data[self::TIME_FROM], - 'timeTo' => $data[self::TIME_TO], - 'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]), - 'customDataFilterType' => EventFilterCustomDataEnum::get($data[self::CUSTOM_DATA_FILTER_TYPE]), - 'ownerUser' => $data[self::OWNER_USER], - 'privateFilterUser' => $data[self::PRIVATE_FILTER_USER], - 'regex' => $this->repository->safeOutput($data[self::REGEX]), - ]); + return $this->builder->build( + new EventFilter(), + [ + 'idEventFilter' => $data[self::ID_FILTER], + 'idGroupFilter' => $data[self::ID_GROUP_FILTER], + 'name' => $this->repository->safeOutput($data[self::NAME]), + 'idGroup' => $data[self::ID_GROUP], + 'eventType' => EventTypeEnum::get($data[self::EVENT_TYPE]), + 'severity' => $severity, + 'status' => EventFilterStatusEnum::get($data[self::STATUS]), + 'search' => $this->repository->safeOutput($data[self::SEARCH]), + 'isNotSearch' => $data[self::NOT_SEARCH], + 'textAgent' => $this->repository->safeOutput($data[self::TEXT_AGENT]), + 'idAgent' => $data[self::ID_AGENT], + 'idAgentModule' => $data[self::ID_AGENT_MODULE], + 'pagination' => $data[self::PAGINATION], + 'slice' => $data[self::SLICE], + 'idUserAck' => $data[self::ID_USER_ACK], + 'groupBy' => EventFilterGroupByEnum::get($data[self::ORDER_BY]), + 'tagWith' => (empty($data[self::TAG_WITH]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITH])) : null, + 'tagWithout' => (empty($data[self::TAG_WITHOUT]) === false) ? explode(',', $this->repository->safeOutput($data[self::TAG_WITHOUT])) : null, + 'filterOnlyAlert' => EventFilterAlertEnum::get($data[self::FILTER_ONLY_ALERT]), + 'searchSecondaryGroups' => $data[self::SEARCH_SECONDARY_GROUPS], + 'searchRecursiveGroups' => $data[self::SEARCH_RECURSIVE_GROUPS], + 'dateFrom' => $data[self::DATE_FROM], + 'dateTo' => $data[self::DATE_TO], + 'source' => $this->repository->safeOutput($this->repository->safeOutput($data[self::SOURCE])), + 'idExtra' => $this->repository->safeOutput($data[self::ID_EXTRA]), + 'userComment' => $this->repository->safeOutput($data[self::USER_COMMENT]), + 'idSourceEvent' => $data[self::ID_SOURCE_EVENT], + 'serverId' => (empty($data[self::SERVER_ID]) === false) ? explode(',', $data[self::SERVER_ID]) : null, + 'timeFrom' => $data[self::TIME_FROM], + 'timeTo' => $data[self::TIME_TO], + 'customData' => $this->repository->safeOutput($data[self::CUSTOM_DATA]), + 'customDataFilterType' => EventFilterCustomDataEnum::get($data[self::CUSTOM_DATA_FILTER_TYPE]), + 'ownerUser' => $data[self::OWNER_USER], + 'privateFilterUser' => $data[self::PRIVATE_FILTER_USER], + 'regex' => $this->repository->safeOutput($data[self::REGEX]), + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var EventFilter $data */ + /* + @var EventFilter $data + */ $severity = null; - if(empty($data->getSeverity()) === false) { + if (empty($data->getSeverity()) === false) { $severities = []; foreach ($data->getSeverity() as $value) { $severities[] = EventSeverityEnum::get($value)?->value; } + $severity = implode(',', $severities); } @@ -166,4 +176,6 @@ final class EventFilterDataMapper extends DataMapperAbstract self::REGEX => $this->repository->safeInput($data->getRegex()), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterFilter.php b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterFilter.php index be28bc4a8b..a7ead0db13 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterFilter.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Entities/EventFilterFilter.php @@ -39,9 +39,12 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class EventFilterFilter extends FilterAbstract { + private ?string $freeSearch = null; + private ?string $fieldAclGroupMysql = EventFilterDataMapper::ID_GROUP; + public function __construct() { $this->setDefaultFieldOrder(EventFilterDataMapper::NAME); @@ -49,6 +52,7 @@ final class EventFilterFilter extends FilterAbstract $this->setEntityFilter(new EventFilter()); } + public function fieldsTranslate(): array { return [ @@ -93,6 +97,7 @@ final class EventFilterFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return [ @@ -101,6 +106,7 @@ final class EventFilterFilter extends FilterAbstract ]; } + public function jsonSerialize(): mixed { return [ @@ -108,21 +114,25 @@ final class EventFilterFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; - if($this->getEntityFilter() !== null) { + if ($this->getEntityFilter() !== null) { $validations = $this->getEntityFilter()->getValidations(); } + $validations['freeSearch'] = Validator::STRING; return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of freeSearch. * @@ -133,11 +143,11 @@ final class EventFilterFilter extends FilterAbstract return $this->freeSearch; } + /** * Set the value of freeSearch. * - * @param ?string $freeSearch - * + * @param string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -145,6 +155,7 @@ final class EventFilterFilter extends FilterAbstract return $this; } + /** * Get the value of fieldsFreeSearch. * @@ -155,6 +166,7 @@ final class EventFilterFilter extends FilterAbstract return [EventFilterDataMapper::NAME]; } + /** * Get the value of fieldAclGroupMysql. * @@ -165,11 +177,11 @@ final class EventFilterFilter extends FilterAbstract return $this->fieldAclGroupMysql; } + /** * Set the value of fieldAclGroupMysql. * - * @param ?string $fieldAclGroupMysql - * + * @param string $fieldAclGroupMysql */ public function setFieldAclGroupMysql(?string $fieldAclGroupMysql): self { @@ -178,6 +190,7 @@ final class EventFilterFilter extends FilterAbstract return $this; } + /** * Get the value of mode for check ACL. * @@ -187,4 +200,6 @@ final class EventFilterFilter extends FilterAbstract { return ''; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterAlertEnum.php b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterAlertEnum.php index 0b785e9f73..c26aae6ad9 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterAlertEnum.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterAlertEnum.php @@ -8,7 +8,7 @@ enum EventFilterAlertEnum: int { use EnumTrait; - case ALL = -1; - case FILTER_ALERT_EVENTS = 0; - case ONLY_ALERT_EVENTS = 1; -} +case ALL = -1; +case FILTER_ALERT_EVENTS = 0; +case ONLY_ALERT_EVENTS = 1; + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterCustomDataEnum.php b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterCustomDataEnum.php index ee94439c4f..3a7622da32 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterCustomDataEnum.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterCustomDataEnum.php @@ -8,6 +8,6 @@ enum EventFilterCustomDataEnum: int { use EnumTrait; - case NAME = 0; - case VALUE = 1; -} +case NAME = 0; +case VALUE = 1; + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterGroupByEnum.php b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterGroupByEnum.php index b306d47217..162dc602a1 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterGroupByEnum.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterGroupByEnum.php @@ -8,8 +8,8 @@ enum EventFilterGroupByEnum: int { use EnumTrait; - case ALL = 0; - case EVENTS = 1; - case AGENTS = 2; - case EXTRA_IDS = 3; -} +case ALL = 0; +case EVENTS = 1; +case AGENTS = 2; +case EXTRA_IDS = 3; + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterStatusEnum.php b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterStatusEnum.php index 9bad37f9dc..7b1882d154 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterStatusEnum.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Enums/EventFilterStatusEnum.php @@ -8,10 +8,10 @@ enum EventFilterStatusEnum: int { use EnumTrait; - case ALL = -1; - case NEW = 0; - case VALIDATED = 1; - case IN_PROCESS = 2; - case NOT_VALIDATED = 3; - case NOT_IN_PROCESS = 4; -} +case ALL = -1; +case new = 0; +case VALIDATED = 1; +case IN_PROCESS = 2; +case NOT_VALIDATED = 3; +case NOT_IN_PROCESS = 4; + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Repositories/EventFilterRepository.php b/pandora_console/include/lib/Modules/Events/Filters/Repositories/EventFilterRepository.php index 10649efe72..ea1b11951b 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Repositories/EventFilterRepository.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Repositories/EventFilterRepository.php @@ -9,15 +9,18 @@ use PandoraFMS\Modules\Shared\Repositories\Repository; class EventFilterRepository { + + public function __construct( private Repository $repository, private EventFilterDataMapper $eventFilterDataMapper ) { } + /** * @return EventFilter[], - */ + */ public function list(EventFilterFilter $eventFilterFilter): array { return $this->repository->__list( @@ -26,6 +29,7 @@ class EventFilterRepository ); } + public function count(EventFilterFilter $eventFilterFilter): int { return $this->repository->__count( @@ -34,6 +38,7 @@ class EventFilterRepository ); } + public function getOne(EventFilterFilter $eventFilterFilter): EventFilter { return $this->repository->__getOne( @@ -42,12 +47,14 @@ class EventFilterRepository ); } + public function create(EventFilter $eventFilter): EventFilter { $id = $this->repository->__create($eventFilter, $this->eventFilterDataMapper); return $eventFilter->setIdEventFilter($id); } + public function update(EventFilter $eventFilter): EventFilter { return $this->repository->__update( @@ -57,9 +64,11 @@ class EventFilterRepository ); } + public function delete(int $id): void { $this->repository->__delete($id, $this->eventFilterDataMapper); } + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/CountEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/CountEventFilterService.php index f630481542..a9d9365e78 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/CountEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/CountEventFilterService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Repositories\EventFilterRepository; final class CountEventFilterService { + + public function __construct( private EventFilterRepository $eventFilterRepository, ) { } + public function __invoke(EventFilterFilter $eventFilterFilter): int { return $this->eventFilterRepository->count($eventFilterFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/CreateEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/CreateEventFilterService.php index 35ec490bcf..eb8ae8ab77 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/CreateEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/CreateEventFilterService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateEventFilterService { + + public function __construct( private Audit $audit, private EventFilterRepository $eventFilterRepository, @@ -16,6 +18,7 @@ final class CreateEventFilterService ) { } + public function __invoke(EventFilter $eventFilter): EventFilter { $this->eventFilterValidation->__invoke($eventFilter); @@ -30,4 +33,6 @@ final class CreateEventFilterService return $eventFilter; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/DeleteEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/DeleteEventFilterService.php index 2732c46f56..b7764445ed 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/DeleteEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/DeleteEventFilterService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class DeleteEventFilterService { + + public function __construct( private Audit $audit, private EventFilterRepository $eventFilterRepository, ) { } + public function __invoke(EventFilter $eventFilter): void { $idEventFilter = $eventFilter->getIdEventFilter(); @@ -26,4 +29,6 @@ final class DeleteEventFilterService 'Deleted eventFilter '.$nameEventFilter ); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/ExistNameEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/ExistNameEventFilterService.php index 98366da148..1fc696b637 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/ExistNameEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/ExistNameEventFilterService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistNameEventFilterService { + + public function __construct( private EventFilterRepository $eventFilterRepository, ) { } + public function __invoke(string $name): bool { $eventFilterFilter = new EventFilterFilter(); - /** @var EventFilter $entityFilter */ + /* + @var EventFilter $entityFilter + */ $entityFilter = $eventFilterFilter->getEntityFilter(); $entityFilter->setName($name); @@ -28,4 +33,6 @@ final class ExistNameEventFilterService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/GetEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/GetEventFilterService.php index 9d8dedd725..47fd23b378 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/GetEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/GetEventFilterService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Events\Filters\Repositories\EventFilterRepository; final class GetEventFilterService { + + public function __construct( private EventFilterRepository $eventFilterRepository, ) { } + public function __invoke(int $idEventFilter): EventFilter { $eventFilterFilter = new EventFilterFilter(); - /** @var EventFilter $entityFilter */ + /* + @var EventFilter $entityFilter + */ $entityFilter = $eventFilterFilter->getEntityFilter(); $entityFilter->setIdEventFilter($idEventFilter); return $this->eventFilterRepository->getOne($eventFilterFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/ListEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/ListEventFilterService.php index ae1514c172..3803628e13 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/ListEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/ListEventFilterService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Filters\Repositories\EventFilterRepository; final class ListEventFilterService { + + public function __construct( private EventFilterRepository $eventFilterRepository, ) { } + public function __invoke(EventFilterFilter $eventFilterFilter): array { return $this->eventFilterRepository->list($eventFilterFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Services/UpdateEventFilterService.php b/pandora_console/include/lib/Modules/Events/Filters/Services/UpdateEventFilterService.php index aaeb028d92..2015cc526c 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Services/UpdateEventFilterService.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Services/UpdateEventFilterService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateEventFilterService { + + public function __construct( private Audit $audit, private EventFilterRepository $eventFilterRepository, @@ -16,6 +18,7 @@ final class UpdateEventFilterService ) { } + public function __invoke(EventFilter $eventFilter, EventFilter $oldEventFilter): EventFilter { $this->eventFilterValidation->__invoke($eventFilter, $oldEventFilter); @@ -30,4 +33,6 @@ final class UpdateEventFilterService return $eventFilter; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Validations/EventFilterValidation.php b/pandora_console/include/lib/Modules/Events/Filters/Validations/EventFilterValidation.php index c54fe0f251..bc7a680bc9 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Validations/EventFilterValidation.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Validations/EventFilterValidation.php @@ -17,6 +17,8 @@ use PandoraFMS\Modules\Users\Services\GetUserService; final class EventFilterValidation { + + public function __construct( private ExistNameEventFilterService $existNameEventFilterService, private GetUserService $getUserService, @@ -25,14 +27,15 @@ final class EventFilterValidation ) { } - public function __invoke(EventFilter $eventFilter, ?EventFilter $oldEventFilter = null): void + + public function __invoke(EventFilter $eventFilter, ?EventFilter $oldEventFilter=null): void { if (!$eventFilter->getName()) { throw new BadRequestException(__('Name is missing')); } - if($oldEventFilter === null || $oldEventFilter->getName() !== $eventFilter->getName()) { - if($this->existNameEventFilterService->__invoke($eventFilter->getName()) === true) { + if ($oldEventFilter === null || $oldEventFilter->getName() !== $eventFilter->getName()) { + if ($this->existNameEventFilterService->__invoke($eventFilter->getName()) === true) { throw new BadRequestException( __('Name %s is already exists', $eventFilter->getName()) ); @@ -131,16 +134,19 @@ final class EventFilterValidation } } + private function validateUser(string $idUser): void { $this->getUserService->__invoke($idUser); } + protected function validateGroup(int $idGroup): void { $this->getGroupService->__invoke($idGroup); } + protected function validateTags(array $tags): void { foreach ($tags as $tag) { @@ -148,6 +154,7 @@ final class EventFilterValidation } } + protected function validateAgent(int $idAgent): void { // TODO: create new service for this. @@ -160,10 +167,11 @@ final class EventFilterValidation } } - protected function validateAgentModule(int $idAgentModule, ?int $idAgent = 0): void + + protected function validateAgentModule(int $idAgentModule, ?int $idAgent=0): void { // TODO: create new service for this. - if(empty($idAgent) === false) { + if (empty($idAgent) === false) { $agent = new Agent($idAgent); $existModule = $agent->searchModules( ['id_agente_modulo' => $idAgentModule], @@ -190,15 +198,17 @@ final class EventFilterValidation } } + protected function validateNodes(array $nodes): void { // TODO: create new service for this. } + protected function validateSeverities(array $severities): void { foreach ($severities as $severity) { - if($severity !== null) { + if ($severity !== null) { $result = EventSeverityEnum::get(strtoupper($severity)); if (empty($result) === true) { throw new BadRequestException(__('Invalid severity: %s', $severity)); @@ -206,4 +216,6 @@ final class EventFilterValidation } } } + + } diff --git a/pandora_console/include/lib/Modules/Events/Filters/Validators/EventFilterValidator.php b/pandora_console/include/lib/Modules/Events/Filters/Validators/EventFilterValidator.php index edf4b49133..1ea7f1ce18 100644 --- a/pandora_console/include/lib/Modules/Events/Filters/Validators/EventFilterValidator.php +++ b/pandora_console/include/lib/Modules/Events/Filters/Validators/EventFilterValidator.php @@ -17,33 +17,40 @@ class EventFilterValidator extends Validator public const VALIDFILTERSTATUS = 'ValidFilterStatus'; public const VALIDFILTERTYPE = 'ValidFilterType'; + protected function isValidFilterAlert($section): bool { $result = EventFilterAlertEnum::get(strtoupper($section)); return empty($result) === true ? false : true; } + protected function isValidFilterCustomData($status): bool { $result = EventFilterCustomDataEnum::get(strtoupper($status)); return empty($result) === true ? false : true; } + protected function isValidFilterGroupBy($type): bool { $result = EventFilterGroupByEnum::get(strtoupper($type)); return empty($result) === true ? false : true; } + protected function isValidFilterStatus($status): bool { $result = EventFilterStatusEnum::get(strtoupper($status)); return empty($result) === true ? false : true; } + protected function isValidFilterType($type): bool { $result = EventTypeEnum::get(strtoupper($type)); return empty($result) === true ? false : true; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Repositories/EventRepository.php b/pandora_console/include/lib/Modules/Events/Repositories/EventRepository.php index 8ea1b168ef..546ef38581 100644 --- a/pandora_console/include/lib/Modules/Events/Repositories/EventRepository.php +++ b/pandora_console/include/lib/Modules/Events/Repositories/EventRepository.php @@ -7,18 +7,27 @@ use PandoraFMS\Modules\Events\Entities\Event; interface EventRepository { + + /** * @return Event[], */ public function list(EventFilter $eventFilter): array; + public function count(EventFilter $eventFilter): int; + public function getOne(EventFilter $eventFilter): Event; + public function create(Event $event): Event; + public function update(Event $event): Event; + public function delete(string $id): void; + + } diff --git a/pandora_console/include/lib/Modules/Events/Repositories/EventRepositoryMySQL.php b/pandora_console/include/lib/Modules/Events/Repositories/EventRepositoryMySQL.php index 9bf0916860..bc4b6c9777 100644 --- a/pandora_console/include/lib/Modules/Events/Repositories/EventRepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Events/Repositories/EventRepositoryMySQL.php @@ -13,12 +13,15 @@ use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL; class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository { + + public function __construct( private EventDataMapper $eventDataMapper, private Config $config ) { } + /** * @return Event[], */ @@ -40,7 +43,6 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository $order, $sort_field ); - } catch (\Throwable $th) { // Capture errors mysql. throw new InvalidArgumentException( @@ -61,6 +63,7 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository return $result; } + public function count(EventFilter $eventFilter): int { try { @@ -89,6 +92,7 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository return (int) $count; } + public function getOne(EventFilter $eventFilter): Event { try { @@ -119,12 +123,14 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository return $this->eventDataMapper->fromDatabase($result); } + public function create(Event $event): Event { $id = $this->__create($event, $this->eventDataMapper); return $event->setIdEvent($id); } + public function update(Event $event): Event { return $this->__update( @@ -134,21 +140,23 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository ); } + public function delete(string $id): void { $this->__delete($id, $this->eventDataMapper); } + public function getEvents( $fields, $filter, - $offset = null, - $limit = null, - $order = null, - $sort_field = null + $offset=null, + $limit=null, + $order=null, + $sort_field=null ): array { ob_start(); - require_once $this->config->get('homedir').'/include/functions_events.php'; + include_once $this->config->get('homedir').'/include/functions_events.php'; $events = \events_get_all( $fields, $filter, @@ -166,4 +174,6 @@ class EventRepositoryMySQL extends RepositoryMySQL implements EventRepository return $events; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/CountEventService.php b/pandora_console/include/lib/Modules/Events/Services/CountEventService.php index fa94a11c9d..2f41706495 100644 --- a/pandora_console/include/lib/Modules/Events/Services/CountEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/CountEventService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Repositories\EventRepository; final class CountEventService { + + public function __construct( private EventRepository $eventRepository, ) { } + public function __invoke(EventFilter $eventFilter): int { return $this->eventRepository->count($eventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/CreateEventService.php b/pandora_console/include/lib/Modules/Events/Services/CreateEventService.php index 06aba7f506..5ba1d3d08e 100644 --- a/pandora_console/include/lib/Modules/Events/Services/CreateEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/CreateEventService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateEventService { + + public function __construct( private Audit $audit, private EventRepository $eventRepository, @@ -18,6 +20,7 @@ final class CreateEventService ) { } + public function __invoke(Event $event): Event { $this->eventValidation->__invoke($event); @@ -35,10 +38,12 @@ final class CreateEventService ); if (empty($event->getIdExtra()) === false) { - //$this->updateEventService->__invoke(); - //'UPDATE tevento SET estado = 1, ack_utimestamp = ? WHERE estado IN (0,2) AND id_extra=?' + // $this->updateEventService->__invoke(); + // 'UPDATE tevento SET estado = 1, ack_utimestamp = ? WHERE estado IN (0,2) AND id_extra=?' } return $event; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/DeleteEventService.php b/pandora_console/include/lib/Modules/Events/Services/DeleteEventService.php index 738d7be042..22cc47d1ec 100644 --- a/pandora_console/include/lib/Modules/Events/Services/DeleteEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/DeleteEventService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class DeleteEventService { + + public function __construct( private Audit $audit, private EventRepository $eventRepository, ) { } + public function __invoke(Event $event): void { $idEvent = $event->getIdEvent(); @@ -25,4 +28,6 @@ final class DeleteEventService 'Deleted event '.$idEvent ); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/GetEventService.php b/pandora_console/include/lib/Modules/Events/Services/GetEventService.php index 059a5500f4..9e36569e21 100644 --- a/pandora_console/include/lib/Modules/Events/Services/GetEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/GetEventService.php @@ -8,11 +8,14 @@ use PandoraFMS\Modules\Events\Repositories\EventRepository; final class GetEventService { + + public function __construct( private EventRepository $eventRepository, ) { } + public function __invoke(int $idEvent): Event { $eventFilter = new EventFilter(); @@ -20,4 +23,6 @@ final class GetEventService return $this->eventRepository->getOne($eventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/KeepInProcessStatusExtraIdEventService.php b/pandora_console/include/lib/Modules/Events/Services/KeepInProcessStatusExtraIdEventService.php index b7b9beef4a..2d4596b4aa 100644 --- a/pandora_console/include/lib/Modules/Events/Services/KeepInProcessStatusExtraIdEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/KeepInProcessStatusExtraIdEventService.php @@ -10,25 +10,32 @@ use PandoraFMS\Modules\Events\Repositories\EventRepository; final class KeepInProcessStatusExtraIdEventService { + + public function __construct( private Config $config, private EventRepository $eventRepository ) { } + public function __invoke(Event $event): Event { - if((bool) $this->config->get('keep_in_process_status_extra_id') === true) { - if($event->getStatus() === EventStatusEnum::NEW) { + if ((bool) $this->config->get('keep_in_process_status_extra_id') === true) { + if ($event->getStatus() === EventStatusEnum::NEW) { $eventFilter = new EventFilter(); - /** @var Event $entityFilter */ + /* + @var Event $entityFilter + */ $entityFilter = $eventFilter->getEntityFilter(); $entityFilter->setIdExtra($event->getIdExtra()); $entityFilter->setStatus(EventStatusEnum::INPROCESS); $inprocessCount = $this->eventRepository->count($eventFilter); - if(empty($inprocessCount) === false) { - /** @var Event $inprocessLastEvent */ + if (empty($inprocessCount) === false) { + /* + @var Event $inprocessLastEvent + */ $inprocessLastEvent = end($this->eventRepository->list($eventFilter)); $event->setAckUtimestamp($inprocessLastEvent->getAckUtimestamp()); $event->setEventCustomId($inprocessLastEvent->getEventCustomId()); @@ -38,4 +45,6 @@ final class KeepInProcessStatusExtraIdEventService return $event; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/ListEventService.php b/pandora_console/include/lib/Modules/Events/Services/ListEventService.php index 5085cc5eba..e035157130 100644 --- a/pandora_console/include/lib/Modules/Events/Services/ListEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/ListEventService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Events\Repositories\EventRepository; final class ListEventService { + + public function __construct( private EventRepository $eventRepository, ) { } + public function __invoke(EventFilter $eventFilter): array { return $this->eventRepository->list($eventFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Services/UpdateEventService.php b/pandora_console/include/lib/Modules/Events/Services/UpdateEventService.php index 21a56f162c..d993a905b0 100644 --- a/pandora_console/include/lib/Modules/Events/Services/UpdateEventService.php +++ b/pandora_console/include/lib/Modules/Events/Services/UpdateEventService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateEventService { + + public function __construct( private Audit $audit, private EventRepository $eventRepository, @@ -16,6 +18,7 @@ final class UpdateEventService ) { } + public function __invoke(Event $event, Event $oldEvent): Event { $this->eventValidation->__invoke($event, $oldEvent); @@ -30,4 +33,6 @@ final class UpdateEventService return $event; } + + } diff --git a/pandora_console/include/lib/Modules/Events/Validations/EventValidation.php b/pandora_console/include/lib/Modules/Events/Validations/EventValidation.php index f017e35cba..60ebc62d24 100644 --- a/pandora_console/include/lib/Modules/Events/Validations/EventValidation.php +++ b/pandora_console/include/lib/Modules/Events/Validations/EventValidation.php @@ -16,6 +16,8 @@ use PandoraFMS\Modules\Users\Services\GetUserService; final class EventValidation { + + public function __construct( private ValidateAclSystem $acl, private Config $config, @@ -25,7 +27,8 @@ final class EventValidation ) { } - public function __invoke(Event $event, ?Event $oldEvent = null): void + + public function __invoke(Event $event, ?Event $oldEvent=null): void { if (!$event->getEvent()) { throw new BadRequestException(__('Event is missing')); @@ -103,16 +106,19 @@ final class EventValidation } } + private function validateUser(string $idUser): void { $this->getUserService->__invoke($idUser); } + protected function validateGroup(int $idGroup): void { $this->getGroupService->__invoke($idGroup); } + protected function validateAgent(int $idAgent): void { // TODO: create new service for this. @@ -125,10 +131,11 @@ final class EventValidation } } - protected function validateAgentModule(int $idAgentModule, ?int $idAgent = 0): void + + protected function validateAgentModule(int $idAgentModule, ?int $idAgent=0): void { // TODO: create new service for this. - if(empty($idAgent) === false) { + if (empty($idAgent) === false) { $agent = new Agent($idAgent); $existModule = $agent->searchModules( ['id_agente_modulo' => $idAgentModule], @@ -155,6 +162,7 @@ final class EventValidation } } + protected function validateAlert(int $idAlert): void { // TODO: create new service for this. @@ -163,13 +171,17 @@ final class EventValidation } } + protected function getCurrentTimestamp(): string { return $this->timestamp->getMysqlCurrentTimestamp(0); } + protected function getCurrentUtimestamp(): int { return $this->timestamp->getMysqlSystemUtimestamp(); } + + } diff --git a/pandora_console/include/lib/Modules/Events/Validators/EventValidator.php b/pandora_console/include/lib/Modules/Events/Validators/EventValidator.php index d818159087..598e8af37f 100644 --- a/pandora_console/include/lib/Modules/Events/Validators/EventValidator.php +++ b/pandora_console/include/lib/Modules/Events/Validators/EventValidator.php @@ -13,21 +13,26 @@ class EventValidator extends Validator public const VALIDSTATUS = 'ValidStatus'; public const VALIDTYPE = 'ValidType'; + protected function isValidSeverity($section): bool { $result = EventSeverityEnum::get(strtoupper($section)); return empty($result) === true ? false : true; } + protected function isValidStatus($status): bool { $result = EventStatusEnum::get(strtoupper($status)); return empty($result) === true ? false : true; } + protected function isValidType($type): bool { $result = EventTypeEnum::get(strtoupper($type)); return empty($result) === true ? false : true; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Actions/CreateGroupAction.php b/pandora_console/include/lib/Modules/Groups/Actions/CreateGroupAction.php index 490a2c9530..966db2d07f 100644 --- a/pandora_console/include/lib/Modules/Groups/Actions/CreateGroupAction.php +++ b/pandora_console/include/lib/Modules/Groups/Actions/CreateGroupAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Services\CreateGroupService; final class CreateGroupAction { + + public function __construct( private CreateGroupService $createGroupService ) { } + public function __invoke(Group $group): Group { return $this->createGroupService->__invoke($group); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Actions/DeleteGroupAction.php b/pandora_console/include/lib/Modules/Groups/Actions/DeleteGroupAction.php index 79997862cd..5af6c3fd10 100644 --- a/pandora_console/include/lib/Modules/Groups/Actions/DeleteGroupAction.php +++ b/pandora_console/include/lib/Modules/Groups/Actions/DeleteGroupAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Services\DeleteGroupService; final class DeleteGroupAction { + + public function __construct( private DeleteGroupService $deleteGroupService ) { } + public function __invoke(Group $group): void { $this->deleteGroupService->__invoke($group); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Actions/GetGroupAction.php b/pandora_console/include/lib/Modules/Groups/Actions/GetGroupAction.php index fc70b8cd52..ae4664d32a 100644 --- a/pandora_console/include/lib/Modules/Groups/Actions/GetGroupAction.php +++ b/pandora_console/include/lib/Modules/Groups/Actions/GetGroupAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Services\GetGroupService; final class GetGroupAction { + + public function __construct( private GetGroupService $getGroupService ) { } + public function __invoke(int $idGroup): Group { return $this->getGroupService->__invoke($idGroup); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Actions/ListGroupAction.php b/pandora_console/include/lib/Modules/Groups/Actions/ListGroupAction.php index 94f2fb074c..b94e5ad279 100644 --- a/pandora_console/include/lib/Modules/Groups/Actions/ListGroupAction.php +++ b/pandora_console/include/lib/Modules/Groups/Actions/ListGroupAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListGroupAction { + + public function __construct( private ListGroupService $listGroupService, private CountGroupService $countGroupService ) { } + public function __invoke(GroupFilter $groupFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListGroupAction $this->listGroupService->__invoke($groupFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Actions/UpdateGroupAction.php b/pandora_console/include/lib/Modules/Groups/Actions/UpdateGroupAction.php index ee4b4d9e69..4066551a56 100644 --- a/pandora_console/include/lib/Modules/Groups/Actions/UpdateGroupAction.php +++ b/pandora_console/include/lib/Modules/Groups/Actions/UpdateGroupAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Services\UpdateGroupService; final class UpdateGroupAction { + + public function __construct( private UpdateGroupService $updateGroupService ) { } + public function __invoke(Group $group, Group $oldGroup): Group { return $this->updateGroupService->__invoke($group, $oldGroup); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php index 70ddf3d891..c0e7f1b048 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateGroupController extends Controller { + + public function __construct( private CreateGroupAction $createGroupAction, private ValidateAclSystem $acl, @@ -20,19 +22,20 @@ final class CreateGroupController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Groups"}, * path="/group", * summary="Creates a new groups", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyGroup"), - * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyGroup"), + * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -50,4 +53,6 @@ final class CreateGroupController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php index 91b29597c4..b5c361cbbf 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteGroupController extends Controller { + + public function __construct( private DeleteGroupAction $deleteGroupAction, private ValidateAclSystem $acl, @@ -21,19 +23,20 @@ final class DeleteGroupController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Groups"}, * path="/group/{idGroup}", * summary="Deletes an group object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdGroup"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdGroup"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -48,4 +51,6 @@ final class DeleteGroupController extends Controller $result = $this->deleteGroupAction->__invoke($group); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/GetGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/GetGroupController.php index 032a15eb03..b9b856bbf6 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/GetGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/GetGroupController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetGroupController extends Controller { + + public function __construct( private GetGroupAction $getGroupAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/group/{idGroup}", * tags={"Groups"}, * summary="Show group", - * @OA\Parameter(ref="#/components/parameters/parameterIdGroup"), - * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdGroup"), + * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -41,4 +44,6 @@ final class GetGroupController extends Controller $result = $this->getGroupAction->__invoke($idGroup); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/ListGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/ListGroupController.php index 31850053b8..5be44d7afc 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/ListGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/ListGroupController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListGroupController extends Controller { + + public function __construct( private ListGroupAction $listGroupAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Groups"}, * path="/group/list", * summary="List groups", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyGroupFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyGroupFilter"), + * @OA\Response( * response="200", * description="List Groups Object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/Group", * description="Array of group objects" * ) @@ -54,11 +57,11 @@ final class ListGroupController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -71,4 +74,6 @@ final class ListGroupController extends Controller $result = $this->listGroupAction->__invoke($groupFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php index 3256407f7f..1a80711eb5 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php @@ -19,16 +19,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an group", * @OA\Parameter(ref="#/components/parameters/parameterIdGroup"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyGroup"), - * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseGroup"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateGroupController extends Controller { + + public function __construct( private UpdateGroupAction $updateGroupAction, private ValidateAclSystem $acl, @@ -37,6 +39,7 @@ final class UpdateGroupController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idGroup = $this->getParam($request, 'idGroup'); @@ -53,4 +56,6 @@ final class UpdateGroupController extends Controller $result = $this->updateGroupAction->__invoke($group, $oldGroup); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Entities/Group.php b/pandora_console/include/lib/Modules/Groups/Entities/Group.php index bcc37d17cf..0ac7b6b84d 100644 --- a/pandora_console/include/lib/Modules/Groups/Entities/Group.php +++ b/pandora_console/include/lib/Modules/Groups/Entities/Group.php @@ -157,31 +157,49 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class Group extends Entity { + private ?int $idGroup = null; + private ?string $name = null; + private ?string $icon = null; + private ?int $parent = null; + private ?string $parentName = null; + private ?bool $haschild = null; + private ?bool $isPropagate = null; + private ?bool $isAlertEnabled = null; + private ?string $customId = null; + private ?int $idSkin = null; + private ?string $description = null; + private ?string $contact = null; + private ?string $other = null; + private ?string $password = null; + private ?int $maxAgents = null; + public function __construct() { } + public function fieldsReadOnly(): array { return ['idGroup' => 1]; } + public function jsonSerialize(): mixed { return [ @@ -202,16 +220,17 @@ final class Group extends Entity ]; } + public function getValidations(): array { return [ - 'idGroup' => [ + 'idGroup' => [ Validator::INTEGER, Validator::GREATERTHAN, ], - 'name' => Validator::STRING, - 'icon' => Validator::STRING, - 'parent' => [ + 'name' => Validator::STRING, + 'icon' => Validator::STRING, + 'parent' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], @@ -222,168 +241,216 @@ final class Group extends Entity Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'description' => Validator::STRING, - 'contact' => Validator::STRING, - 'other' => Validator::STRING, - 'maxAgents' => [ + 'description' => Validator::STRING, + 'contact' => Validator::STRING, + 'other' => Validator::STRING, + 'maxAgents' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getIdGroup(): ?int { return $this->idGroup; } + + public function setIdGroup(?int $idGroup): self { $this->idGroup = $idGroup; return $this; } + public function getName(): ?string { return $this->name; } + + public function setName(?string $name): self { $this->name = $name; return $this; } + public function getIcon(): ?string { return $this->icon; } + + public function setIcon(?string $icon): self { $this->icon = $icon; return $this; } + public function getParent(): ?int { return $this->parent; } + + public function setParent(?int $parent): self { $this->parent = $parent; return $this; } + public function getIsPropagate(): ?bool { return $this->isPropagate; } + + public function setIsPropagate(?bool $isPropagate): self { $this->isPropagate = $isPropagate; return $this; } + public function getIsAlertEnabled(): ?bool { return $this->isAlertEnabled; } + + public function setIsAlertEnabled(?bool $isAlertEnabled): self { $this->isAlertEnabled = $isAlertEnabled; return $this; } + public function getCustomId(): ?string { return $this->customId; } + + public function setCustomId(?string $customId): self { $this->customId = $customId; return $this; } + public function getIdSkin(): ?int { return $this->idSkin; } + + public function setIdSkin(?int $idSkin): self { $this->idSkin = $idSkin; return $this; } + public function getDescription(): ?string { return $this->description; } + + public function setDescription(?string $description): self { $this->description = $description; return $this; } + public function getContact(): ?string { return $this->contact; } + + public function setContact(?string $contact): self { $this->contact = $contact; return $this; } + public function getOther(): ?string { return $this->other; } + + public function setOther(?string $other): self { $this->other = $other; return $this; } + public function getPassword(): ?string { return $this->password; } + + public function setPassword(?string $password): self { $this->password = $password; return $this; } + public function getMaxAgents(): ?int { return $this->maxAgents; } + + public function setMaxAgents(?int $maxAgents): self { $this->maxAgents = $maxAgents; return $this; } + public function getParentName(): ?string { return $this->parentName; } + + public function setParentName(?string $parentName): self { $this->parentName = $parentName; return $this; } + public function getHaschild(): ?bool { return $this->haschild; } + + public function setHaschild(?bool $haschild): self { $this->haschild = $haschild; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Entities/GroupDataMapper.php b/pandora_console/include/lib/Modules/Groups/Entities/GroupDataMapper.php index e15b5bbd1a..75d5e12599 100644 --- a/pandora_console/include/lib/Modules/Groups/Entities/GroupDataMapper.php +++ b/pandora_console/include/lib/Modules/Groups/Entities/GroupDataMapper.php @@ -24,6 +24,7 @@ final class GroupDataMapper extends DataMapperAbstract public const PASSWORD = 'password'; public const MAX_AGENTS = 'max_agents'; + public function __construct( private Repository $repository, private Builder $builder, @@ -34,33 +35,41 @@ final class GroupDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return Group::class; } + public function fromDatabase(array $data): Group { - return $this->builder->build(new Group(), [ - 'idGroup' => $data[self::ID_GROUP], - 'name' => $this->repository->safeOutput($data[self::NAME]), - 'icon' => $data[self::ICON], - 'parent' => $data[self::PARENT], - 'isPropagate' => $data[self::IS_PROPAGATE], - 'isAlertEnabled' => $data[self::IS_DISABLED], - 'customId' => $data[self::CUSTOM_ID], - 'idSkin' => $data[self::ID_SKIN], - 'description' => $this->repository->safeOutput($data[self::DESCRIPTION]), - 'contact' => $this->repository->safeOutput($data[self::CONTACT]), - 'other' => $this->repository->safeOutput($data[self::OTHER]), - 'password' => $data[self::PASSWORD], - 'maxAgents' => $data[self::MAX_AGENTS], - ]); + return $this->builder->build( + new Group(), + [ + 'idGroup' => $data[self::ID_GROUP], + 'name' => $this->repository->safeOutput($data[self::NAME]), + 'icon' => $data[self::ICON], + 'parent' => $data[self::PARENT], + 'isPropagate' => $data[self::IS_PROPAGATE], + 'isAlertEnabled' => $data[self::IS_DISABLED], + 'customId' => $data[self::CUSTOM_ID], + 'idSkin' => $data[self::ID_SKIN], + 'description' => $this->repository->safeOutput($data[self::DESCRIPTION]), + 'contact' => $this->repository->safeOutput($data[self::CONTACT]), + 'other' => $this->repository->safeOutput($data[self::OTHER]), + 'password' => $data[self::PASSWORD], + 'maxAgents' => $data[self::MAX_AGENTS], + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var Group $data */ + /* + @var Group $data + */ return [ self::ID_GROUP => $data->getIdGroup(), self::NAME => $this->repository->safeInput($data->getName()), @@ -77,4 +86,6 @@ final class GroupDataMapper extends DataMapperAbstract self::MAX_AGENTS => $data->getMaxAgents(), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php b/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php index 362ddbb016..3d39504503 100644 --- a/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php +++ b/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php @@ -39,8 +39,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class GroupFilter extends FilterAbstract { + private ?string $freeSearch = null; + public function __construct() { $this->setDefaultFieldOrder(GroupDataMapper::NAME); @@ -48,6 +50,7 @@ final class GroupFilter extends FilterAbstract $this->setEntityFilter(new Group()); } + public function fieldsTranslate(): array { return [ @@ -67,11 +70,13 @@ final class GroupFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return ['password' => 1]; } + public function jsonSerialize(): mixed { return [ @@ -79,21 +84,25 @@ final class GroupFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; - if($this->getEntityFilter() !== null) { + if ($this->getEntityFilter() !== null) { $validations = $this->getEntityFilter()->getValidations(); } + $validations['freeSearch'] = Validator::STRING; return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of freeSearch. * @@ -104,11 +113,11 @@ final class GroupFilter extends FilterAbstract return $this->freeSearch; } + /** * Set the value of freeSearch. * - * @param ?string $freeSearch - * + * @param string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -116,6 +125,7 @@ final class GroupFilter extends FilterAbstract return $this; } + /** * Get the value of fieldsFreeSearch. * @@ -128,4 +138,6 @@ final class GroupFilter extends FilterAbstract GroupDataMapper::TABLE_NAME.'.'.GroupDataMapper::DESCRIPTION, ]; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepository.php b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepository.php index 9f31a76131..ad143dfefe 100644 --- a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepository.php +++ b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepository.php @@ -7,18 +7,27 @@ use PandoraFMS\Modules\Groups\Entities\GroupFilter; interface GroupRepository { + + /** * @return Group[], */ public function list(GroupFilter $groupFilter): array; + public function count(GroupFilter $groupFilter): int; + public function getOne(GroupFilter $groupFilter): Group; + public function create(Group $group): Group; + public function update(Group $group): Group; + public function delete(int $id): void; + + } diff --git a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php index b7ceda64b0..6e564d3f27 100644 --- a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php @@ -15,12 +15,15 @@ use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL; class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository { + + public function __construct( private GroupDataMapper $groupDataMapper, private Config $config ) { } + /** * @return Group[], */ @@ -49,6 +52,7 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository return $result; } + public function count(GroupFilter $groupFilter): int { $sql = $this->getGroupsQuery($groupFilter, $this->groupDataMapper, true); @@ -65,6 +69,7 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository return (int) $count; } + public function getOne(GroupFilter $groupFilter): Group { try { @@ -85,12 +90,14 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository return $this->groupDataMapper->fromDatabase($result); } + public function create(Group $group): Group { $id = $this->__create($group, $this->groupDataMapper); return $group->setIdGroup($id); } + public function update(Group $group): Group { return $this->__update( @@ -100,15 +107,17 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository ); } + public function delete(int $id): void { $this->__delete($id, $this->groupDataMapper); } + private function getGroupsQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count = false + bool $count=false ): string { $pagination = ''; $orderBy = ''; @@ -166,4 +175,6 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository return $sql; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/CountGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/CountGroupService.php index 4b8cccc95f..e9e9e61e26 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/CountGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/CountGroupService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Repositories\GroupRepository; final class CountGroupService { + + public function __construct( private GroupRepository $groupRepository, ) { } + public function __invoke(GroupFilter $groupFilter): int { return $this->groupRepository->count($groupFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/CreateGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/CreateGroupService.php index f2f0d0c2da..f55491ec6b 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/CreateGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/CreateGroupService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateGroupService { + + public function __construct( private Audit $audit, private GroupRepository $groupRepository, @@ -16,6 +18,7 @@ final class CreateGroupService ) { } + public function __invoke(Group $group): Group { $this->groupValidation->__invoke($group); @@ -30,4 +33,6 @@ final class CreateGroupService return $group; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/DeleteGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/DeleteGroupService.php index 66e1658b4c..c369da822d 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/DeleteGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/DeleteGroupService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class DeleteGroupService { + + public function __construct( private Audit $audit, private GroupRepository $groupRepository, ) { } + public function __invoke(Group $group): void { $idGroup = $group->getIdGroup(); @@ -39,4 +42,6 @@ final class DeleteGroupService 'Deleted group '.$idGroup ); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/ExistNameGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/ExistNameGroupService.php index 29c15d7c23..0db518c959 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/ExistNameGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/ExistNameGroupService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistNameGroupService { + + public function __construct( private GroupRepository $GroupRepository, ) { } + public function __invoke(string $name): bool { $GroupFilter = new GroupFilter(); - /** @var Group $entityFilter */ + /* + @var Group $entityFilter + */ $entityFilter = $GroupFilter->getEntityFilter(); $entityFilter->setName($name); @@ -28,4 +33,6 @@ final class ExistNameGroupService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/GetGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/GetGroupService.php index 6734e1221d..44bfd31135 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/GetGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/GetGroupService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Groups\Repositories\GroupRepository; final class GetGroupService { + + public function __construct( private GroupRepository $groupRepository, ) { } + public function __invoke(int $idGroup): Group { $groupFilter = new GroupFilter(); - /** @var Group $entityFilter */ + /* + @var Group $entityFilter + */ $entityFilter = $groupFilter->getEntityFilter(); $entityFilter->setIdGroup($idGroup); return $this->groupRepository->getOne($groupFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/ListGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/ListGroupService.php index 48acb34e37..bf73e1f794 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/ListGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/ListGroupService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Groups\Repositories\GroupRepository; final class ListGroupService { + + public function __construct( private GroupRepository $groupRepository, ) { } + public function __invoke(GroupFilter $groupFilter): array { return $this->groupRepository->list($groupFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Services/UpdateGroupService.php b/pandora_console/include/lib/Modules/Groups/Services/UpdateGroupService.php index 6c98677a74..e14a58f744 100644 --- a/pandora_console/include/lib/Modules/Groups/Services/UpdateGroupService.php +++ b/pandora_console/include/lib/Modules/Groups/Services/UpdateGroupService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateGroupService { + + public function __construct( private Audit $audit, private GroupRepository $groupRepository, @@ -16,6 +18,7 @@ final class UpdateGroupService ) { } + public function __invoke(Group $group, Group $oldGroup): Group { $this->groupValidation->__invoke($group, $oldGroup); @@ -30,4 +33,6 @@ final class UpdateGroupService return $group; } + + } diff --git a/pandora_console/include/lib/Modules/Groups/Validations/GroupValidation.php b/pandora_console/include/lib/Modules/Groups/Validations/GroupValidation.php index c8a5081d80..cd369c5d86 100644 --- a/pandora_console/include/lib/Modules/Groups/Validations/GroupValidation.php +++ b/pandora_console/include/lib/Modules/Groups/Validations/GroupValidation.php @@ -10,6 +10,8 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; final class GroupValidation { + + public function __construct( private ValidateAclSystem $acl, private GetGroupService $getGroupService, @@ -17,14 +19,15 @@ final class GroupValidation ) { } - public function __invoke(Group $group, ?Group $oldGroup = null): void + + public function __invoke(Group $group, ?Group $oldGroup=null): void { if (!$group->getName()) { throw new BadRequestException(__('Name is missing')); } if ($oldGroup === null || $oldGroup->getName() !== $group->getName()) { - if($this->existNameGroupService->__invoke($group->getName()) === true) { + if ($this->existNameGroupService->__invoke($group->getName()) === true) { throw new BadRequestException( __('Name %s is already exists', $group->getName()) ); @@ -65,11 +68,13 @@ final class GroupValidation } } + protected function validateGroup(int $idGroup): void { $this->getGroupService->__invoke($idGroup); } + protected function validateSkin(int $idSkin): void { // TODO: create new service for this. @@ -77,4 +82,6 @@ final class GroupValidation throw new BadRequestException(__('Invalid id skin')); } } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php index c0538da7fc..614b302001 100644 --- a/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php +++ b/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Services\CreateProfileService; final class CreateProfileAction { + + public function __construct( private CreateProfileService $createProfileService ) { } + public function __invoke(Profile $profile): Profile { return $this->createProfileService->__invoke($profile); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php index 719850a4ed..0e339a0d8e 100644 --- a/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php +++ b/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Services\DeleteProfileService; final class DeleteProfileAction { + + public function __construct( private DeleteProfileService $deleteProfileService ) { } + public function __invoke(Profile $profile): void { $this->deleteProfileService->__invoke($profile); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php index 9af07f3686..0d4ac76818 100644 --- a/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php +++ b/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Services\GetProfileService; final class GetProfileAction { + + public function __construct( private GetProfileService $getProfileService ) { } + public function __invoke(int $idProfile): Profile { return $this->getProfileService->__invoke($idProfile); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php index cdaaa203a4..915fa13db5 100644 --- a/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php +++ b/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListProfileAction { + + public function __construct( private ListProfileService $listProfileService, private CountProfileService $countProfileService ) { } + public function __invoke(ProfileFilter $profileFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListProfileAction $this->listProfileService->__invoke($profileFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php index 0e564d080e..d1efbb2e85 100644 --- a/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php +++ b/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Services\UpdateProfileService; final class UpdateProfileAction { + + public function __construct( private UpdateProfileService $updateProfileService ) { } + public function __invoke(Profile $profile, Profile $oldProfile): Profile { return $this->updateProfileService->__invoke($profile, $oldProfile); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php index 65298dc26f..778a6fe61f 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateProfileController extends Controller { + + public function __construct( private CreateProfileAction $createProfileAction, private ValidateAclSystem $acl, @@ -20,19 +22,20 @@ final class CreateProfileController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Profiles"}, * path="/profile", * summary="Creates a new profiles", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -51,4 +54,6 @@ final class CreateProfileController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php index 536b025989..44b32d80cb 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteProfileController extends Controller { + + public function __construct( private DeleteProfileAction $deleteProfileAction, private ValidateAclSystem $acl, @@ -21,19 +23,20 @@ final class DeleteProfileController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Profiles"}, * path="/profile/{idProfile}", * summary="Deletes an profile object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -51,4 +54,6 @@ final class DeleteProfileController extends Controller $result = $this->deleteProfileAction->__invoke($profile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php index 113606d548..f2567ddc6f 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetProfileController extends Controller { + + public function __construct( private GetProfileAction $getProfileAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/profile/{idProfile}", * tags={"Profiles"}, * summary="Show profile", - * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -42,4 +45,6 @@ final class GetProfileController extends Controller $result = $this->getProfileAction->__invoke($idProfile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php index c2a290c9af..6e25e7721e 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListProfileController extends Controller { + + public function __construct( private ListProfileAction $listProfileAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Profiles"}, * path="/profile/list", * summary="List profiles", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyProfileFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyProfileFilter"), + * @OA\Response( * response="200", * description="List Incidence object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/Profile", * description="Array of incidences Type objects" * ) @@ -54,11 +57,11 @@ final class ListProfileController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -72,4 +75,6 @@ final class ListProfileController extends Controller $result = $this->listProfileAction->__invoke($profileFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php index 6d064cec4a..b9d1d437c4 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php @@ -19,16 +19,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an profile", * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseProfile"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateProfileController extends Controller { + + public function __construct( private UpdateProfileAction $updateProfileAction, private ValidateAclSystem $acl, @@ -37,6 +39,7 @@ final class UpdateProfileController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idProfile = $this->getParam($request, 'idProfile'); @@ -56,4 +59,6 @@ final class UpdateProfileController extends Controller $result = $this->updateProfileAction->__invoke($profile, $oldProfile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php b/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php index ceea2a7ee4..a17f586dbe 100644 --- a/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php +++ b/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php @@ -224,41 +224,69 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class Profile extends Entity { + private ?int $idProfile = null; + private ?string $name = null; + private ?bool $isAgentView = null; + private ?bool $isAgentEdit = null; + private ?bool $isAlertEdit = null; + private ?bool $isUserManagement = null; + private ?bool $isDbManagement = null; + private ?bool $isAlertManagement = null; + private ?bool $isPandoraManagement = null; + private ?bool $isReportView = null; + private ?bool $isReportEdit = null; + private ?bool $isReportManagement = null; + private ?bool $isEventView = null; + private ?bool $isEventEdit = null; + private ?bool $isEventManagement = null; + private ?bool $isAgentDisable = null; + private ?bool $isMapView = null; + private ?bool $isMapEdit = null; + private ?bool $isMapManagement = null; + private ?bool $isVconsoleView = null; + private ?bool $isVconsoleEdit = null; + private ?bool $isVconsoleManagement = null; + private ?bool $isNetworkConfigView = null; + private ?bool $isNetworkConfigEdit = null; + private ?bool $isNetworkConfigManagement = null; + public function __construct() { } + public function fieldsReadOnly(): array { return ['idProfile' => 1]; } + public function jsonSerialize(): mixed { return [ @@ -290,10 +318,11 @@ final class Profile extends Entity ]; } + public function getValidations(): array { return [ - 'idProfile' => [ + 'idProfile' => [ Validator::INTEGER, Validator::GREATERTHAN, ], @@ -324,258 +353,336 @@ final class Profile extends Entity ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getIdProfile(): ?int { return $this->idProfile; } + + public function setIdProfile(?int $idProfile): self { $this->idProfile = $idProfile; return $this; } + public function getName(): ?string { return $this->name; } + + public function setName(?string $name): self { $this->name = $name; return $this; } + public function getIsAgentView(): ?bool { return $this->isAgentView; } + + public function setIsAgentView(?bool $isAgentView): self { $this->isAgentView = $isAgentView; return $this; } + public function getIsAgentEdit(): ?bool { return $this->isAgentEdit; } + + public function setIsAgentEdit(?bool $isAgentEdit): self { $this->isAgentEdit = $isAgentEdit; return $this; } + public function getIsAlertEdit(): ?bool { return $this->isAlertEdit; } + + public function setIsAlertEdit(?bool $isAlertEdit): self { $this->isAlertEdit = $isAlertEdit; return $this; } + public function getIsUserManagement(): ?bool { return $this->isUserManagement; } + + public function setIsUserManagement(?bool $isUserManagement): self { $this->isUserManagement = $isUserManagement; return $this; } + public function getIsDbManagement(): ?bool { return $this->isDbManagement; } + + public function setIsDbManagement(?bool $isDbManagement): self { $this->isDbManagement = $isDbManagement; return $this; } + public function getIsAlertManagement(): ?bool { return $this->isAlertManagement; } + + public function setIsAlertManagement(?bool $isAlertManagement): self { $this->isAlertManagement = $isAlertManagement; return $this; } + public function getIsPandoraManagement(): ?bool { return $this->isPandoraManagement; } + + public function setIsPandoraManagement(?bool $isPandoraManagement): self { $this->isPandoraManagement = $isPandoraManagement; return $this; } + public function getIsReportView(): ?bool { return $this->isReportView; } + + public function setIsReportView(?bool $isReportView): self { $this->isReportView = $isReportView; return $this; } + public function getIsReportEdit(): ?bool { return $this->isReportEdit; } + + public function setIsReportEdit(?bool $isReportEdit): self { $this->isReportEdit = $isReportEdit; return $this; } + public function getIsReportManagement(): ?bool { return $this->isReportManagement; } + + public function setIsReportManagement(?bool $isReportManagement): self { $this->isReportManagement = $isReportManagement; return $this; } + public function getIsEventView(): ?bool { return $this->isEventView; } + + public function setIsEventView(?bool $isEventView): self { $this->isEventView = $isEventView; return $this; } + public function getIsEventEdit(): ?bool { return $this->isEventEdit; } + + public function setIsEventEdit(?bool $isEventEdit): self { $this->isEventEdit = $isEventEdit; return $this; } + public function getIsEventManagement(): ?bool { return $this->isEventManagement; } + + public function setIsEventManagement(?bool $isEventManagement): self { $this->isEventManagement = $isEventManagement; return $this; } + public function getIsAgentDisable(): ?bool { return $this->isAgentDisable; } + + public function setIsAgentDisable(?bool $isAgentDisable): self { $this->isAgentDisable = $isAgentDisable; return $this; } + public function getIsMapView(): ?bool { return $this->isMapView; } + + public function setIsMapView(?bool $isMapView): self { $this->isMapView = $isMapView; return $this; } + public function getIsMapEdit(): ?bool { return $this->isMapEdit; } + + public function setIsMapEdit(?bool $isMapEdit): self { $this->isMapEdit = $isMapEdit; return $this; } + public function getIsMapManagement(): ?bool { return $this->isMapManagement; } + + public function setIsMapManagement(?bool $isMapManagement): self { $this->isMapManagement = $isMapManagement; return $this; } + public function getIsVconsoleView(): ?bool { return $this->isVconsoleView; } + + public function setIsVconsoleView(?bool $isVconsoleView): self { $this->isVconsoleView = $isVconsoleView; return $this; } + public function getIsVconsoleEdit(): ?bool { return $this->isVconsoleEdit; } + + public function setIsVconsoleEdit(?bool $isVconsoleEdit): self { $this->isVconsoleEdit = $isVconsoleEdit; return $this; } + public function getIsVconsoleManagement(): ?bool { return $this->isVconsoleManagement; } + + public function setIsVconsoleManagement(?bool $isVconsoleManagement): self { $this->isVconsoleManagement = $isVconsoleManagement; return $this; } + public function getIsNetworkConfigView(): ?bool { return $this->isNetworkConfigView; } + + public function setIsNetworkConfigView(?bool $isNetworkConfigView): self { $this->isNetworkConfigView = $isNetworkConfigView; return $this; } + public function getIsNetworkConfigEdit(): ?bool { return $this->isNetworkConfigEdit; } + + public function setIsNetworkConfigEdit(?bool $isNetworkConfigEdit): self { $this->isNetworkConfigEdit = $isNetworkConfigEdit; return $this; } + public function getIsNetworkConfigManagement(): ?bool { return $this->isNetworkConfigManagement; } + + public function setIsNetworkConfigManagement(?bool $isNetworkConfigManagement): self { $this->isNetworkConfigManagement = $isNetworkConfigManagement; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php index 46f3214143..5866d21460 100644 --- a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php +++ b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php @@ -36,6 +36,7 @@ final class ProfileDataMapper extends DataMapperAbstract public const IS_NETWORK_CONFIG_EDIT = 'network_config_edit'; public const IS_NETWORK_CONFIG_MANAGEMENT = 'network_config_management'; + public function __construct( private Repository $repository, private Builder $builder, @@ -46,45 +47,53 @@ final class ProfileDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return Profile::class; } + public function fromDatabase(array $data): Profile { - return $this->builder->build(new Profile(), [ - 'idProfile' => $data[self::ID_PROFILE], - 'name' => $this->repository->safeOutput($data[self::NAME]), - 'isAgentView' => $data[self::IS_AGENT_VIEW], - 'isAgentEdit' => $data[self::IS_AGENT_EDIT], - 'isAlertEdit' => $data[self::IS_ALERT_EDIT], - 'isUserManagement' => $data[self::IS_USER_MANAGEMENT], - 'isDbManagement' => $data[self::IS_DB_MANAGEMENT], - 'isAlertManagement' => $data[self::IS_ALERT_MANAGEMENT], - 'isPandoraManagement' => $data[self::IS_PANDORA_MANAGEMENT], - 'isReportView' => $data[self::IS_REPORT_VIEW], - 'isReportEdit' => $data[self::IS_REPORT_EDIT], - 'isReportManagement' => $data[self::IS_REPORT_MANAGEMENT], - 'isEventView' => $data[self::IS_EVENT_VIEW], - 'isEventEdit' => $data[self::IS_EVENT_EDIT], - 'isEventManagement' => $data[self::IS_EVENT_MANAGEMENT], - 'isAgentDisable' => $data[self::IS_AGENT_DISABLE], - 'isMapView' => $data[self::IS_MAP_VIEW], - 'isMapEdit' => $data[self::IS_MAP_EDIT], - 'isMapManagement' => $data[self::IS_MAP_MANAGEMENT], - 'isVconsoleView' => $data[self::IS_VCONSOLE_VIEW], - 'isVconsoleEdit' => $data[self::IS_VCONSOLE_EDIT], - 'isVconsoleManagement' => $data[self::IS_VCONSOLE_MANAGEMENT], - 'isNetworkConfigView' => $data[self::IS_NETWORK_CONFIG_VIEW], - 'isNetworkConfigEdit' => $data[self::IS_NETWORK_CONFIG_EDIT], - 'isNetworkConfigManagement' => $data[self::IS_NETWORK_CONFIG_MANAGEMENT], - ]); + return $this->builder->build( + new Profile(), + [ + 'idProfile' => $data[self::ID_PROFILE], + 'name' => $this->repository->safeOutput($data[self::NAME]), + 'isAgentView' => $data[self::IS_AGENT_VIEW], + 'isAgentEdit' => $data[self::IS_AGENT_EDIT], + 'isAlertEdit' => $data[self::IS_ALERT_EDIT], + 'isUserManagement' => $data[self::IS_USER_MANAGEMENT], + 'isDbManagement' => $data[self::IS_DB_MANAGEMENT], + 'isAlertManagement' => $data[self::IS_ALERT_MANAGEMENT], + 'isPandoraManagement' => $data[self::IS_PANDORA_MANAGEMENT], + 'isReportView' => $data[self::IS_REPORT_VIEW], + 'isReportEdit' => $data[self::IS_REPORT_EDIT], + 'isReportManagement' => $data[self::IS_REPORT_MANAGEMENT], + 'isEventView' => $data[self::IS_EVENT_VIEW], + 'isEventEdit' => $data[self::IS_EVENT_EDIT], + 'isEventManagement' => $data[self::IS_EVENT_MANAGEMENT], + 'isAgentDisable' => $data[self::IS_AGENT_DISABLE], + 'isMapView' => $data[self::IS_MAP_VIEW], + 'isMapEdit' => $data[self::IS_MAP_EDIT], + 'isMapManagement' => $data[self::IS_MAP_MANAGEMENT], + 'isVconsoleView' => $data[self::IS_VCONSOLE_VIEW], + 'isVconsoleEdit' => $data[self::IS_VCONSOLE_EDIT], + 'isVconsoleManagement' => $data[self::IS_VCONSOLE_MANAGEMENT], + 'isNetworkConfigView' => $data[self::IS_NETWORK_CONFIG_VIEW], + 'isNetworkConfigEdit' => $data[self::IS_NETWORK_CONFIG_EDIT], + 'isNetworkConfigManagement' => $data[self::IS_NETWORK_CONFIG_MANAGEMENT], + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var Profile $data */ + /* + @var Profile $data + */ return [ self::ID_PROFILE => $data->getIdProfile(), self::NAME => $this->repository->safeInput($data->getName()), @@ -113,4 +122,6 @@ final class ProfileDataMapper extends DataMapperAbstract self::IS_NETWORK_CONFIG_MANAGEMENT => $data->getIsNetworkConfigManagement(), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php index bc0e87652f..084b18b2aa 100644 --- a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php +++ b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php @@ -39,8 +39,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class ProfileFilter extends FilterAbstract { + private ?string $freeSearch = null; + public function __construct() { $this->setDefaultFieldOrder(ProfileDataMapper::NAME); @@ -48,6 +50,7 @@ final class ProfileFilter extends FilterAbstract $this->setEntityFilter(new Profile()); } + public function fieldsTranslate(): array { return [ @@ -56,11 +59,13 @@ final class ProfileFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return []; } + public function jsonSerialize(): mixed { return [ @@ -68,21 +73,25 @@ final class ProfileFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; - if($this->getEntityFilter() !== null) { + if ($this->getEntityFilter() !== null) { $validations = $this->getEntityFilter()->getValidations(); } + $validations['freeSearch'] = Validator::STRING; return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of freeSearch. * @@ -93,11 +102,11 @@ final class ProfileFilter extends FilterAbstract return $this->freeSearch; } + /** * Set the value of freeSearch. * - * @param ?string $freeSearch - * + * @param string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -105,6 +114,7 @@ final class ProfileFilter extends FilterAbstract return $this; } + /** * Get the value of fieldsFreeSearch. * @@ -115,4 +125,5 @@ final class ProfileFilter extends FilterAbstract return [ProfileDataMapper::NAME]; } + } diff --git a/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php b/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php index ca556cf912..a5249b9ec4 100644 --- a/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php +++ b/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php @@ -9,15 +9,18 @@ use PandoraFMS\Modules\Shared\Repositories\Repository; class ProfileRepository { + + public function __construct( private Repository $repository, private ProfileDataMapper $profileDataMapper ) { } + /** * @return Profile[], - */ + */ public function list(ProfileFilter $profileFilter): array { return $this->repository->__list( @@ -26,6 +29,7 @@ class ProfileRepository ); } + public function count(ProfileFilter $profileFilter): int { return $this->repository->__count( @@ -34,6 +38,7 @@ class ProfileRepository ); } + public function getOne(ProfileFilter $profileFilter): Profile { return $this->repository->__getOne( @@ -42,12 +47,14 @@ class ProfileRepository ); } + public function create(Profile $profile): Profile { $id = $this->repository->__create($profile, $this->profileDataMapper); return $profile->setIdProfile($id); } + public function update(Profile $profile): Profile { return $this->repository->__update( @@ -57,9 +64,11 @@ class ProfileRepository ); } + public function delete(int $id): void { $this->repository->__delete($id, $this->profileDataMapper); } + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php index 3fb03cd721..ded574031a 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Repositories\ProfileRepository; final class CountProfileService { + + public function __construct( private ProfileRepository $profileRepository, ) { } + public function __invoke(ProfileFilter $profileFilter): int { return $this->profileRepository->count($profileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php index c64ac5e77c..5aba652baf 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateProfileService { + + public function __construct( private Audit $audit, private ProfileRepository $profileRepository, @@ -16,6 +18,7 @@ final class CreateProfileService ) { } + public function __invoke(Profile $profile): Profile { $this->profileValidation->__invoke($profile); @@ -30,4 +33,6 @@ final class CreateProfileService return $profile; } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php index f2e391ee20..40fcb14573 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class DeleteProfileService { + + public function __construct( private Audit $audit, private ProfileRepository $profileRepository, ) { } + public function __invoke(Profile $profile): void { $idProfile = $profile->getIdProfile(); @@ -26,4 +29,6 @@ final class DeleteProfileService 'Deleted profile '.$nameProfile ); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php index 1620a804be..801c8b93c6 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistNameProfileService { + + public function __construct( private ProfileRepository $profileRepository, ) { } + public function __invoke(string $name): bool { $profileFilter = new ProfileFilter(); - /** @var Profile $entityFilter */ + /* + @var Profile $entityFilter + */ $entityFilter = $profileFilter->getEntityFilter(); $entityFilter->setName($name); @@ -28,4 +33,6 @@ final class ExistNameProfileService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php index 330a248f45..d2db2e3651 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Profiles\Repositories\ProfileRepository; final class GetProfileService { + + public function __construct( private ProfileRepository $profileRepository, ) { } + public function __invoke(int $idProfile): Profile { $profileFilter = new ProfileFilter(); - /** @var Profile $entityFilter */ + /* + @var Profile $entityFilter + */ $entityFilter = $profileFilter->getEntityFilter(); $entityFilter->setIdProfile($idProfile); return $this->profileRepository->getOne($profileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php index 24f684f5b6..f5bb6cd327 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Profiles\Repositories\ProfileRepository; final class ListProfileService { + + public function __construct( private ProfileRepository $profileRepository, ) { } + public function __invoke(ProfileFilter $profileFilter): array { return $this->profileRepository->list($profileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php index b4c66e6952..cbf0c08d65 100644 --- a/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php +++ b/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateProfileService { + + public function __construct( private Audit $audit, private ProfileRepository $profileRepository, @@ -16,6 +18,7 @@ final class UpdateProfileService ) { } + public function __invoke(Profile $profile, Profile $oldProfile): Profile { $this->profileValidation->__invoke($profile, $oldProfile); @@ -30,4 +33,6 @@ final class UpdateProfileService return $profile; } + + } diff --git a/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php b/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php index e284e3d82f..410a86d7b6 100644 --- a/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php +++ b/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php @@ -8,115 +8,120 @@ use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; final class ProfileValidation { + + public function __construct( private ExistNameProfileService $existNameProfileService ) { } - public function __invoke(Profile $profile, ?Profile $oldProfile = null): void + + public function __invoke(Profile $profile, ?Profile $oldProfile=null): void { if (!$profile->getName()) { throw new BadRequestException(__('Name is missing')); } - if($oldProfile === null || $oldProfile->getName() !== $profile->getName()) { - if($this->existNameProfileService->__invoke($profile->getName()) === true) { + if ($oldProfile === null || $oldProfile->getName() !== $profile->getName()) { + if ($this->existNameProfileService->__invoke($profile->getName()) === true) { throw new BadRequestException( __('Name %s is already exists', $profile->getName()) ); } } - if($profile->getIsAgentView() === null) { + if ($profile->getIsAgentView() === null) { $profile->setIsAgentView(false); } - if($profile->getIsAgentEdit() === null) { + if ($profile->getIsAgentEdit() === null) { $profile->setIsAgentEdit(false); } - if($profile->getIsAlertEdit() === null) { + if ($profile->getIsAlertEdit() === null) { $profile->setIsAlertEdit(false); } - if($profile->getIsUserManagement() === null) { + if ($profile->getIsUserManagement() === null) { $profile->setIsUserManagement(false); } - if($profile->getIsDbManagement() === null) { + if ($profile->getIsDbManagement() === null) { $profile->setIsDbManagement(false); } - if($profile->getIsAlertManagement() === null) { + if ($profile->getIsAlertManagement() === null) { $profile->setIsAlertManagement(false); } - if($profile->getIsPandoraManagement() === null) { + if ($profile->getIsPandoraManagement() === null) { $profile->setIsPandoraManagement(false); } - if($profile->getIsReportView() === null) { + if ($profile->getIsReportView() === null) { $profile->setIsReportView(false); } - if($profile->getIsReportEdit() === null) { + if ($profile->getIsReportEdit() === null) { $profile->setIsReportEdit(false); } - if($profile->getIsReportManagement() === null) { + if ($profile->getIsReportManagement() === null) { $profile->setIsReportManagement(false); } - if($profile->getIsEventView() === null) { + if ($profile->getIsEventView() === null) { $profile->setIsEventView(false); } - if($profile->getIsEventEdit() === null) { + if ($profile->getIsEventEdit() === null) { $profile->setIsEventEdit(false); } - if($profile->getIsEventManagement() === null) { + if ($profile->getIsEventManagement() === null) { $profile->setIsEventManagement(false); } - if($profile->getIsAgentDisable() === null) { + if ($profile->getIsAgentDisable() === null) { $profile->setIsAgentDisable(false); } - if($profile->getIsMapView() === null) { + if ($profile->getIsMapView() === null) { $profile->setIsMapView(false); } - if($profile->getIsMapEdit() === null) { + if ($profile->getIsMapEdit() === null) { $profile->setIsMapEdit(false); } - if($profile->getIsMapManagement() === null) { + if ($profile->getIsMapManagement() === null) { $profile->setIsMapManagement(false); } - if($profile->getIsVconsoleView() === null) { + if ($profile->getIsVconsoleView() === null) { $profile->setIsVconsoleView(false); } - if($profile->getIsVconsoleEdit() === null) { + if ($profile->getIsVconsoleEdit() === null) { $profile->setIsVconsoleEdit(false); } - if($profile->getIsVconsoleManagement() === null) { + if ($profile->getIsVconsoleManagement() === null) { $profile->setIsVconsoleManagement(false); } - if($profile->getIsNetworkConfigView() === null) { + if ($profile->getIsNetworkConfigView() === null) { $profile->setIsNetworkConfigView(false); } - if($profile->getIsNetworkConfigEdit() === null) { + if ($profile->getIsNetworkConfigEdit() === null) { $profile->setIsNetworkConfigEdit(false); } - if($profile->getIsNetworkConfigManagement() === null) { + if ($profile->getIsNetworkConfigManagement() === null) { $profile->setIsNetworkConfigManagement(false); } } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Builders/Builder.php b/pandora_console/include/lib/Modules/Shared/Builders/Builder.php index 97e22f8b7d..1c188439b3 100644 --- a/pandora_console/include/lib/Modules/Shared/Builders/Builder.php +++ b/pandora_console/include/lib/Modules/Shared/Builders/Builder.php @@ -7,6 +7,8 @@ use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; class Builder { + + public function build(Entity $entity, array $data): Entity { foreach ($data as $field => $value) { @@ -19,4 +21,6 @@ class Builder return $entity; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php b/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php index 8be849b606..42dd1cdfc7 100644 --- a/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php +++ b/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php @@ -18,10 +18,13 @@ use Slim\Routing\RouteContext; abstract class Controller { + + public function __construct() { } + public function getParam(Request $request, string $param): mixed { $routeContext = RouteContext::fromRequest($request); @@ -35,6 +38,7 @@ abstract class Controller return $value; } + public function getFile(Request $request, string $file): UploadedFileInterface { $files = $request->getUploadedFiles(); @@ -49,6 +53,7 @@ abstract class Controller return $files[$file]; } + public function extractParams(Request $request): array { $queryParams = ($request->getQueryParams() ?? []); @@ -67,6 +72,7 @@ abstract class Controller return $params; } + public function fromRequest(Request $request, string $className): mixed { $params = $this->extractParams($request); @@ -84,10 +90,11 @@ abstract class Controller return $class->fromArray($params); } + public function getResponse( Response $response, mixed $result, - ?string $contentType = 'application/json' + ?string $contentType='application/json' ): Response { if ($contentType === 'application/json') { $result = json_encode($result); @@ -97,6 +104,7 @@ abstract class Controller return $response->withHeader('Content-Type', $contentType); } + public function getResponseAttachment(Response $response, string $path, string $fileName) { try { @@ -112,4 +120,6 @@ abstract class Controller return $response->withBody($file_stream)->withHeader('Content-Disposition', 'attachment; filename='.$fileName)->withHeader('Content-Type', mime_content_type($path)); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php index 8920fc80ef..df43075d0f 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php @@ -4,38 +4,50 @@ namespace PandoraFMS\Modules\Shared\Core; abstract class DataMapperAbstract { + private null|string $tableRelated = null; + private null|string $keyRelated = null; + private null|string $searchFieldRelated = null; + private mixed $searchFieldValueRelated = null; + public function __construct( private string $tableName, private string $primaryKey ) { } + abstract public function getClassName(): string; + abstract public function fromDatabase(array $data): MappeableInterface; + abstract public function toDatabase(MappeableInterface $data): array; + public function getTableName(): string { return $this->tableName; } + public function getPrimaryKey(): string { return $this->primaryKey; } + public function getTableRelated(): null|string { return $this->tableRelated; } + public function setTableRelated(null|string $tableRelated): self { $this->tableRelated = $tableRelated; @@ -43,11 +55,13 @@ abstract class DataMapperAbstract return $this; } + public function getKeyRelated(): null|string { return $this->keyRelated; } + public function setKeyRelated(null|string $keyRelated): self { $this->keyRelated = $keyRelated; @@ -55,11 +69,13 @@ abstract class DataMapperAbstract return $this; } + public function getSearchFieldRelated(): null|string { return $this->searchFieldRelated; } + public function setSearchFieldRelated(null|string $searchFieldRelated): self { $this->searchFieldRelated = $searchFieldRelated; @@ -67,11 +83,13 @@ abstract class DataMapperAbstract return $this; } + public function getSearchFieldValueRelated(): mixed { return $this->searchFieldValueRelated; } + public function setSearchFieldValueRelated(mixed $searchFieldValueRelated): self { $this->searchFieldValueRelated = $searchFieldValueRelated; @@ -79,6 +97,7 @@ abstract class DataMapperAbstract return $this; } + public function getStringNameClass(): string { $strname = [ @@ -96,4 +115,6 @@ abstract class DataMapperAbstract return $result; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php index 3f593bcd9d..bb5e1d3b07 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php @@ -19,43 +19,56 @@ abstract class FilterAbstract extends SerializableAbstract public const DESC = 'DESC'; private ?int $limit = null; + private ?int $offset = null; + private ?string $defaultFieldOrder = null; + private ?string $defaultDirectionOrder = null; + private ?array $fields = null; + private ?Entity $entityFilter = null; + public function __construct() { } + abstract public function fieldsTranslate(): array; + public function getFieldsFreeSearch(): ?array { return []; } + public function getMultipleSearch(): ?array { return []; } + public function getMultipleSearchString(): ?array { return []; } + public function getFieldAclGroupMysql(): ?string { return ''; } + public function getModeAclGroupMysql(): ?string { return null; } + public function fromArray(array $params): static { $fails = $this->validate($params); @@ -72,7 +85,7 @@ abstract class FilterAbstract extends SerializableAbstract if (method_exists($this, 'set'.ucfirst($field)) === true) { $this->{'set'.ucfirst($field)}($value ?? null); - } elseif ($this->getEntityFilter() !== null && method_exists($this->getEntityFilter(), 'set'.ucfirst($field)) === true) { + } else if ($this->getEntityFilter() !== null && method_exists($this->getEntityFilter(), 'set'.ucfirst($field)) === true) { $this->getEntityFilter()->{'set'.ucfirst($field)}($value ?? null); } } @@ -80,11 +93,13 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getLimit(): ?int { return $this->limit; } + public function setLimit(?int $limit): self { $this->limit = $limit; @@ -92,11 +107,13 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getOffset(): ?int { return $this->offset; } + public function setOffset(?int $offset): self { $this->offset = $offset; @@ -104,11 +121,13 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getDefaultFieldOrder(): ?string { return $this->defaultFieldOrder; } + public function setDefaultFieldOrder(?string $defaultFieldOrder): self { $this->defaultFieldOrder = $defaultFieldOrder; @@ -116,11 +135,13 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getDefaultDirectionOrder(): ?string { return $this->defaultDirectionOrder; } + public function setDefaultDirectionOrder(?string $defaultDirectionOrder): self { $this->defaultDirectionOrder = $defaultDirectionOrder; @@ -128,11 +149,13 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getEntityFilter(): ?Entity { return $this->entityFilter; } + public function setEntityFilter(?Entity $entityFilter): self { $this->entityFilter = $entityFilter; @@ -140,15 +163,19 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } + public function getFields(): ?array { return $this->fields; } + public function setFields(?array $fields): self { $this->fields = $fields; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php index 21777880fa..42a01aa321 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php @@ -8,23 +8,31 @@ use PandoraFMS\Modules\Shared\Exceptions\InvalidFilterException; abstract class SerializableAbstract implements JsonSerializable { + + public function __construct() { } + abstract public function fieldsReadOnly(): array; + abstract public function jsonSerialize(): mixed; + abstract public function getValidations(): array; + abstract public function validateFields(array $filters): array; + public function toArray() { return $this->jsonSerialize(); } + public function validate(array $params): array { $filters = []; @@ -40,6 +48,7 @@ abstract class SerializableAbstract implements JsonSerializable return $this->validateFields($filters); } + public function fromArray(array $params): static { $fails = $this->validate($params); @@ -63,4 +72,6 @@ abstract class SerializableAbstract implements JsonSerializable return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php b/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php index d55aee91cc..dd57b05b50 100644 --- a/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php +++ b/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php @@ -6,13 +6,20 @@ use JsonSerializable; class PaginationData implements JsonSerializable { + private ?int $totalPages = null; + private ?int $sizePage = null; + private ?int $currentPage = null; + private ?int $totalRegisters = null; + private ?int $totalRegistersPage = null; + private ?array $data = null; + public function __construct( $currentPage, $sizePage, @@ -29,11 +36,13 @@ class PaginationData implements JsonSerializable $this->setData($data); } + public function toArray() { return $this->jsonSerialize(); } + public function jsonSerialize(): mixed { return [ @@ -44,15 +53,17 @@ class PaginationData implements JsonSerializable 'totalRegisters' => $this->getTotalRegisters(), 'totalRegistersPage' => $this->getTotalRegistersPage(), ], - 'data' => $this->getData(), + 'data' => $this->getData(), ]; } + public function getTotalPages(): ?int { return $this->totalPages; } + public function setTotalPages(?int $totalPages): self { $this->totalPages = $totalPages; @@ -60,11 +71,13 @@ class PaginationData implements JsonSerializable return $this; } + public function getSizePage(): ?int { return $this->sizePage; } + public function setSizePage(?int $sizePage): self { $this->sizePage = $sizePage; @@ -72,11 +85,13 @@ class PaginationData implements JsonSerializable return $this; } + public function getCurrentPage(): ?int { return $this->currentPage; } + public function setCurrentPage(?int $currentPage): self { $this->currentPage = $currentPage; @@ -84,11 +99,13 @@ class PaginationData implements JsonSerializable return $this; } + public function getTotalRegisters(): ?int { return $this->totalRegisters; } + public function setTotalRegisters(?int $totalRegisters): self { $this->totalRegisters = $totalRegisters; @@ -96,11 +113,13 @@ class PaginationData implements JsonSerializable return $this; } + public function getTotalRegistersPage(): ?int { return $this->totalRegistersPage; } + public function setTotalRegistersPage(?int $totalRegistersPage): self { $this->totalRegistersPage = $totalRegistersPage; @@ -108,15 +127,19 @@ class PaginationData implements JsonSerializable return $this; } + public function getData(): ?array { return $this->data; } + public function setData(?array $data): self { $this->data = $data; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php b/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php index acd2ec8a45..ac7dc58231 100644 --- a/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php +++ b/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php @@ -4,67 +4,89 @@ namespace PandoraFMS\Modules\Shared\Enums; enum HttpCodesEnum: int { - public const CONTINUE = 100; - public const SWITCHING_PROTOCOLS = 101; - public const PROCESSING = 102; // RFC2518 - public const EARLY_HINTS = 103; // RFC8297 - public const OK = 200; - public const CREATED = 201; - public const ACCEPTED = 202; - public const NON_AUTHORITATIVE_INFORMATION = 203; - public const NO_CONTENT = 204; - public const RESET_CONTENT = 205; - public const PARTIAL_CONTENT = 206; - public const MULTI_STATUS = 207; // RFC4918 - public const ALREADY_REPORTED = 208; // RFC5842 - public const IM_USED = 226; // RFC3229 - public const MULTIPLE_CHOICES = 300; - public const MOVED_PERMANENTLY = 301; - public const FOUND = 302; - public const SEE_OTHER = 303; - public const NOT_MODIFIED = 304; - public const USE_PROXY = 305; - public const RESERVED = 306; - public const TEMPORARY_REDIRECT = 307; - public const PERMANENTLY_REDIRECT = 308; // RFC7238 - public const BAD_REQUEST = 400; - public const UNAUTHORIZED = 401; - public const PAYMENT_REQUIRED = 402; - public const FORBIDDEN = 403; - public const NOT_FOUND = 404; - public const METHOD_NOT_ALLOWED = 405; - public const NOT_ACCEPTABLE = 406; - public const PROXY_AUTHENTICATION_REQUIRED = 407; - public const REQUEST_TIMEOUT = 408; - public const CONFLICT = 409; - public const GONE = 410; - public const LENGTH_REQUIRED = 411; - public const PRECONDITION_FAILED = 412; - public const REQUEST_ENTITY_TOO_LARGE = 413; - public const REQUEST_URI_TOO_LONG = 414; - public const UNSUPPORTED_MEDIA_TYPE = 415; - public const REQUESTED_RANGE_NOT_SATISFIABLE = 416; - public const EXPECTATION_FAILED = 417; - public const I_AM_A_TEAPOT = 418; // RFC2324 - public const MISDIRECTED_REQUEST = 421; // RFC7540 - public const UNPROCESSABLE_ENTITY = 422; // RFC4918 - public const LOCKED = 423; // RFC4918 - public const FAILED_DEPENDENCY = 424; // RFC4918 - public const TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 - public const UPGRADE_REQUIRED = 426; // RFC2817 - public const PRECONDITION_REQUIRED = 428; // RFC6585 - public const TOO_MANY_REQUESTS = 429; // RFC6585 - public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 - public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; // RFC7725 - public const INTERNAL_SERVER_ERROR = 500; - public const NOT_IMPLEMENTED = 501; - public const BAD_GATEWAY = 502; - public const SERVICE_UNAVAILABLE = 503; - public const GATEWAY_TIMEOUT = 504; - public const VERSION_NOT_SUPPORTED = 505; - public const VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 - public const INSUFFICIENT_STORAGE = 507; // RFC4918 - public const LOOP_DETECTED = 508; // RFC5842 - public const NOT_EXTENDED = 510; // RFC2774 - public const NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 +public const CONTINUE = 100; +public const SWITCHING_PROTOCOLS = 101; +public const PROCESSING = 102; +// RFC2518 +public const EARLY_HINTS = 103; +// RFC8297 +public const OK = 200; +public const CREATED = 201; +public const ACCEPTED = 202; +public const NON_AUTHORITATIVE_INFORMATION = 203; +public const NO_CONTENT = 204; +public const RESET_CONTENT = 205; +public const PARTIAL_CONTENT = 206; +public const MULTI_STATUS = 207; +// RFC4918 +public const ALREADY_REPORTED = 208; +// RFC5842 +public const IM_USED = 226; +// RFC3229 +public const MULTIPLE_CHOICES = 300; +public const MOVED_PERMANENTLY = 301; +public const FOUND = 302; +public const SEE_OTHER = 303; +public const NOT_MODIFIED = 304; +public const USE_PROXY = 305; +public const RESERVED = 306; +public const TEMPORARY_REDIRECT = 307; +public const PERMANENTLY_REDIRECT = 308; +// RFC7238 +public const BAD_REQUEST = 400; +public const UNAUTHORIZED = 401; +public const PAYMENT_REQUIRED = 402; +public const FORBIDDEN = 403; +public const NOT_FOUND = 404; +public const METHOD_NOT_ALLOWED = 405; +public const NOT_ACCEPTABLE = 406; +public const PROXY_AUTHENTICATION_REQUIRED = 407; +public const REQUEST_TIMEOUT = 408; +public const CONFLICT = 409; +public const GONE = 410; +public const LENGTH_REQUIRED = 411; +public const PRECONDITION_FAILED = 412; +public const REQUEST_ENTITY_TOO_LARGE = 413; +public const REQUEST_URI_TOO_LONG = 414; +public const UNSUPPORTED_MEDIA_TYPE = 415; +public const REQUESTED_RANGE_NOT_SATISFIABLE = 416; +public const EXPECTATION_FAILED = 417; +public const I_AM_A_TEAPOT = 418; +// RFC2324 +public const MISDIRECTED_REQUEST = 421; +// RFC7540 +public const UNPROCESSABLE_ENTITY = 422; +// RFC4918 +public const LOCKED = 423; +// RFC4918 +public const FAILED_DEPENDENCY = 424; +// RFC4918 +public const TOO_EARLY = 425; +// RFC-ietf-httpbis-replay-04 +public const UPGRADE_REQUIRED = 426; +// RFC2817 +public const PRECONDITION_REQUIRED = 428; +// RFC6585 +public const TOO_MANY_REQUESTS = 429; +// RFC6585 +public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; +// RFC6585 +public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; +// RFC7725 +public const INTERNAL_SERVER_ERROR = 500; +public const NOT_IMPLEMENTED = 501; +public const BAD_GATEWAY = 502; +public const SERVICE_UNAVAILABLE = 503; +public const GATEWAY_TIMEOUT = 504; +public const VERSION_NOT_SUPPORTED = 505; +public const VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; +// RFC2295 +public const INSUFFICIENT_STORAGE = 507; +// RFC4918 +public const LOOP_DETECTED = 508; +// RFC5842 +public const NOT_EXTENDED = 510; +// RFC2774 +public const NETWORK_AUTHENTICATION_REQUIRED = 511; +// RFC6585 } diff --git a/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php b/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php index b5919a9fb4..5f33df8115 100644 --- a/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php +++ b/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php @@ -8,12 +8,12 @@ enum LanguagesEnum: string { use EnumTrait; - case CATALONIAN = 'ca'; - case ENGLISH = 'en_GB'; - case SPANISH = 'es'; - case FRENCH = 'fr'; - case JAPANESE = 'ja'; - case RUSSIAN = 'ru'; - case CHINESE = 'zh_CN'; +case CATALONIAN = 'ca'; +case ENGLISH = 'en_GB'; +case SPANISH = 'es'; +case FRENCH = 'fr'; +case JAPANESE = 'ja'; +case RUSSIAN = 'ru'; +case CHINESE = 'zh_CN'; -} + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php index e9e9e9c4f7..fe4e2f4692 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php @@ -7,8 +7,12 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class BadRequestException extends Exception { + + public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::BAD_REQUEST); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php index b08d274483..a7f18e0b33 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php @@ -7,8 +7,12 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class ForbiddenACLException extends Exception { + + public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::FORBIDDEN); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php index b561f6e7a2..f25e4c1ace 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php @@ -6,8 +6,12 @@ use Exception; class ForbiddenActionException extends Exception { + + public function __construct(string $fails, int $httpCodesEnum) { parent::__construct($fails, $httpCodesEnum); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php index 8a2f0ecacb..f7d5683519 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php @@ -7,8 +7,12 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class InvalidClassException extends Exception { + + public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::NOT_IMPLEMENTED); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php index 6f0e4ce76d..4da4ab06c3 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php @@ -7,6 +7,8 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class InvalidFilterException extends Exception { + + public function __construct(array $fails) { $str = ''; @@ -16,4 +18,6 @@ class InvalidFilterException extends Exception parent::__construct(__($str), HttpCodesEnum::BAD_REQUEST); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php index 054090cd5f..2ac602fa9e 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php @@ -7,8 +7,12 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class NotFoundException extends Exception { + + public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::NOT_FOUND); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Middlewares/AclListMiddleware.php b/pandora_console/include/lib/Modules/Shared/Middlewares/AclListMiddleware.php index eb46df29cb..60b9399c0a 100644 --- a/pandora_console/include/lib/Modules/Shared/Middlewares/AclListMiddleware.php +++ b/pandora_console/include/lib/Modules/Shared/Middlewares/AclListMiddleware.php @@ -7,16 +7,19 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class AclListMiddleware { + + public function __construct( private readonly Config $config ) { } + public function check(string $ipOrigin): bool { $result = true; try { - require_once $this->config->get('homedir').'/include/functions_api.php'; + include_once $this->config->get('homedir').'/include/functions_api.php'; if ((bool) \isInACL($ipOrigin) === false) { $result = false; } @@ -26,4 +29,6 @@ final class AclListMiddleware return $result; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php b/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php index 111bec0484..93d091e154 100644 --- a/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php +++ b/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php @@ -11,61 +11,80 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; abstract class Repository { + + abstract protected function dbGetRow( string $field, string $table, mixed $value ): array; + abstract protected function dbGetValue( string $field, string $table, array $filters, - string $whereJoin = 'AND' + string $whereJoin='AND' ): mixed; + abstract protected function dbGetValueSql( string $sql, - ?bool $cache = false + ?bool $cache=false ): string; + abstract protected function dbGetRowSql( string $sql ): array; + abstract protected function dbGetAllRowsSql( string $sql, - ?bool $cache = false + ?bool $cache=false ): array; + abstract protected function dbInsert(string $table, array $values): mixed; + abstract protected function dbUpdate(string $table, array $values, array $condition): mixed; + abstract protected function dbDelete(string $table, array $where): mixed; - abstract protected function dbFormatWhereClauseSQL(array $values, $prefix = ''): string; + + abstract protected function dbFormatWhereClauseSQL(array $values, $prefix=''): string; + abstract public function buildQueryFilters(FilterAbstract $filter, DataMapperAbstract $mapper): string; + abstract public function buildQueryPagination(FilterAbstract $filter): string; + abstract public function buildQueryOrderBy(FilterAbstract $filter): string; - abstract public function checkAclGroupMysql(string $field, ?string $mode = ''): string; + + abstract public function checkAclGroupMysql(string $field, ?string $mode=''): string; + abstract public function buildQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count = false + bool $count=false ): string; + abstract public function maxFieldSql(string $field): string; + abstract public function safeInput(?string $value): ?string; + abstract public function safeOutput(?string $value): ?string; + /** * @return object[], */ @@ -94,6 +113,7 @@ abstract class Repository return $result; } + public function __rows(FilterAbstract $filter, DataMapperAbstract $mapper): array { try { @@ -110,6 +130,7 @@ abstract class Repository return $rows; } + public function __count(FilterAbstract $filter, DataMapperAbstract $mapper): int { $sql = $this->buildQuery($filter, $mapper, true); @@ -126,6 +147,7 @@ abstract class Repository return (int) $count; } + public function __getOne(FilterAbstract $filter, DataMapperAbstract $mapper): object { try { @@ -146,6 +168,7 @@ abstract class Repository return $mapper->fromDatabase($result); } + public function __create(Entity $entity, DataMapperAbstract $mapper): int { try { @@ -175,6 +198,7 @@ abstract class Repository return $id; } + public function __update(Entity $entity, DataMapperAbstract $mapper, mixed $id): object { $values = $mapper->toDatabase($entity); @@ -196,11 +220,12 @@ abstract class Repository return $entity; } + public function __delete( mixed $id, DataMapperAbstract $mapper, - ?string $key = null, - ?array $where = null + ?string $key=null, + ?array $where=null ): void { try { if (empty($key) === true) { @@ -233,6 +258,7 @@ abstract class Repository } } + public function __getValue(FilterAbstract $filter, DataMapperAbstract $mapper): mixed { try { @@ -249,8 +275,11 @@ abstract class Repository return $result; } + public function __maxField(string $field): string { return $this->maxFieldSql($field); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Audit.php b/pandora_console/include/lib/Modules/Shared/Services/Audit.php index b2ff3c5cec..1eee66ec2f 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Audit.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Audit.php @@ -4,15 +4,18 @@ namespace PandoraFMS\Modules\Shared\Services; class Audit { + + public function __construct( private Config $config, ) { } + public function write( string $action, - string $message = '', - string $extra = '' + string $message='', + string $extra='' ): void { $idUser ??= $this->config->get('id_user'); $remoteAddr ??= $this->config->get('REMOTE_ADDR'); @@ -24,4 +27,6 @@ class Audit $extra ); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Config.php b/pandora_console/include/lib/Modules/Shared/Services/Config.php index 2c4616d344..cdbe9a3c52 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Config.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Config.php @@ -4,12 +4,15 @@ namespace PandoraFMS\Modules\Shared\Services; final class Config { - public function get(string $key, mixed $default = null): mixed + + + public function get(string $key, mixed $default=null): mixed { global $config; return ($config[$key] ?? $default); } + public function set(string $key, mixed $value): bool { global $config; @@ -21,4 +24,6 @@ final class Config return $res; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/FileService.php b/pandora_console/include/lib/Modules/Shared/Services/FileService.php index b57a834ee7..2f1c1b2860 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/FileService.php +++ b/pandora_console/include/lib/Modules/Shared/Services/FileService.php @@ -10,15 +10,18 @@ use Psr\Http\Message\UploadedFileInterface; class FileService { + + public function __construct( private Config $config, ) { } + public function moveUploadedFile( UploadedFileInterface $uploadedFile, - ?string $filename = null, - ?string $subdirectory = '' + ?string $filename=null, + ?string $subdirectory='' ) { $directory = $this->config->get('attachment_directory'); $extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION); @@ -47,6 +50,7 @@ class FileService return $filename; } + public function removeFile(string $filename) { $directory = $this->config->get('attachment_directory'); @@ -58,10 +62,11 @@ class FileService } } + public function validationFile( UploadedFileInterface $file, - string $regexInvalidExtension = null, - int $maxSize = null + string $regexInvalidExtension=null, + int $maxSize=null ): void { if (empty($regexInvalidExtension) === true) { $regexInvalidExtension = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| @@ -84,6 +89,7 @@ class FileService } } + private function calculateSizeBytes(int $maxSize) { $max = ini_get('upload_max_filesize'); @@ -93,4 +99,6 @@ class FileService return ($maxSize * 1000000); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Management.php b/pandora_console/include/lib/Modules/Shared/Services/Management.php index 277162e361..f7527b07cf 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Management.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Management.php @@ -6,10 +6,13 @@ use PandoraFMS\Modules\Shared\Exceptions\ForbiddenACLException; class Management { - public function __construct( - ) { + + + public function __construct() + { } + public function isManagementAllowed(string $class): void { // TODO: change service. @@ -29,4 +32,6 @@ class Management ); } } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php b/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php index ad00509763..445f4550c6 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php @@ -4,14 +4,17 @@ namespace PandoraFMS\Modules\Shared\Services; class Timestamp { + + public function __construct( private Config $config ) { } + public function getMysqlCurrentTimestamp( int $unixtime, - ?string $format = 'Y-m-d H:i:s', + ?string $format='Y-m-d H:i:s', ): string { if ($unixtime == 0) { $unixtime = time(); @@ -24,9 +27,12 @@ class Timestamp return date($format, $unixtime); } + public function getMysqlSystemUtimestamp(): int { $return = \mysql_get_system_time(); return $return; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php b/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php index b5229bb09f..0777878ef2 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php +++ b/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php @@ -8,6 +8,8 @@ use PandoraFMS\Modules\Users\UserProfiles\Actions\GetUserProfileAction; class ValidateAclSystem { + + public function __construct( private Config $config, private Audit $audit, @@ -15,10 +17,11 @@ class ValidateAclSystem ) { } + public function validate( int $idGroup, string|array $permissions, - string $message = '', + string $message='', ): void { // ACL. $idUser ??= $this->config->get('id_user'); @@ -46,10 +49,11 @@ class ValidateAclSystem } } + public function validateUserGroups( int|array|null $idGroup, string $permissions, - string $message = '', + string $message='', ): void { $idUser ??= $this->config->get('id_user'); @@ -81,6 +85,7 @@ class ValidateAclSystem } } + public function validateUserAdmin(): void { if ((bool) \users_is_admin() === false) { @@ -88,7 +93,8 @@ class ValidateAclSystem } } - public function validateUserCanManageAll($acl = 'PM'): void + + public function validateUserCanManageAll($acl='PM'): void { if ((bool) \users_is_admin() === false && (bool) \users_can_manage_group_all($acl) === false @@ -99,6 +105,7 @@ class ValidateAclSystem } } + public function validateUserProfile( int $idProfile ): void { @@ -106,6 +113,7 @@ class ValidateAclSystem $this->getUserProfileAction->__invoke($idUser, $idProfile); } + public function validateAclToken( Token $token ) { @@ -124,4 +132,6 @@ class ValidateAclSystem throw new ForbiddenACLException(__('ACL Forbidden only user administrator edit token other users')); } } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php index c4a6c87eb6..7ec56339df 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php @@ -4,9 +4,11 @@ namespace PandoraFMS\Modules\Shared\Traits; trait EnumTrait { + + public static function get( mixed $value, - string $type = 'name' + string $type='name' ): mixed { $cases = static::cases(); $index = array_search($value, array_column($cases, $type)); @@ -16,4 +18,6 @@ trait EnumTrait return null; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php index 90e8f57356..9ca73860b5 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php @@ -4,17 +4,22 @@ namespace PandoraFMS\Modules\Shared\Traits; trait GroupByFilterTrait { + private ?array $groupByFields = null; + public function getGroupByFields(): ?array { return $this->groupByFields; } + public function setGroupByFields(?array $groupByFields): self { $this->groupByFields = $groupByFields; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php index 7a0f040b34..19c3147f7c 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php @@ -4,14 +4,18 @@ namespace PandoraFMS\Modules\Shared\Traits; trait OrderFilterTrait { + private ?string $sortField = null; + private ?string $sortDirection = null; + public function getSortField(): ?string { return $this->sortField; } + public function setSortField(?string $sortField): self { $this->sortField = $sortField; @@ -19,15 +23,19 @@ trait OrderFilterTrait return $this; } + public function getSortDirection(): ?string { return $this->sortDirection; } + public function setSortDirection(?string $sortDirection): self { $this->sortDirection = $sortDirection; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php index 078f31fe8e..f58bacf77e 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php @@ -4,14 +4,18 @@ namespace PandoraFMS\Modules\Shared\Traits; trait PaginationFilterTrait { + private ?int $sizePage = null; + private ?int $page = null; + public function getSizePage(): ?int { return $this->sizePage; } + public function setSizePage(?int $sizePage): self { $this->sizePage = $sizePage; @@ -19,15 +23,19 @@ trait PaginationFilterTrait return $this; } + public function getPage(): ?int { return $this->page; } + public function setPage(?int $page): self { $this->page = $page; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php b/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php index 347394dcd3..92e4c239a0 100644 --- a/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php +++ b/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php @@ -4,6 +4,8 @@ namespace PandoraFMS\Modules\Shared\Utils; final class ArrayTools { + + public function extractFromObjectByAttribute(string $attribute, array $list): array { return array_reduce( @@ -16,6 +18,7 @@ final class ArrayTools ); } + public function indexObjectByAttribute(string $attribute, array $list): array { return array_reduce( @@ -27,4 +30,6 @@ final class ArrayTools [] ); } + + } diff --git a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php index 5600342275..0e024db840 100644 --- a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php +++ b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php @@ -19,10 +19,12 @@ class Validator public const LANGUAGE = 'Language'; public const MAIL = 'Mail'; + public function __construct() { } + public function validate(array $args): array { $failed = []; @@ -48,6 +50,7 @@ class Validator return $failed; } + private function buildError(string $type, string $field, $value): ?array { if ($this->{'is'.$type}($value) !== true) { @@ -60,57 +63,68 @@ class Validator return null; } + public function isInteger($arg): bool { return is_numeric($arg); } + public function isGreaterThan($arg): bool { return $arg > 0; } + public function isGreaterEqualThan($arg): bool { return $arg >= 0; } + public function isBool($arg): bool { return is_bool($arg); } + public function isString($arg): bool { return is_string($arg) || is_numeric($arg); } + public function isArray($arg): bool { return is_array($arg); } + public function isDate($date) { return $this->isDateTime($date, 'Y-m-d'); } + public function isTime($date) { return $this->isDateTime($date, 'H:i:s'); } - public function isDateTime($date, $format = 'Y-m-d H:i:s') + + public function isDateTime($date, $format='Y-m-d H:i:s') { $d = \DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; } + public function isTimeZone(string $timeZone): string { return array_search($timeZone, timezone_identifiers_list()); } + protected function isLanguage(string $language): bool { $result = LanguagesEnum::get(strtoupper($language)); @@ -118,8 +132,11 @@ class Validator return empty($result) === true ? false : true; } + protected function isMail(string $mail): bool { return filter_var($mail, FILTER_VALIDATE_EMAIL); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Actions/CreateTagAction.php b/pandora_console/include/lib/Modules/Tags/Actions/CreateTagAction.php index da61340873..88cd2ff4ae 100644 --- a/pandora_console/include/lib/Modules/Tags/Actions/CreateTagAction.php +++ b/pandora_console/include/lib/Modules/Tags/Actions/CreateTagAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Services\CreateTagService; final class CreateTagAction { + + public function __construct( private CreateTagService $createTagService ) { } + public function __invoke(Tag $tag): Tag { return $this->createTagService->__invoke($tag); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Actions/DeleteTagAction.php b/pandora_console/include/lib/Modules/Tags/Actions/DeleteTagAction.php index 282f18b1a2..ba1e4727f9 100644 --- a/pandora_console/include/lib/Modules/Tags/Actions/DeleteTagAction.php +++ b/pandora_console/include/lib/Modules/Tags/Actions/DeleteTagAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Services\DeleteTagService; final class DeleteTagAction { + + public function __construct( private DeleteTagService $deleteTagService ) { } + public function __invoke(Tag $tag): void { $this->deleteTagService->__invoke($tag); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Actions/GetTagAction.php b/pandora_console/include/lib/Modules/Tags/Actions/GetTagAction.php index 514c296229..a3acd74081 100644 --- a/pandora_console/include/lib/Modules/Tags/Actions/GetTagAction.php +++ b/pandora_console/include/lib/Modules/Tags/Actions/GetTagAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Services\GetTagService; final class GetTagAction { + + public function __construct( private GetTagService $getTagService ) { } + public function __invoke(int $idTag): Tag { return $this->getTagService->__invoke($idTag); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Actions/ListTagAction.php b/pandora_console/include/lib/Modules/Tags/Actions/ListTagAction.php index efed126c6a..5aa2e9c79f 100644 --- a/pandora_console/include/lib/Modules/Tags/Actions/ListTagAction.php +++ b/pandora_console/include/lib/Modules/Tags/Actions/ListTagAction.php @@ -10,12 +10,15 @@ use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListTagAction { + + public function __construct( private ListTagService $listTagService, private CountTagService $countTagService ) { } + public function __invoke(TagFilter $tagFilter): array { return (new PaginationData( @@ -25,4 +28,6 @@ final class ListTagAction $this->listTagService->__invoke($tagFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Actions/UpdateTagAction.php b/pandora_console/include/lib/Modules/Tags/Actions/UpdateTagAction.php index 62fa12bc12..21b175a0d6 100644 --- a/pandora_console/include/lib/Modules/Tags/Actions/UpdateTagAction.php +++ b/pandora_console/include/lib/Modules/Tags/Actions/UpdateTagAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Services\UpdateTagService; final class UpdateTagAction { + + public function __construct( private UpdateTagService $updateTagService ) { } + public function __invoke(Tag $tag, Tag $oldTag): Tag { return $this->updateTagService->__invoke($tag, $oldTag); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php index dda6499fe6..d031430279 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateTagController extends Controller { + + public function __construct( private CreateTagAction $createTagAction, private ValidateAclSystem $acl, @@ -20,19 +22,20 @@ final class CreateTagController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Tags"}, * path="/tag", * summary="Creates a new tags", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyTag"), - * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyTag"), + * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -48,4 +51,6 @@ final class CreateTagController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php index e77b229e6e..17a4390479 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteTagController extends Controller { + + public function __construct( private DeleteTagAction $deleteTagAction, private ValidateAclSystem $acl, @@ -21,19 +23,20 @@ final class DeleteTagController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Tags"}, * path="/tag/{idTag}", * summary="Deletes an tag object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdTag"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdTag"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -48,4 +51,6 @@ final class DeleteTagController extends Controller $result = $this->deleteTagAction->__invoke($tag); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/GetTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/GetTagController.php index e3d736b40b..dce0da4332 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/GetTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/GetTagController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetTagController extends Controller { + + public function __construct( private GetTagAction $getTagAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/tag/{idTag}", * tags={"Tags"}, * summary="Show tag", - * @OA\Parameter(ref="#/components/parameters/parameterIdTag"), - * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdTag"), + * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -41,4 +44,6 @@ final class GetTagController extends Controller $result = $this->getTagAction->__invoke($idTag); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/ListTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/ListTagController.php index e4dfab7a85..fe4d81f8dc 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/ListTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/ListTagController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListTagController extends Controller { + + public function __construct( private ListTagAction $listTagAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Tags"}, * path="/tag/list", * summary="List tags", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyTagFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyTagFilter"), + * @OA\Response( * response="200", * description="List Incidence object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/Tag", * description="Array of incidences Type objects" * ) @@ -54,11 +57,11 @@ final class ListTagController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -71,4 +74,6 @@ final class ListTagController extends Controller $result = $this->listTagAction->__invoke($tagFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php index 1ae5768848..cd10e867df 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php @@ -19,16 +19,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an tag", * @OA\Parameter(ref="#/components/parameters/parameterIdTag"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyTag"), - * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseTag"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateTagController extends Controller { + + public function __construct( private UpdateTagAction $updateTagAction, private ValidateAclSystem $acl, @@ -37,6 +39,7 @@ final class UpdateTagController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idTag = $this->getParam($request, 'idTag'); @@ -53,4 +56,6 @@ final class UpdateTagController extends Controller $result = $this->updateTagAction->__invoke($tag, $oldTag); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Entities/Tag.php b/pandora_console/include/lib/Modules/Tags/Entities/Tag.php index 943e11d398..e9ca3d4ea5 100644 --- a/pandora_console/include/lib/Modules/Tags/Entities/Tag.php +++ b/pandora_console/include/lib/Modules/Tags/Entities/Tag.php @@ -93,18 +93,27 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class Tag extends Entity { + private ?int $idTag = null; + private ?string $name = null; + private ?string $description = null; + private ?string $url = null; + private ?string $mail = null; + private ?string $phone = null; + private ?string $previousName = null; + public function __construct() { } + public function fieldsReadOnly(): array { return [ @@ -113,6 +122,7 @@ final class Tag extends Entity ]; } + public function jsonSerialize(): mixed { return [ @@ -125,10 +135,11 @@ final class Tag extends Entity ]; } + public function getValidations(): array { return [ - 'idTag' => [ + 'idTag' => [ Validator::INTEGER, Validator::GREATERTHAN, ], @@ -141,78 +152,102 @@ final class Tag extends Entity ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getIdTag(): ?int { return $this->idTag; } + + public function setIdTag(?int $idTag): self { $this->idTag = $idTag; return $this; } + public function getName(): ?string { return $this->name; } + + public function setName(?string $name): self { $this->name = $name; return $this; } + public function getDescription(): ?string { return $this->description; } + + public function setDescription(?string $description): self { $this->description = $description; return $this; } + public function getUrl(): ?string { return $this->url; } + + public function setUrl(?string $url): self { $this->url = $url; return $this; } + public function getMail(): ?string { return $this->mail; } + + public function setMail(?string $mail): self { $this->mail = $mail; return $this; } + public function getPhone(): ?string { return $this->phone; } + + public function setPhone(?string $phone): self { $this->phone = $phone; return $this; } + public function getPreviousName(): ?string { return $this->previousName; } + + public function setPreviousName(?string $previousName): self { $this->previousName = $previousName; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Entities/TagDataMapper.php b/pandora_console/include/lib/Modules/Tags/Entities/TagDataMapper.php index 065d1a9a50..a68a40e80b 100644 --- a/pandora_console/include/lib/Modules/Tags/Entities/TagDataMapper.php +++ b/pandora_console/include/lib/Modules/Tags/Entities/TagDataMapper.php @@ -18,6 +18,7 @@ final class TagDataMapper extends DataMapperAbstract public const PHONE = 'phone'; public const PREVIOUS_NAME = 'previous_name'; + public function __construct( private Repository $repository, private Builder $builder, @@ -28,27 +29,35 @@ final class TagDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return Tag::class; } + public function fromDatabase(array $data): Tag { - return $this->builder->build(new Tag(), [ - 'idTag' => $data[self::ID_TAG], - 'name' => $this->repository->safeOutput($data[self::NAME]), - 'description' => $this->repository->safeOutput($data[self::DESCRIPTION]), - 'url' => $this->repository->safeOutput($data[self::URL]), - 'mail' => $this->repository->safeOutput($data[self::MAIL]), - 'phone' => $this->repository->safeOutput($data[self::PHONE]), - 'previousName' => $this->repository->safeOutput($data[self::PREVIOUS_NAME]), - ]); + return $this->builder->build( + new Tag(), + [ + 'idTag' => $data[self::ID_TAG], + 'name' => $this->repository->safeOutput($data[self::NAME]), + 'description' => $this->repository->safeOutput($data[self::DESCRIPTION]), + 'url' => $this->repository->safeOutput($data[self::URL]), + 'mail' => $this->repository->safeOutput($data[self::MAIL]), + 'phone' => $this->repository->safeOutput($data[self::PHONE]), + 'previousName' => $this->repository->safeOutput($data[self::PREVIOUS_NAME]), + ] + ); } + public function toDatabase(MappeableInterface $data): array { - /** @var Tag $data */ + /* + @var Tag $data + */ return [ self::ID_TAG => $data->getIdTag(), self::NAME => $this->repository->safeInput($data->getName()), @@ -59,4 +68,6 @@ final class TagDataMapper extends DataMapperAbstract self::PREVIOUS_NAME => $this->repository->safeInput($data->getPreviousName()), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Entities/TagFilter.php b/pandora_console/include/lib/Modules/Tags/Entities/TagFilter.php index c5e20b773f..40fd1b609c 100644 --- a/pandora_console/include/lib/Modules/Tags/Entities/TagFilter.php +++ b/pandora_console/include/lib/Modules/Tags/Entities/TagFilter.php @@ -39,8 +39,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class TagFilter extends FilterAbstract { + private ?string $freeSearch = null; + public function __construct() { $this->setDefaultFieldOrder(TagDataMapper::NAME); @@ -48,6 +50,7 @@ final class TagFilter extends FilterAbstract $this->setEntityFilter(new Tag()); } + public function fieldsTranslate(): array { return [ @@ -61,11 +64,13 @@ final class TagFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return ['previousName' => 1]; } + public function jsonSerialize(): mixed { return [ @@ -73,21 +78,25 @@ final class TagFilter extends FilterAbstract ]; } + public function getValidations(): array { $validations = []; - if($this->getEntityFilter() !== null) { + if ($this->getEntityFilter() !== null) { $validations = $this->getEntityFilter()->getValidations(); } + $validations['freeSearch'] = Validator::STRING; return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + /** * Get the value of freeSearch. * @@ -98,11 +107,11 @@ final class TagFilter extends FilterAbstract return $this->freeSearch; } + /** * Set the value of freeSearch. * - * @param ?string $freeSearch - * + * @param string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -110,6 +119,7 @@ final class TagFilter extends FilterAbstract return $this; } + /** * Get the value of fieldsFreeSearch. * @@ -117,7 +127,11 @@ final class TagFilter extends FilterAbstract */ public function getFieldsFreeSearch(): ?array { - return [TagDataMapper::NAME, TagDataMapper::DESCRIPTION]; + return [ + TagDataMapper::NAME, + TagDataMapper::DESCRIPTION, + ]; } + } diff --git a/pandora_console/include/lib/Modules/Tags/Repositories/TagRepository.php b/pandora_console/include/lib/Modules/Tags/Repositories/TagRepository.php index 2f7a420898..a50baf41da 100644 --- a/pandora_console/include/lib/Modules/Tags/Repositories/TagRepository.php +++ b/pandora_console/include/lib/Modules/Tags/Repositories/TagRepository.php @@ -9,15 +9,18 @@ use PandoraFMS\Modules\Shared\Repositories\Repository; class TagRepository { + + public function __construct( private Repository $repository, private TagDataMapper $tagDataMapper ) { } + /** * @return Tag[], - */ + */ public function list(TagFilter $tagFilter): array { return $this->repository->__list( @@ -26,6 +29,7 @@ class TagRepository ); } + public function count(TagFilter $tagFilter): int { return $this->repository->__count( @@ -34,6 +38,7 @@ class TagRepository ); } + public function getOne(TagFilter $tagFilter): Tag { return $this->repository->__getOne( @@ -42,12 +47,14 @@ class TagRepository ); } + public function create(Tag $tag): Tag { $id = $this->repository->__create($tag, $this->tagDataMapper); return $tag->setIdTag($id); } + public function update(Tag $tag): Tag { return $this->repository->__update( @@ -57,9 +64,11 @@ class TagRepository ); } + public function delete(int $id): void { $this->repository->__delete($id, $this->tagDataMapper); } + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/CountTagService.php b/pandora_console/include/lib/Modules/Tags/Services/CountTagService.php index bac59b61c4..ebe8e5cd22 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/CountTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/CountTagService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Repositories\TagRepository; final class CountTagService { + + public function __construct( private TagRepository $tagRepository, ) { } + public function __invoke(TagFilter $tagFilter): int { return $this->tagRepository->count($tagFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/CreateTagService.php b/pandora_console/include/lib/Modules/Tags/Services/CreateTagService.php index 6a67a5e3d9..41b514a83c 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/CreateTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/CreateTagService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class CreateTagService { + + public function __construct( private Audit $audit, private TagRepository $tagRepository, @@ -16,6 +18,7 @@ final class CreateTagService ) { } + public function __invoke(Tag $tag): Tag { $this->tagValidation->__invoke($tag); @@ -30,4 +33,6 @@ final class CreateTagService return $tag; } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/DeleteTagService.php b/pandora_console/include/lib/Modules/Tags/Services/DeleteTagService.php index a60b9d8b88..3d57841813 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/DeleteTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/DeleteTagService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Tags\Repositories\TagRepository; final class DeleteTagService { + + public function __construct( private Audit $audit, private TagRepository $tagRepository, ) { } + public function __invoke(Tag $tag): void { $idTag = $tag->getIdTag(); @@ -32,4 +35,6 @@ final class DeleteTagService 'Deleted tag '.$nameTag ); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/ExistNameTagService.php b/pandora_console/include/lib/Modules/Tags/Services/ExistNameTagService.php index 0ec14844a8..b58daf9d9e 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/ExistNameTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/ExistNameTagService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistNameTagService { + + public function __construct( private TagRepository $tagRepository, ) { } + public function __invoke(string $name): bool { $tagFilter = new TagFilter(); - /** @var Tag $entityFilter */ + /* + @var Tag $entityFilter + */ $entityFilter = $tagFilter->getEntityFilter(); $entityFilter->setName($name); @@ -28,4 +33,6 @@ final class ExistNameTagService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/GetTagService.php b/pandora_console/include/lib/Modules/Tags/Services/GetTagService.php index ef3bf6ed04..aabd65a9c4 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/GetTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/GetTagService.php @@ -8,18 +8,25 @@ use PandoraFMS\Modules\Tags\Repositories\TagRepository; final class GetTagService { + + public function __construct( private TagRepository $tagRepository, ) { } + public function __invoke(int $idTag): Tag { $tagFilter = new TagFilter(); - /** @var Tag $entityFilter */ + /* + @var Tag $entityFilter + */ $entityFilter = $tagFilter->getEntityFilter(); $entityFilter->setIdTag($idTag); return $this->tagRepository->getOne($tagFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/ListTagService.php b/pandora_console/include/lib/Modules/Tags/Services/ListTagService.php index 14daf812a2..2be6d44e81 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/ListTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/ListTagService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Tags\Repositories\TagRepository; final class ListTagService { + + public function __construct( private TagRepository $tagRepository, ) { } + public function __invoke(TagFilter $tagFilter): array { return $this->tagRepository->list($tagFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Services/UpdateTagService.php b/pandora_console/include/lib/Modules/Tags/Services/UpdateTagService.php index 2f3770c948..6fc38715b4 100644 --- a/pandora_console/include/lib/Modules/Tags/Services/UpdateTagService.php +++ b/pandora_console/include/lib/Modules/Tags/Services/UpdateTagService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Shared\Services\Audit; final class UpdateTagService { + + public function __construct( private Audit $audit, private TagRepository $tagRepository, @@ -16,6 +18,7 @@ final class UpdateTagService ) { } + public function __invoke(Tag $tag, Tag $oldTag): Tag { $this->tagValidation->__invoke($tag, $oldTag); @@ -30,4 +33,6 @@ final class UpdateTagService return $tag; } + + } diff --git a/pandora_console/include/lib/Modules/Tags/Validations/TagValidation.php b/pandora_console/include/lib/Modules/Tags/Validations/TagValidation.php index 1bc998a990..9c2059ebd4 100644 --- a/pandora_console/include/lib/Modules/Tags/Validations/TagValidation.php +++ b/pandora_console/include/lib/Modules/Tags/Validations/TagValidation.php @@ -8,27 +8,32 @@ use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; final class TagValidation { + + public function __construct( private ExistNameTagService $existNameTagService ) { } - public function __invoke(Tag $tag, ?Tag $oldTag = null): void + + public function __invoke(Tag $tag, ?Tag $oldTag=null): void { if (!$tag->getName()) { throw new BadRequestException(__('Name is missing')); } - if($oldTag === null || $oldTag->getName() !== $tag->getName()) { - if($this->existNameTagService->__invoke($tag->getName()) === true) { + if ($oldTag === null || $oldTag->getName() !== $tag->getName()) { + if ($this->existNameTagService->__invoke($tag->getName()) === true) { throw new BadRequestException( __('Name %s is already exists', $tag->getName()) ); } } - //if($tag->getIsAgentView() === null) { - // $tag->setIsAgentView(false); - //} + // if($tag->getIsAgentView() === null) { + // $tag->setIsAgentView(false); + // } } + + } diff --git a/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php index 8ddae2852d..cb94c67919 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Services\CreateUserService; final class CreateUserAction { + + public function __construct( private CreateUserService $createUserService ) { } + public function __invoke(User $user): User { return $this->createUserService->__invoke($user); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php index 988955be02..f74118083c 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Services\DeleteUserService; final class DeleteUserAction { + + public function __construct( private DeleteUserService $deleteUserService ) { } + public function __invoke(User $user): void { $this->deleteUserService->__invoke($user); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php index 33e7f5b9d4..eb96a1941d 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Services\GetUserService; final class GetUserAction { + + public function __construct( private GetUserService $getUserService ) { } + public function __invoke(string $idUser): User { return $this->getUserService->__invoke($idUser); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php index ca04e41771..68d5cec9da 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Users\Services\ListUserService; final class ListUserAction { + + public function __construct( private ListUserService $listUserService, private CountUserService $countUserService ) { } + public function __invoke(UserFilter $userFilter): array { return (new PaginationData( @@ -24,4 +27,6 @@ final class ListUserAction $this->listUserService->__invoke($userFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php index c9ff136384..3a1eb9a896 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Services\UpdateUserService; final class UpdateUserAction { + + public function __construct( private UpdateUserService $updateUserService ) { } + public function __invoke(User $user, User $oldUser): User { return $this->updateUserService->__invoke($user, $oldUser); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php index f639b4d455..5508674f0e 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateUserController extends Controller { + + public function __construct( private CreateUserAction $createUserAction, private ValidateAclSystem $acl, @@ -20,19 +22,20 @@ final class CreateUserController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user", * summary="Creates a new users", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -50,4 +53,6 @@ final class CreateUserController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php index cccf79e070..e74813d2cf 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteUserController extends Controller { + + public function __construct( private DeleteUserAction $deleteUserAction, private ValidateAclSystem $acl, @@ -21,19 +23,20 @@ final class DeleteUserController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/{idUser}", * summary="Deletes an user object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -50,4 +53,6 @@ final class DeleteUserController extends Controller $result = $this->deleteUserAction->__invoke($user); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php index 04b830803c..1c6d180666 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php @@ -11,25 +11,28 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetUserController extends Controller { + + public function __construct( private GetUserAction $getUserAction, private ValidateAclSystem $acl ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/user/{idUser}", * tags={"Users"}, * summary="show users", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -42,4 +45,6 @@ final class GetUserController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php index 75f8ca5b4a..f3218e4b7d 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php @@ -12,40 +12,43 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListUserController extends Controller { + + public function __construct( private ListUserAction $listUserAction, private ValidateAclSystem $acl, ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/list", * summary="List user", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserFilter"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserFilter"), + * @OA\Response( * response="200", * description="List Incidence object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/User", * description="Array of user objects" * ) @@ -54,11 +57,11 @@ final class ListUserController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -72,4 +75,6 @@ final class ListUserController extends Controller return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php index d365e882b3..aa784f2f3c 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php @@ -19,16 +19,18 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an user", * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateUserController extends Controller { + + public function __construct( private UpdateUserAction $updateUserAction, private ValidateAclSystem $acl, @@ -37,6 +39,7 @@ final class UpdateUserController extends Controller ) { } + public function __invoke(Request $request, Response $response): Response { $idUser = $this->getParam($request, 'idUser'); @@ -55,4 +58,6 @@ final class UpdateUserController extends Controller $result = $this->updateUserAction->__invoke($user, $oldUser); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Entities/User.php b/pandora_console/include/lib/Modules/Users/Entities/User.php index e3f0b329aa..89a56b837b 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/User.php +++ b/pandora_console/include/lib/Modules/Users/Entities/User.php @@ -475,65 +475,121 @@ use PandoraFMS\Modules\Users\Validators\UserValidator; */ final class User extends Entity { + private ?string $idUser = null; + private ?string $fullName = null; + private ?string $firstName = null; + private ?string $lastName = null; + private ?string $middleName = null; + private ?string $password = null; + private ?string $passwordValidate = null; + private ?string $oldPassword = null; + private ?string $comments = null; + private ?int $lastConnect = null; + private ?int $registered = null; + private ?string $email = null; + private ?string $phone = null; + private ?bool $isAdmin = null; + private ?LanguagesEnum $language = null; + private ?string $timezone = null; + private ?int $blockSize = null; + private ?int $idSkin = null; + private ?bool $disabled = null; + private ?int $shortcut = null; + private ?string $shortcutData = null; + private ?UserHomeScreenEnum $section = null; + private ?string $dataSection = null; + private ?UserHomeScreenEnum $metaconsoleSection = null; + private ?string $metaconsoleDataSection = null; + private ?bool $forceChangePass = null; + private ?string $lastPassChange = null; + private ?string $lastFailedLogin = null; + private ?int $failedAttempt = null; + private ?bool $loginBlocked = null; + private ?UserMetaconsoleAccessEnum $metaconsoleAccess = null; + private ?bool $notLogin = null; + private ?bool $localUser = null; + private ?int $metaconsoleAgentsManager = null; + private ?int $metaconsoleAccessNode = null; + private ?bool $strictAcl = null; + private ?int $idFilter = null; + private ?int $sessionTime = null; + private ?int $defaultEventFilter = null; + private ?int $metaconsoleDefaultEventFilter = null; + private ?bool $showTipsStartup = null; + private ?array $autorefreshWhiteList = null; + private ?int $timeAutorefresh = null; + private ?int $defaultCustomView = null; + private ?string $ehorusUserLevelUser = null; + private ?string $ehorusUserLevelPass = null; + private ?bool $ehorusUserLevelEnabled = null; + private ?string $itsmUserLevelUser = null; + private ?string $itsmUserLevelPass = null; + private ?string $apiToken = null; + private ?bool $allowedIpActive = null; + private ?string $allowedIpList = null; + private ?string $authTokenSecret = null; + private ?string $sessionMaxTimeExpire = null; + public function __construct() { } + public function fieldsReadOnly(): array { return [ @@ -546,6 +602,7 @@ final class User extends Entity ]; } + public function jsonSerialize(): mixed { return [ @@ -601,66 +658,67 @@ final class User extends Entity ]; } + public function getValidations(): array { return [ - 'idUser' => UserValidator::STRING, - 'fullName' => UserValidator::STRING, - 'firstName' => UserValidator::STRING, - 'lastName' => UserValidator::STRING, - 'middleName' => UserValidator::STRING, - 'password' => UserValidator::STRING, - 'passwordValidate' => UserValidator::STRING, - 'oldPassword' => UserValidator::STRING, - 'comments' => UserValidator::STRING, - 'lastConnect' => [ + 'idUser' => UserValidator::STRING, + 'fullName' => UserValidator::STRING, + 'firstName' => UserValidator::STRING, + 'lastName' => UserValidator::STRING, + 'middleName' => UserValidator::STRING, + 'password' => UserValidator::STRING, + 'passwordValidate' => UserValidator::STRING, + 'oldPassword' => UserValidator::STRING, + 'comments' => UserValidator::STRING, + 'lastConnect' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'registered' => [ + 'registered' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'email' => UserValidator::MAIL, - 'phone' => UserValidator::STRING, - 'isAdmin' => UserValidator::BOOLEAN, - 'language' => UserValidator::LANGUAGE, - 'timezone' => UserValidator::TIMEZONE, - 'blockSize' => [ + 'email' => UserValidator::MAIL, + 'phone' => UserValidator::STRING, + 'isAdmin' => UserValidator::BOOLEAN, + 'language' => UserValidator::LANGUAGE, + 'timezone' => UserValidator::TIMEZONE, + 'blockSize' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'idSkin' => [ + 'idSkin' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'disabled' => UserValidator::BOOLEAN, - 'shortcut' => UserValidator::INTEGER, - 'shortcutData' => UserValidator::STRING, - 'section' => UserValidator::VALIDSECTION, - 'dataSection' => UserValidator::STRING, - 'metaconsoleSection' => UserValidator::VALIDSECTION, - 'metaconsoleDataSection' => UserValidator::STRING, - 'forceChangePass' => UserValidator::BOOLEAN, - 'lastPassChange' => UserValidator::DATETIME, - 'lastFailedLogin' => UserValidator::DATETIME, - 'failedAttempt' => [ + 'disabled' => UserValidator::BOOLEAN, + 'shortcut' => UserValidator::INTEGER, + 'shortcutData' => UserValidator::STRING, + 'section' => UserValidator::VALIDSECTION, + 'dataSection' => UserValidator::STRING, + 'metaconsoleSection' => UserValidator::VALIDSECTION, + 'metaconsoleDataSection' => UserValidator::STRING, + 'forceChangePass' => UserValidator::BOOLEAN, + 'lastPassChange' => UserValidator::DATETIME, + 'lastFailedLogin' => UserValidator::DATETIME, + 'failedAttempt' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'loginBlocked' => UserValidator::BOOLEAN, - 'metaconsoleAccess' => UserValidator::VALIDMETACONSOLEACCESS, - 'notLogin' => UserValidator::BOOLEAN, - 'localUser' => UserValidator::BOOLEAN, - 'metaconsoleAgentsManager' => UserValidator::INTEGER, - 'metaconsoleAccessNode' => UserValidator::INTEGER, - 'strictAcl' => UserValidator::BOOLEAN, - 'idFilter' => [ + 'loginBlocked' => UserValidator::BOOLEAN, + 'metaconsoleAccess' => UserValidator::VALIDMETACONSOLEACCESS, + 'notLogin' => UserValidator::BOOLEAN, + 'localUser' => UserValidator::BOOLEAN, + 'metaconsoleAgentsManager' => UserValidator::INTEGER, + 'metaconsoleAccessNode' => UserValidator::INTEGER, + 'strictAcl' => UserValidator::BOOLEAN, + 'idFilter' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'sessionTime' => UserValidator::INTEGER, - 'defaultEventFilter' => [ + 'sessionTime' => UserValidator::INTEGER, + 'defaultEventFilter' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], @@ -668,36 +726,39 @@ final class User extends Entity UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'showTipsStartup' => UserValidator::BOOLEAN, - 'autorefreshWhiteList' => UserValidator::ARRAY, - 'timeAutorefresh' => UserValidator::INTEGER, - 'defaultCustomView' => [ + 'showTipsStartup' => UserValidator::BOOLEAN, + 'autorefreshWhiteList' => UserValidator::ARRAY, + 'timeAutorefresh' => UserValidator::INTEGER, + 'defaultCustomView' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'ehorusUserLevelUser' => UserValidator::STRING, - 'ehorusUserLevelPass' => UserValidator::STRING, - 'ehorusUserLevelEnabled' => UserValidator::BOOLEAN, - 'itsmUserLevelUser' => UserValidator::STRING, - 'itsmUserLevelPass' => UserValidator::STRING, - 'apiToken' => UserValidator::STRING, - 'allowedIpActive' => UserValidator::BOOLEAN, - 'allowedIpList' => UserValidator::STRING, - 'authTokenSecret' => UserValidator::STRING, - 'sessionMaxTimeExpire' => UserValidator::INTEGER, + 'ehorusUserLevelUser' => UserValidator::STRING, + 'ehorusUserLevelPass' => UserValidator::STRING, + 'ehorusUserLevelEnabled' => UserValidator::BOOLEAN, + 'itsmUserLevelUser' => UserValidator::STRING, + 'itsmUserLevelPass' => UserValidator::STRING, + 'apiToken' => UserValidator::STRING, + 'allowedIpActive' => UserValidator::BOOLEAN, + 'allowedIpList' => UserValidator::STRING, + 'authTokenSecret' => UserValidator::STRING, + 'sessionMaxTimeExpire' => UserValidator::INTEGER, ]; } + public function validateFields(array $filters): array { return (new UserValidator())->validate($filters); } + public function getIdUser(): ?string { return $this->idUser; } + public function setIdUser(?string $idUser): self { $this->idUser = $idUser; @@ -705,11 +766,13 @@ final class User extends Entity return $this; } + public function getFullName(): ?string { return $this->fullName; } + public function setFullName(?string $fullName): self { $this->fullName = $fullName; @@ -717,11 +780,13 @@ final class User extends Entity return $this; } + public function getFirstName(): ?string { return $this->firstName; } + public function setFirstName(?string $firstName): self { $this->firstName = $firstName; @@ -729,11 +794,13 @@ final class User extends Entity return $this; } + public function getLastName(): ?string { return $this->lastName; } + public function setLastName(?string $lastName): self { $this->lastName = $lastName; @@ -741,11 +808,13 @@ final class User extends Entity return $this; } + public function getMiddleName(): ?string { return $this->middleName; } + public function setMiddleName(?string $middleName): self { $this->middleName = $middleName; @@ -753,11 +822,13 @@ final class User extends Entity return $this; } + public function getPassword(): ?string { return $this->password; } + public function setPassword(?string $password): self { $this->password = $password; @@ -765,11 +836,13 @@ final class User extends Entity return $this; } + public function getComments(): ?string { return $this->comments; } + public function setComments(?string $comments): self { $this->comments = $comments; @@ -777,11 +850,13 @@ final class User extends Entity return $this; } + public function getLastConnect(): ?int { return $this->lastConnect; } + public function setLastConnect(?int $lastConnect): self { $this->lastConnect = $lastConnect; @@ -789,11 +864,13 @@ final class User extends Entity return $this; } + public function getRegistered(): ?int { return $this->registered; } + public function setRegistered(?int $registered): self { $this->registered = $registered; @@ -801,11 +878,13 @@ final class User extends Entity return $this; } + public function getEmail(): ?string { return $this->email; } + public function setEmail(?string $email): self { $this->email = $email; @@ -813,11 +892,13 @@ final class User extends Entity return $this; } + public function getPhone(): ?string { return $this->phone; } + public function setPhone(?string $phone): self { $this->phone = $phone; @@ -825,11 +906,13 @@ final class User extends Entity return $this; } + public function getIsAdmin(): ?bool { return $this->isAdmin; } + public function setIsAdmin(?bool $isAdmin): self { $this->isAdmin = $isAdmin; @@ -837,11 +920,13 @@ final class User extends Entity return $this; } + public function getLanguage(): ?LanguagesEnum { return $this->language; } + public function setLanguage(null|string|LanguagesEnum $language): self { if (is_string($language) === true) { @@ -853,11 +938,13 @@ final class User extends Entity return $this; } + public function getTimezone(): ?string { return $this->timezone; } + public function setTimezone(?string $timezone): self { $this->timezone = $timezone; @@ -865,11 +952,13 @@ final class User extends Entity return $this; } + public function getBlockSize(): ?int { return $this->blockSize; } + public function setBlockSize(?int $blockSize): self { $this->blockSize = $blockSize; @@ -877,11 +966,13 @@ final class User extends Entity return $this; } + public function getIdSkin(): ?int { return $this->idSkin; } + public function setIdSkin(?int $idSkin): self { $this->idSkin = $idSkin; @@ -889,11 +980,13 @@ final class User extends Entity return $this; } + public function getDisabled(): ?bool { return $this->disabled; } + public function setDisabled(?bool $disabled): self { $this->disabled = $disabled; @@ -901,11 +994,13 @@ final class User extends Entity return $this; } + public function getShortcut(): ?int { return $this->shortcut; } + public function setShortcut(?int $shortcut): self { $this->shortcut = $shortcut; @@ -913,11 +1008,13 @@ final class User extends Entity return $this; } + public function getShortcutData(): ?string { return $this->shortcutData; } + public function setShortcutData(?string $shortcutData): self { $this->shortcutData = $shortcutData; @@ -925,11 +1022,13 @@ final class User extends Entity return $this; } + public function getSection(): ?UserHomeScreenEnum { return $this->section; } + public function setSection(null|string|UserHomeScreenEnum $section): self { if (is_string($section) === true) { @@ -941,11 +1040,13 @@ final class User extends Entity return $this; } + public function getDataSection(): ?string { return $this->dataSection; } + public function setDataSection(?string $dataSection): self { $this->dataSection = $dataSection; @@ -953,11 +1054,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleSection(): ?UserHomeScreenEnum { return $this->metaconsoleSection; } + public function setMetaconsoleSection(null|string|UserHomeScreenEnum $metaconsoleSection): self { if (is_string($metaconsoleSection) === true) { @@ -969,11 +1072,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleDataSection(): ?string { return $this->metaconsoleDataSection; } + public function setMetaconsoleDataSection(?string $metaconsoleDataSection): self { $this->metaconsoleDataSection = $metaconsoleDataSection; @@ -981,11 +1086,13 @@ final class User extends Entity return $this; } + public function getForceChangePass(): ?bool { return $this->forceChangePass; } + public function setForceChangePass(?bool $forceChangePass): self { $this->forceChangePass = $forceChangePass; @@ -993,11 +1100,13 @@ final class User extends Entity return $this; } + public function getLastPassChange(): ?string { return $this->lastPassChange; } + public function setLastPassChange(?string $lastPassChange): self { $this->lastPassChange = $lastPassChange; @@ -1005,11 +1114,13 @@ final class User extends Entity return $this; } + public function getLastFailedLogin(): ?string { return $this->lastFailedLogin; } + public function setLastFailedLogin(?string $lastFailedLogin): self { $this->lastFailedLogin = $lastFailedLogin; @@ -1017,11 +1128,13 @@ final class User extends Entity return $this; } + public function getFailedAttempt(): ?int { return $this->failedAttempt; } + public function setFailedAttempt(?int $failedAttempt): self { $this->failedAttempt = $failedAttempt; @@ -1029,11 +1142,13 @@ final class User extends Entity return $this; } + public function getLoginBlocked(): ?bool { return $this->loginBlocked; } + public function setLoginBlocked(?bool $loginBlocked): self { $this->loginBlocked = $loginBlocked; @@ -1041,11 +1156,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleAccess(): ?UserMetaconsoleAccessEnum { return $this->metaconsoleAccess; } + public function setMetaconsoleAccess(null|string|UserMetaconsoleAccessEnum $metaconsoleAccess): self { if (is_string($metaconsoleAccess) === true) { @@ -1059,11 +1176,13 @@ final class User extends Entity return $this; } + public function getNotLogin(): ?bool { return $this->notLogin; } + public function setNotLogin(?bool $notLogin): self { $this->notLogin = $notLogin; @@ -1071,11 +1190,13 @@ final class User extends Entity return $this; } + public function getLocalUser(): ?bool { return $this->localUser; } + public function setLocalUser(?bool $localUser): self { $this->localUser = $localUser; @@ -1083,11 +1204,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleAgentsManager(): ?int { return $this->metaconsoleAgentsManager; } + public function setMetaconsoleAgentsManager(?int $metaconsoleAgentsManager): self { $this->metaconsoleAgentsManager = $metaconsoleAgentsManager; @@ -1095,11 +1218,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleAccessNode(): ?int { return $this->metaconsoleAccessNode; } + public function setMetaconsoleAccessNode(?int $metaconsoleAccessNode): self { $this->metaconsoleAccessNode = $metaconsoleAccessNode; @@ -1107,11 +1232,13 @@ final class User extends Entity return $this; } + public function getStrictAcl(): ?bool { return $this->strictAcl; } + public function setStrictAcl(?bool $strictAcl): self { $this->strictAcl = $strictAcl; @@ -1119,11 +1246,13 @@ final class User extends Entity return $this; } + public function getIdFilter(): ?int { return $this->idFilter; } + public function setIdFilter(?int $idFilter): self { $this->idFilter = $idFilter; @@ -1131,11 +1260,13 @@ final class User extends Entity return $this; } + public function getSessionTime(): ?int { return $this->sessionTime; } + public function setSessionTime(?int $sessionTime): self { $this->sessionTime = $sessionTime; @@ -1143,11 +1274,13 @@ final class User extends Entity return $this; } + public function getDefaultEventFilter(): ?int { return $this->defaultEventFilter; } + public function setDefaultEventFilter(?int $defaultEventFilter): self { $this->defaultEventFilter = $defaultEventFilter; @@ -1155,11 +1288,13 @@ final class User extends Entity return $this; } + public function getMetaconsoleDefaultEventFilter(): ?int { return $this->metaconsoleDefaultEventFilter; } + public function setMetaconsoleDefaultEventFilter(?int $metaconsoleDefaultEventFilter): self { $this->metaconsoleDefaultEventFilter = $metaconsoleDefaultEventFilter; @@ -1167,11 +1302,13 @@ final class User extends Entity return $this; } + public function getShowTipsStartup(): ?bool { return $this->showTipsStartup; } + public function setShowTipsStartup(?bool $showTipsStartup): self { $this->showTipsStartup = $showTipsStartup; @@ -1179,11 +1316,13 @@ final class User extends Entity return $this; } + public function getAutorefreshWhiteList(): ?array { return $this->autorefreshWhiteList; } + public function setAutorefreshWhiteList(array|string|null $autorefreshWhiteList): self { if (is_string($autorefreshWhiteList) === true) { @@ -1197,11 +1336,13 @@ final class User extends Entity return $this; } + public function getTimeAutorefresh(): ?int { return $this->timeAutorefresh; } + public function setTimeAutorefresh(?int $timeAutorefresh): self { $this->timeAutorefresh = $timeAutorefresh; @@ -1209,11 +1350,13 @@ final class User extends Entity return $this; } + public function getDefaultCustomView(): ?int { return $this->defaultCustomView; } + public function setDefaultCustomView(?int $defaultCustomView): self { $this->defaultCustomView = $defaultCustomView; @@ -1221,11 +1364,13 @@ final class User extends Entity return $this; } + public function getEhorusUserLevelUser(): ?string { return $this->ehorusUserLevelUser; } + public function setEhorusUserLevelUser(?string $ehorusUserLevelUser): self { $this->ehorusUserLevelUser = $ehorusUserLevelUser; @@ -1233,11 +1378,13 @@ final class User extends Entity return $this; } + public function getEhorusUserLevelPass(): ?string { return $this->ehorusUserLevelPass; } + public function setEhorusUserLevelPass(?string $ehorusUserLevelPass): self { $this->ehorusUserLevelPass = $ehorusUserLevelPass; @@ -1245,11 +1392,13 @@ final class User extends Entity return $this; } + public function getEhorusUserLevelEnabled(): ?bool { return $this->ehorusUserLevelEnabled; } + public function setEhorusUserLevelEnabled(?bool $ehorusUserLevelEnabled): self { $this->ehorusUserLevelEnabled = $ehorusUserLevelEnabled; @@ -1257,11 +1406,13 @@ final class User extends Entity return $this; } + public function getItsmUserLevelUser(): ?string { return $this->itsmUserLevelUser; } + public function setItsmUserLevelUser(?string $itsmUserLevelUser): self { $this->itsmUserLevelUser = $itsmUserLevelUser; @@ -1269,11 +1420,13 @@ final class User extends Entity return $this; } + public function getItsmUserLevelPass(): ?string { return $this->itsmUserLevelPass; } + public function setItsmUserLevelPass(?string $itsmUserLevelPass): self { $this->itsmUserLevelPass = $itsmUserLevelPass; @@ -1281,11 +1434,13 @@ final class User extends Entity return $this; } + public function getApiToken(): ?string { return $this->apiToken; } + public function setApiToken(?string $apiToken): self { $this->apiToken = $apiToken; @@ -1293,11 +1448,13 @@ final class User extends Entity return $this; } + public function getAllowedIpActive(): ?bool { return $this->allowedIpActive; } + public function setAllowedIpActive(?bool $allowedIpActive): self { $this->allowedIpActive = $allowedIpActive; @@ -1305,11 +1462,13 @@ final class User extends Entity return $this; } + public function getAllowedIpList(): ?string { return $this->allowedIpList; } + public function setAllowedIpList(?string $allowedIpList): self { $this->allowedIpList = $allowedIpList; @@ -1317,11 +1476,13 @@ final class User extends Entity return $this; } + public function getAuthTokenSecret(): ?string { return $this->authTokenSecret; } + public function setAuthTokenSecret(?string $authTokenSecret): self { $this->authTokenSecret = $authTokenSecret; @@ -1329,11 +1490,13 @@ final class User extends Entity return $this; } + public function getSessionMaxTimeExpire(): ?string { return $this->sessionMaxTimeExpire; } + public function setSessionMaxTimeExpire(?string $sessionMaxTimeExpire): self { $this->sessionMaxTimeExpire = $sessionMaxTimeExpire; @@ -1341,11 +1504,13 @@ final class User extends Entity return $this; } + public function getPasswordValidate(): ?string { return $this->passwordValidate; } + public function setPasswordValidate(?string $passwordValidate): self { $this->passwordValidate = $passwordValidate; @@ -1353,15 +1518,19 @@ final class User extends Entity return $this; } + public function getOldPassword(): ?string { return $this->oldPassword; } + public function setOldPassword(?string $oldPassword): self { $this->oldPassword = $oldPassword; return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php index 2ed1582337..9f00713631 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php +++ b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php @@ -66,6 +66,7 @@ final class UserDataMapper extends DataMapperAbstract public const AUTH_TOKEN_SECRET = 'auth_token_secret'; public const SESSION_MAX_TIME_EXPIRE = 'session_max_time_expire'; + public function __construct( private Repository $repository, private Builder $builder, @@ -76,11 +77,13 @@ final class UserDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return User::class; } + public function fromDatabase(array $data): User { return $this->builder->build( @@ -142,6 +145,7 @@ final class UserDataMapper extends DataMapperAbstract ); } + /** * @param User $data */ @@ -202,4 +206,6 @@ final class UserDataMapper extends DataMapperAbstract self::SESSION_MAX_TIME_EXPIRE => $data->getSessionMaxTimeExpire(), ]; } + + } diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php index 7872a1a27f..b2f707a202 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php @@ -8,18 +8,18 @@ enum UserAutoRefreshPagesEnum: string { use EnumTrait; - case AGENT_DETAIL = 'operation/agentes/estado_agente'; - case ALERT_DETAIL = 'operation/agentes/alerts_status'; - case CLUSTER_VIEW = 'enterprise/operation/cluster/cluster'; - case GIS_MAP = 'operation/gis_maps/render_view'; - case GRAPH_VIEWER = 'operation/reporting/graph_viewer'; - case SNMP_CONSOLE = 'operation/snmpconsole/snmp_view'; - case SAP_VIEW = 'general/sap_view'; - case TACTICAL_VIEW = 'operation/agentes/tactical'; - case GROUP_VIEW = 'operation/agentes/group_view'; - case MONITOR_DETAIL = 'operation/agentes/status_monitor'; - case SERVICES = 'enterprise/operation/services/services'; - case DASHBOARD = 'operation/dashboard/dashboard'; - case VISUAL_CONSOLE = 'operation/visual_console/render_view'; - case EVENTS = 'operation/events/events'; -} +case AGENT_DETAIL = 'operation/agentes/estado_agente'; +case ALERT_DETAIL = 'operation/agentes/alerts_status'; +case CLUSTER_VIEW = 'enterprise/operation/cluster/cluster'; +case GIS_MAP = 'operation/gis_maps/render_view'; +case GRAPH_VIEWER = 'operation/reporting/graph_viewer'; +case SNMP_CONSOLE = 'operation/snmpconsole/snmp_view'; +case SAP_VIEW = 'general/sap_view'; +case TACTICAL_VIEW = 'operation/agentes/tactical'; +case GROUP_VIEW = 'operation/agentes/group_view'; +case MONITOR_DETAIL = 'operation/agentes/status_monitor'; +case SERVICES = 'enterprise/operation/services/services'; +case DASHBOARD = 'operation/dashboard/dashboard'; +case VISUAL_CONSOLE = 'operation/visual_console/render_view'; +case EVENTS = 'operation/events/events'; + } diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php index 9207a2b387..9e1d9886a1 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php @@ -8,13 +8,13 @@ enum UserHomeScreenEnum: string { use EnumTrait; - case DEFAULT = 'default'; - case VISUAL_CONSOLE = 'visual_console'; - case EVENT_LIST = 'event_list'; - case GROUP_VIEW = 'group_view'; - case TACTICAL_VIEW = 'tactical_view'; - case ALERT_DETAIL = 'alert_detail'; - case EXTERNAL_LINK = 'external_link'; - case OTHER = 'other'; - case DASHBOARD = 'dashboard'; -} + case default = 'default'; +case VISUAL_CONSOLE = 'visual_console'; +case EVENT_LIST = 'event_list'; +case GROUP_VIEW = 'group_view'; +case TACTICAL_VIEW = 'tactical_view'; +case ALERT_DETAIL = 'alert_detail'; +case EXTERNAL_LINK = 'external_link'; +case OTHER = 'other'; +case DASHBOARD = 'dashboard'; + } diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php index c261f9c945..26566f9360 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php @@ -8,6 +8,6 @@ enum UserMetaconsoleAccessEnum: string { use EnumTrait; - case BASIC = 'basic'; - case ADVANCED = 'advanced'; -} +case BASIC = 'basic'; +case ADVANCED = 'advanced'; + } diff --git a/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php b/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php index 80e5100e5c..628808b82c 100644 --- a/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php +++ b/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php @@ -7,20 +7,30 @@ use PandoraFMS\Modules\Users\Entities\UserFilter; interface UserRepository { + + /** * @return User[], */ public function list(UserFilter $userFilter): array; + public function count(UserFilter $userFilter): int; + public function getOne(UserFilter $userFilter): User; + public function create(User $user): User; + public function update(User $user): User; + public function delete(string $id): void; + public function getExistUser(string $idUser): User; + + } diff --git a/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php b/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php index 796344c4f7..1978ed94e8 100644 --- a/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php @@ -15,12 +15,15 @@ use PandoraFMS\Modules\Users\Entities\UserFilter; final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository { + + public function __construct( private UserDataMapper $userDataMapper, private Config $config ) { } + /** * @return User[], */ @@ -49,6 +52,7 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor return $result; } + public function count(UserFilter $userFilter): int { $sql = $this->getUsersQuery($userFilter, $this->userDataMapper, true); @@ -65,6 +69,7 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor return (int) $count; } + public function getOne(UserFilter $userFilter): User { try { @@ -85,6 +90,7 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor return $this->userDataMapper->fromDatabase($result); } + public function getExistUser(string $idUser): User { try { @@ -105,12 +111,14 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor return $this->userDataMapper->fromDatabase($result); } + public function create(User $user): User { $this->__create($user, $this->userDataMapper); return $user; } + public function update(User $user): User { return $this->__update( @@ -120,15 +128,17 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor ); } + public function delete(string $id): void { $this->__delete($id, $this->userDataMapper); } + private function getUsersQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count = false + bool $count=false ): string { $pagination = ''; $orderBy = ''; @@ -185,4 +195,6 @@ final class UserRepositoryMySQL extends RepositoryMySQL implements UserRepositor return $sql; } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/CountUserService.php b/pandora_console/include/lib/Modules/Users/Services/CountUserService.php index bdb156e663..b68a376a42 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CountUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CountUserService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class CountUserService { + + public function __construct( private UserRepository $userRepository, ) { } + public function __invoke(UserFilter $userFilter): int { return $this->userRepository->count($userFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php b/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php index d5135ab416..2d14107cdc 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Users\Validations\UserValidation; final class CreateUserService { + + public function __construct( private Audit $audit, private UserRepository $userRepository, @@ -16,6 +18,7 @@ final class CreateUserService ) { } + public function __invoke(User $user): User { $this->userValidation->__invoke($user); @@ -33,4 +36,6 @@ final class CreateUserService return $user; } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php b/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php index 83f190b680..0b41abe84f 100644 --- a/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class DeleteUserService { + + public function __construct( private Audit $audit, private UserRepository $userRepository, ) { } + public function __invoke(User $user): void { $idUser = $user->getIdUser(); @@ -26,4 +29,6 @@ final class DeleteUserService ' Deleted user #'.$idUser ); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/ExistIdUserService.php b/pandora_console/include/lib/Modules/Users/Services/ExistIdUserService.php index 029b40177c..1813096220 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ExistIdUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ExistIdUserService.php @@ -7,11 +7,14 @@ use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; final class ExistIdUserService { + + public function __construct( private UserRepository $UserRepository, ) { } + public function __invoke(string $idUser): bool { try { @@ -21,4 +24,6 @@ final class ExistIdUserService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php index cea233c8fa..97b670dbee 100644 --- a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php @@ -8,19 +8,26 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class GetUserService { + + public function __construct( private UserRepository $userRepository, ) { } + public function __invoke(string $idUser): User { $userFilter = new UserFilter(); - /** @var User $entityFilter */ + /* + @var User $entityFilter + */ $entityFilter = $userFilter->getEntityFilter(); $entityFilter->setIdUser($idUser); return $this->userRepository->getOne($userFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/ListUserService.php b/pandora_console/include/lib/Modules/Users/Services/ListUserService.php index 014a046f28..89e02523b5 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ListUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ListUserService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class ListUserService { + + public function __construct( private UserRepository $userRepository, ) { } + public function __invoke(UserFilter $userFilter): array { return $this->userRepository->list($userFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php b/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php index b1fcae7c51..a4878aca8e 100644 --- a/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php @@ -9,6 +9,8 @@ use PandoraFMS\Modules\Users\Validations\UserValidation; final class UpdateUserService { + + public function __construct( private Audit $audit, private UserRepository $userRepository, @@ -16,6 +18,7 @@ final class UpdateUserService ) { } + public function __invoke(User $user, User $oldUser): User { $this->userValidation->__invoke($user, $oldUser); @@ -35,4 +38,6 @@ final class UpdateUserService return $user; } + + } diff --git a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php index ffdb1367d1..2342621055 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php @@ -8,11 +8,14 @@ use PandoraFMS\Modules\Users\Entities\User; final class ValidatePasswordUserService { + + public function __construct( private Config $config, ) { } + public function __invoke(User $user, ?User $oldUser): void { // Excluyes palabras. @@ -65,6 +68,7 @@ final class ValidatePasswordUserService } } + private function checkExcludePassword(string $newPassword): bool { if ((bool) $this->config->get('enable_pass_policy') === true @@ -83,6 +87,7 @@ final class ValidatePasswordUserService return false; } + private function getOldPasswords(string $idUser): array { // TODO: create new service for this. @@ -103,4 +108,6 @@ final class ValidatePasswordUserService return $oldPasswords; } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php index 60fe948892..fcc4d6b375 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\CreateUserProfileService; final class CreateUserProfileAction { + + public function __construct( private CreateUserProfileService $createUserProfileService ) { } + public function __invoke(UserProfile $userProfile): UserProfile { return $this->createUserProfileService->__invoke($userProfile); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php index e106ed9479..de6f9b0993 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\DeleteUserProfileService; final class DeleteUserProfileAction { + + public function __construct( private DeleteUserProfileService $deleteService ) { } + public function __invoke(UserProfile $userProfile): void { $this->deleteService->__invoke($userProfile); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php index e32623a4f2..699924a69a 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\GetUserProfileService; final class GetUserProfileAction { + + public function __construct( private GetUserProfileService $getUserProfileService ) { } + public function __invoke(string $idUser, int $idProfile): UserProfile { return $this->getUserProfileService->__invoke($idUser, $idProfile); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php index abaf2d7caf..26817afd79 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php @@ -9,12 +9,15 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\ListUserProfileService; final class ListUserProfileAction { + + public function __construct( private ListUserProfileService $listUserProfileService, private CountUserProfileService $countUserProfileService ) { } + public function __invoke(UserProfileFilter $userProfileFilter): array { return (new PaginationData( @@ -24,4 +27,6 @@ final class ListUserProfileAction $this->listUserProfileService->__invoke($userProfileFilter) ))->toArray(); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php index 17dcd6b886..581731b126 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php @@ -15,6 +15,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class CreateUserProfileController extends Controller { + + public function __construct( private CreateUserProfileAction $createUserProfileAction, private ValidateAclSystem $acl, @@ -24,21 +26,22 @@ final class CreateUserProfileController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/{idUser}/profile/{idProfile}", * summary="Create user profile", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -63,4 +66,6 @@ final class CreateUserProfileController extends Controller $result = $this->createUserProfileAction->__invoke($userProfile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php index 3637a72ced..db472af958 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php @@ -15,6 +15,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteUserProfileController extends Controller { + + public function __construct( private DeleteUserProfileAction $deleteUserProfileAction, private ValidateAclSystem $acl, @@ -25,20 +27,21 @@ final class DeleteUserProfileController extends Controller ) { } + /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/{idUser}/profile/{idProfile}", * summary="Deletes user profile.", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -59,4 +62,6 @@ final class DeleteUserProfileController extends Controller $result = $this->deleteUserProfileAction->__invoke($userProfile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php index 81221fd0d5..34a1257103 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetUserProfileController extends Controller { + + public function __construct( private GetUserProfileAction $getUserProfileAction, private GetUserAction $getUserAction, @@ -21,20 +23,21 @@ final class GetUserProfileController extends Controller ) { } + /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/user/{idUser}/profile/{idProfile}", * tags={"Users"}, * summary="show data field user profile", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -50,4 +53,6 @@ final class GetUserProfileController extends Controller $result = $this->getUserProfileAction->__invoke($idUser, $idProfile); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php index bcdc26239d..2301dfbd97 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php @@ -13,6 +13,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class ListUserProfileController extends Controller { + + public function __construct( private ListUserProfileAction $listUserProfileAction, private GetUserAction $getUserAction, @@ -20,35 +22,36 @@ final class ListUserProfileController extends Controller ) { } + /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/{idUser}/profiles", * summary="List user profiles", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), - * @OA\Response( + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), + * @OA\Response( * response="200", * description="List data profiles user object", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="paginationData", * type="object", * ref="#/components/schemas/paginationData", * description="Page object", * ), - * @OA\Property( + * @OA\Property( * property="data", * type="array", - * @OA\Items( + * @OA\Items( * ref="#/components/schemas/UserProfile", * description="Array of profiles" * ) @@ -57,11 +60,11 @@ final class ListUserProfileController extends Controller * ) * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -78,4 +81,6 @@ final class ListUserProfileController extends Controller $result = $this->listUserProfileAction->__invoke($userProfileFilter); return $this->getResponse($response, $result); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php index a370f8c5f3..82a3b1cf32 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php @@ -113,24 +113,35 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class UserProfile extends Entity { + private ?int $idUserProfile = null; + private ?string $idUser = null; + private ?int $idProfile = null; + private ?int $idGroup = null; + private ?bool $isNoHierarchy = null; + private ?string $assignedBy = null; + private ?int $idPolicy = null; + private ?array $tags = null; + public function __construct() { } + public function fieldsReadOnly(): array { return ['idUserProfile' => 1]; } + public function jsonSerialize(): mixed { return [ @@ -145,6 +156,7 @@ final class UserProfile extends Entity ]; } + public function getValidations(): array { return [ @@ -152,12 +164,12 @@ final class UserProfile extends Entity Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'idUser' => Validator::STRING, - 'idProfile' => [ + 'idUser' => Validator::STRING, + 'idProfile' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'idGroup' => [ + 'idGroup' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], @@ -167,19 +179,23 @@ final class UserProfile extends Entity Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'tags' => Validator::ARRAY, + 'tags' => Validator::ARRAY, ]; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + public function getIdUserProfile(): ?int { return $this->idUserProfile; } + + public function setIdUserProfile(?int $idUserProfile): self { $this->idUserProfile = $idUserProfile; @@ -187,10 +203,13 @@ final class UserProfile extends Entity return $this; } + public function getIdUser(): ?string { return $this->idUser; } + + public function setIdUser(?string $idUser): self { $this->idUser = $idUser; @@ -198,10 +217,13 @@ final class UserProfile extends Entity return $this; } + public function getIdProfile(): ?int { return $this->idProfile; } + + public function setIdProfile(?int $idProfile): self { $this->idProfile = $idProfile; @@ -209,10 +231,13 @@ final class UserProfile extends Entity return $this; } + public function getIdGroup(): ?int { return $this->idGroup; } + + public function setIdGroup(?int $idGroup): self { $this->idGroup = $idGroup; @@ -220,10 +245,13 @@ final class UserProfile extends Entity return $this; } + public function getAssignedBy(): ?string { return $this->assignedBy; } + + public function setAssignedBy(?string $assignedBy): self { $this->assignedBy = $assignedBy; @@ -231,30 +259,39 @@ final class UserProfile extends Entity return $this; } + public function getIsNoHierarchy(): ?bool { return $this->isNoHierarchy; } + + public function setIsNoHierarchy(?bool $isNoHierarchy): self { $this->isNoHierarchy = $isNoHierarchy; return $this; } + public function getIdPolicy(): ?int { return $this->idPolicy; } + + public function setIdPolicy(?int $idPolicy): self { $this->idPolicy = $idPolicy; return $this; } + public function getTags(): ?array { return $this->tags; } + + public function setTags(array|string|null $tags): self { if (is_string($tags) === true) { @@ -265,4 +302,6 @@ final class UserProfile extends Entity return $this; } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php index e36293550c..5d97ff2135 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php @@ -19,6 +19,7 @@ final class UserProfileDataMapper extends DataMapperAbstract public const ID_POLICY = 'id_policy'; public const TAGS = 'tags'; + public function __construct( private Repository $repository, private Builder $builder, @@ -29,11 +30,13 @@ final class UserProfileDataMapper extends DataMapperAbstract ); } + public function getClassName(): string { return UserProfile::class; } + public function fromDatabase(array $data): UserProfile { return $this->builder->build( @@ -51,9 +54,12 @@ final class UserProfileDataMapper extends DataMapperAbstract ); } + public function toDatabase(MappeableInterface $data): array { - /** @var UserProfile $data */ + /* + @var UserProfile $data + */ return [ self::ID_USER_PROFILE => $data->getIdUserProfile(), self::ID_USER => $data->getIdUser(), @@ -65,4 +71,6 @@ final class UserProfileDataMapper extends DataMapperAbstract self::TAGS => (empty($data->getTags()) === false) ? implode(',', $data->getTags()) : null, ]; } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php index 487071a183..70a168c2e8 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php @@ -32,6 +32,8 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class UserProfileFilter extends FilterAbstract { + + public function __construct() { $this->setDefaultFieldOrder(UserProfileDataMapper::ID_USER_PROFILE); @@ -39,6 +41,7 @@ final class UserProfileFilter extends FilterAbstract $this->setEntityFilter(new UserProfile()); } + public function fieldsTranslate(): array { return [ @@ -46,16 +49,19 @@ final class UserProfileFilter extends FilterAbstract ]; } + public function fieldsReadOnly(): array { return []; } + public function jsonSerialize(): mixed { return []; } + public function getValidations(): array { $validations = []; @@ -66,8 +72,11 @@ final class UserProfileFilter extends FilterAbstract return $validations; } + public function validateFields(array $filters): array { return (new Validator())->validate($filters); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php index 907abb0390..a7b8793fed 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php @@ -10,13 +10,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileFilter; class UserProfileRepository { + + public function __construct( private Repository $repository, private UserProfileDataMapper $userProfileDataMapper ) { } - /** @return UserProfile[] */ + + /** + * @return UserProfile[] + */ public function list(UserProfileFilter $userProfileFilter): array { return $this->repository->__list( @@ -25,6 +30,7 @@ class UserProfileRepository ); } + public function count(UserProfileFilter $userProfileFilter): int { return $this->repository->__count( @@ -33,6 +39,7 @@ class UserProfileRepository ); } + public function getOne(UserProfileFilter $userProfileFilter): UserProfile { return $this->repository->__getOne( @@ -41,6 +48,7 @@ class UserProfileRepository ); } + public function create(UserProfile $userProfile): UserProfile { try { @@ -51,6 +59,7 @@ class UserProfileRepository } } + public function update(UserProfile $userProfile): UserProfile { return $this->repository->__update( @@ -60,8 +69,11 @@ class UserProfileRepository ); } - public function delete(int $id, ?string $key = null): void + + public function delete(int $id, ?string $key=null): void { $this->repository->__delete($id, $this->userProfileDataMapper, $key); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php index 8786e01ed9..77526e0e9a 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class CountUserProfileService { + + public function __construct( private UserProfileRepository $userProfileRepository, ) { } + public function __invoke(UserProfileFilter $userProfileFilter): int { return $this->userProfileRepository->count($userProfileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php index b120283b4e..956c836924 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php @@ -10,6 +10,8 @@ use PandoraFMS\Modules\Users\UserProfiles\Validations\UserProfileValidation; final class CreateUserProfileService { + + public function __construct( private UserProfileRepository $userProfileRepository, private UserProfileValidation $userProfileValidation, @@ -18,6 +20,7 @@ final class CreateUserProfileService ) { } + public function __invoke(UserProfile $userProfile): UserProfile { $this->userProfileValidation->__invoke($userProfile); @@ -34,4 +37,6 @@ final class CreateUserProfileService return $userProfile; } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php index 1af74c5c70..9129df83d9 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php @@ -10,6 +10,8 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class DeleteUserProfileService { + + public function __construct( private Config $config, private Audit $audit, @@ -18,6 +20,7 @@ final class DeleteUserProfileService ) { } + public function __invoke(UserProfile $userProfile): void { $idUser = $userProfile->getIdUser(); @@ -30,4 +33,6 @@ final class DeleteUserProfileService 'Deleted profile: '.$profile->getName().' for user: '.$idUser ); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php index 175b540540..4f7124668f 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php @@ -9,15 +9,20 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class ExistUserProfileService { + + public function __construct( private UserProfileRepository $userProfileRepository, ) { } + public function __invoke(UserProfile $userProfile): bool { $groupFilter = new UserProfileFilter(); - /** @var UserProfile $entityFilter */ + /* + @var UserProfile $entityFilter + */ $entityFilter = $groupFilter->getEntityFilter(); $entityFilter->setIdUser($userProfile->getIdUser()); $entityFilter->setIdProfile($userProfile->getIdProfile()); @@ -30,4 +35,6 @@ final class ExistUserProfileService return false; } } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php index ff43755db8..e28f5ffbbb 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php @@ -8,19 +8,26 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class GetUserProfileService { + + public function __construct( private UserProfileRepository $userProfileRepository, ) { } + public function __invoke(string $idUser, int $idProfile): UserProfile { $userProfileFilter = new UserProfileFilter(); - /** @var UserProfile $entityFilter */ + /* + @var UserProfile $entityFilter + */ $entityFilter = $userProfileFilter->getEntityFilter(); $entityFilter->setIdUser($idUser); $entityFilter->setIdProfile($idProfile); return $this->userProfileRepository->getOne($userProfileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php index ae57f96df5..dfa928f074 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php @@ -7,13 +7,18 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class ListUserProfileService { + + public function __construct( private UserProfileRepository $userProfileRepository, ) { } + public function __invoke(UserProfileFilter $userProfileFilter): array { return $this->userProfileRepository->list($userProfileFilter); } + + } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php index c003af3339..73b8a689ea 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php @@ -14,6 +14,8 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\ExistUserProfileService; final class UserProfileValidation { + + public function __construct( private GetGroupService $getGroupService, private GetUserService $getUserService, @@ -25,6 +27,7 @@ final class UserProfileValidation ) { } + public function __invoke(UserProfile $userProfile): void { if (!$userProfile->getIdUser()) { @@ -74,21 +77,25 @@ final class UserProfileValidation } } + private function validateUser(string $idUser): void { $this->getUserService->__invoke($idUser); } + private function validateProfile(int $idProfile): void { $this->getProfileService->__invoke($idProfile); } + protected function validateGroup(int $idGroup): void { $this->getGroupService->__invoke($idGroup); } + protected function validatePolicy(int $idPolicy): void { // TODO: create new service for this. @@ -97,10 +104,13 @@ final class UserProfileValidation } } + protected function validateTags(array $tags): void { foreach ($tags as $tag) { $this->getTagService->__invoke((int) $tag); } } + + } diff --git a/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php b/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php index 5fe41e57d9..589b5926b8 100644 --- a/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php +++ b/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php @@ -18,6 +18,8 @@ use PandoraFMS\Modules\Users\Services\ValidatePasswordUserService; final class UserValidation { + + public function __construct( private Config $config, private Timestamp $timestamp, @@ -29,13 +31,14 @@ final class UserValidation ) { } - public function __invoke(User $user, ?User $oldUser = null): void + + public function __invoke(User $user, ?User $oldUser=null): void { $isAdmin = $this->isAdmin($this->config->get('id_user')); $this->validateIdUser($user); if ($oldUser === null || $oldUser->getIdUser() !== $user->getIdUser()) { - if($this->existIdUserService->__invoke($user->getIdUser()) === true) { + if ($this->existIdUserService->__invoke($user->getIdUser()) === true) { throw new BadRequestException( __('Id user %s is already exists', $user->getIdUser()) ); @@ -268,16 +271,19 @@ final class UserValidation } } + private function getCurrentTimestamp(): string { return $this->timestamp->getMysqlCurrentTimestamp(0); } + private function getCurrentUtimestamp(): int { return $this->timestamp->getMysqlSystemUtimestamp(); } + private function existsUser(string $idUser): void { $exist = true; @@ -292,6 +298,7 @@ final class UserValidation } } + private function validateIdUser(User $user): void { if ($user->getIdUser() === false) { @@ -306,18 +313,21 @@ final class UserValidation } } + private function generateApiToken(): string { // TODO: create new service for this. return \api_token_generate(); } + private function isAdmin(string $idUser): bool { // TODO: create new service for this. return \users_is_admin($idUser); } + protected function validateSkin(int $idSkin): void { // TODO: create new service for this. @@ -326,11 +336,13 @@ final class UserValidation } } + protected function validateEventFilter(int $idFilter): void { $this->getEventFilterService->__invoke($idFilter); } + protected function validateCustomView(int $idView): void { // TODO: create new service for this. @@ -339,6 +351,7 @@ final class UserValidation } } + protected function validateDashboard(string $idUser, int $idDashboard): void { // TODO: create new service for this. @@ -347,6 +360,7 @@ final class UserValidation } } + protected function validateVisualConsole(int $visualConsoleId): void { // TODO: create new service for this. @@ -356,4 +370,6 @@ final class UserValidation throw new BadRequestException(__('Invalid visual console id')); } } + + } diff --git a/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php b/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php index 1a7e4cbab3..ecf44f3b31 100644 --- a/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php +++ b/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php @@ -11,15 +11,19 @@ class UserValidator extends Validator public const VALIDSECTION = 'ValidSection'; public const VALIDMETACONSOLEACCESS = 'ValidMetaconsoleAccess'; + protected function isValidSection($section): bool { $result = UserHomeScreenEnum::get(strtoupper($section)); return empty($result) === true ? false : true; } + protected function isValidMetaconsoleAccess($metaconsoleAccess): bool { $result = UserMetaconsoleAccessEnum::get(strtoupper($metaconsoleAccess)); return empty($result) === true ? false : true; } + + } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index d476913545..c1cf6bc423 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -1018,6 +1018,10 @@ select:-internal-list-box { display: flex; } +.align-self-center { + align-self: center; +} + .flex_important { display: flex !important; }