diff --git a/client/package-lock.json b/client/package-lock.json index bc657dc..3c5f5b1 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -431,9 +431,9 @@ "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==" }, "@eslint/eslintrc": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.2.tgz", - "integrity": "sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.3.tgz", + "integrity": "sha512-yZzuIG+jnVu6hNSzFEN07e8BxF3uAzYtQb6uDkaYZLo6oYZDCq454c5kB8zxnzfCYyP4MIuyBn10L0DqwujTmA==", "requires": { "ajv": "^6.12.4", "debug": "^4.3.2", @@ -483,9 +483,9 @@ } }, "@eslint/js": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", - "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==" + "version": "8.53.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.53.0.tgz", + "integrity": "sha512-Kn7K8dx/5U6+cT1yEhpX1w4PCSg0M+XyRILPgvwcEBjerFWCwQj5sbr3/VmxqV0JGHCBCzyd6LxypEuehypY1w==" }, "@firebase/analytics": { "version": "0.7.8", @@ -1153,34 +1153,34 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==" }, "@types/bootstrap": { - "version": "5.2.8", - "resolved": "https://registry.npmjs.org/@types/bootstrap/-/bootstrap-5.2.8.tgz", - "integrity": "sha512-14do+aWZPc1w3G+YevSsy8eas1XEPhTOUNBhQX/r12YKn7ySssATJusBQ/HCQAd2nq54U8vvrftHSb1YpeJUXg==", + "version": "5.2.9", + "resolved": "https://registry.npmjs.org/@types/bootstrap/-/bootstrap-5.2.9.tgz", + "integrity": "sha512-Fcg4nORBKaVUAG4F0ePWcatWQVfr3NAT9XIN+hl1PaiAwb4tq55+iua9R3exsbB3yyfhyQlHYg2foTlW86J+RA==", "requires": { "@popperjs/core": "^2.9.2" } }, "@types/cheerio": { - "version": "0.22.33", - "resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.33.tgz", - "integrity": "sha512-XUlu2BK4q3xJsccRLK69m/cABZd7m60o+cDEPUTG6jTpuG2vqN35UioeF99MQ/HoSOEPq0Bgil8g3jtzE0oH9A==", + "version": "0.22.34", + "resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.34.tgz", + "integrity": "sha512-uoi5gQGpH5vdNrGOexnNm+19YZLdIRMF/IW8V6w1kIeoXaO1m2mVUMV4dl76tvRRKoIp9d/Z97ZYeIE4lacEsA==", "requires": { "@types/node": "*" } }, "@types/enzyme": { - "version": "3.10.15", - "resolved": "https://registry.npmjs.org/@types/enzyme/-/enzyme-3.10.15.tgz", - "integrity": "sha512-Tdm2XXW7TfyKhb/ddSLMpj8W0UgxbCOOauFNeLJH7+KzsfOBrHF6XPctw11SwGoOPyUglYQpvMoQNFXOF0uTwg==", + "version": "3.10.16", + "resolved": "https://registry.npmjs.org/@types/enzyme/-/enzyme-3.10.16.tgz", + "integrity": "sha512-17uMdJjSKjvdn/MhO/G2lRNPZGvJxFpvgONrsRoS1+khtJ6UcnCwC9v3gk2UqPyAkMZb6a1VYxScc/vOgkDl9w==", "requires": { "@types/cheerio": "*", "@types/react": "^16" }, "dependencies": { "@types/react": { - "version": "16.14.50", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.50.tgz", - "integrity": "sha512-7TWZ/HjhXsRK3BbhSFxTinbSft3sUXJAU3ONngT0rpcKJaIOlxkRke4bidqQTopUbEv1ApC5nlSEkIpX43MkTg==", + "version": "16.14.51", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.51.tgz", + "integrity": "sha512-4T/wsDXStA5OUGTj6w2INze3ZCz22IwQiWcApgqqNRU2A6vNUIPXpNkjAMUFxx6diYPVkvz+d7gEtU7AZ+0Xqg==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -1190,45 +1190,45 @@ } }, "@types/jasmine": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-5.1.1.tgz", - "integrity": "sha512-qL4GoZHHJl1JQ0vK31OtXMfkfGxYJnysmYz9kk0E8j5W96ThKykBF90uD3PcVmQUAzulbsaus2eFiBhCH5itfw==" + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-5.1.2.tgz", + "integrity": "sha512-GJzYZWAr7aZuVsQwo77ErgdnqiXiz1lwsXXKgsJEwMlAxWQqjpiTGh0JOpLGXSlIFvIAFbgZTHs0u+jBzh/GFg==" }, "@types/json-schema": { - "version": "7.0.14", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.14.tgz", - "integrity": "sha512-U3PUjAudAdJBeC2pgN8uTIKgxrb4nlDF3SF0++EldXQvQBGkpFZMSnwQiIoDU77tv45VgNkl/L4ouD+rEomujw==" + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==" }, "@types/karma": { - "version": "6.3.6", - "resolved": "https://registry.npmjs.org/@types/karma/-/karma-6.3.6.tgz", - "integrity": "sha512-mMz2m0tt/U83yV5/z3k4GHrUqfdTKdXCfhnqdFo56W9dFPwjGiX/WrlOTDBWq5foCgwMHbrOMYdLXHVT/rNWew==", + "version": "6.3.7", + "resolved": "https://registry.npmjs.org/@types/karma/-/karma-6.3.7.tgz", + "integrity": "sha512-xue0uxcaPd6eSm7vjvo5b6raEq1n98zpsvAPGuvYjq7z/2q8Bct2fBJk+r9mtz9MO8AvtHlIX9sNnpErpttDEQ==", "requires": { "@types/node": "*", "log4js": "^6.4.1" } }, "@types/karma-chrome-launcher": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@types/karma-chrome-launcher/-/karma-chrome-launcher-3.1.3.tgz", - "integrity": "sha512-7eQz2j00Ffv5pa7cOz8h7tASyM97XVLx++OvuUDl1z9YD4eJnNVXKbmz/MwBpL+24hIClr34inoCSF6kTURT9A==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/@types/karma-chrome-launcher/-/karma-chrome-launcher-3.1.4.tgz", + "integrity": "sha512-DmZXMnOG1zcl/GqtWbfAePFqWLuDFOYdfa+TpvlNvGHiT8GxJjr5RKTptX8K8ZUokjX1pZGAf4KeC46iok3VcA==", "requires": { "@types/karma": "*" } }, "@types/karma-jasmine": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@types/karma-jasmine/-/karma-jasmine-4.0.4.tgz", - "integrity": "sha512-L8k6kKXda2JKOQ272h1f3+li7NdOu7EY6s53DbCDBpjGr7UFB/FZE/E5Az8wgBkAJXOqqSOHP6s8kUw+KK2iTg==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/karma-jasmine/-/karma-jasmine-4.0.5.tgz", + "integrity": "sha512-BCkxhflM7N5oLOCV+Jdz2fBFa9Yev4wm5iA80k3EVDyh3rUXminuCSuX16jTT/fr2J1dKrOfp22/2WuvW4nyPg==", "requires": { "@types/jasmine": "*", "@types/karma": "*" } }, "@types/lodash": { - "version": "4.14.200", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.200.tgz", - "integrity": "sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==" + "version": "4.14.201", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.201.tgz", + "integrity": "sha512-y9euML0cim1JrykNxADLfaG0FgD1g/yTHwUs/Jg9ZIU7WKj2/4IW9Lbb1WZbvck78W/lfGXFfe+u2EGfIJXdLQ==" }, "@types/long": { "version": "4.0.2", @@ -1241,14 +1241,14 @@ "integrity": "sha512-JIzsAvJeA/5iY6Y/OxZbv1lUcc8dNSE77lb2gnBH+/PJ3lFR1Ccvgwl5JWnHAkNHcRsT0TbpVOsiMKZ1F/yyJg==" }, "@types/prop-types": { - "version": "15.7.9", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.9.tgz", - "integrity": "sha512-n1yyPsugYNSmHgxDFjicaI2+gCNjsBck8UX9kuofAKlc0h1bL+20oSF72KeNaW2DUlesbEVCFgyV2dPGTiY42g==" + "version": "15.7.10", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.10.tgz", + "integrity": "sha512-mxSnDQxPqsZxmeShFH+uwQ4kO4gcJcGahjjMFeLbKE95IAZiiZyiEepGZjtXJ7hN/yfu0bu9xN2ajcU0JcxX6A==" }, "@types/react": { - "version": "17.0.69", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.69.tgz", - "integrity": "sha512-klEeru//GhiQvXUBayz0Q4l3rKHWsBR/EUOhOeow6hK2jV7MlO44+8yEk6+OtPeOlRfnpUnrLXzGK+iGph5aeg==", + "version": "17.0.70", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.70.tgz", + "integrity": "sha512-yqYMK49/cnqw+T8R9/C+RNjRddYmPDGI5lKHi3bOYceQCBAh8X2ngSbZP0gnVeyvHr0T7wEgIIGKT1usNol08w==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -1256,9 +1256,9 @@ } }, "@types/react-datepicker": { - "version": "4.19.1", - "resolved": "https://registry.npmjs.org/@types/react-datepicker/-/react-datepicker-4.19.1.tgz", - "integrity": "sha512-HV52yjxuRi49psAVuHTFXXr+RSrCbIFDn9ayei0YH8xVVAXCO+5GwHAGKeREAmNbneweN0ySGoByr90yJCAnrQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/@types/react-datepicker/-/react-datepicker-4.19.2.tgz", + "integrity": "sha512-Ta1YGrdK3PNWQjiilXly/ABjxsyjTHj4FoKlvhM4v2RC3aOM+m7xpr2fixjMIHEoS+108gt+sUBNGYGaXlxtfQ==", "requires": { "@popperjs/core": "^2.9.2", "@types/react": "*", @@ -1267,42 +1267,42 @@ } }, "@types/react-dom": { - "version": "17.0.22", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.22.tgz", - "integrity": "sha512-wHt4gkdSMb4jPp1vc30MLJxoWGsZs88URfmt3FRXoOEYrrqK3I8IuZLE/uFBb4UT6MRfI0wXFu4DS7LS0kUC7Q==", + "version": "17.0.23", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.23.tgz", + "integrity": "sha512-lnJAZfMEDxfvELeeT24w4rnUYwpzUzQAOTfJQbWYnLcx8AEfz+fXJDCbowIBqNK/Bi4D6j8ovT8Qsda2OtDApA==", "requires": { "@types/react": "^17" } }, "@types/react-redux": { - "version": "5.0.26", - "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-5.0.26.tgz", - "integrity": "sha512-DoWD97Hvh/bOSjQtd4OMmPu4fTVsvmruQD1CMi6Zan/xtEuHB5IuW+cakMY/pY8nt5xtLgZsu0RGL3grymrZCA==", + "version": "5.0.27", + "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-5.0.27.tgz", + "integrity": "sha512-n3HVhkl8dG6qENcxP+x4G1FnpCBR8zL1+UbUwJwRk+dY9r8dPj85M3mtgS/T1Ep7eHTsAc2RGG14kY4lr7aCzQ==", "requires": { "@types/react": "*", "redux": "^3.6.0" } }, "@types/react-toggle": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@types/react-toggle/-/react-toggle-4.0.4.tgz", - "integrity": "sha512-eI7kFf8GIp8tRZaAvq0pFATy7zlAqlDCvGYkYVfl2arAKKAom9bHM3QvdVFsFUuvWseX/c7FkLG5CxAXF8psVw==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/react-toggle/-/react-toggle-4.0.5.tgz", + "integrity": "sha512-MHHEDe7GnF/EhLtI5sT70Dqab8rwlgjRZtu/u6gmfbYd+HeYxWiUSRog16+1BCfkz7Wy2VU6+TPU2oCsDtqDzA==", "requires": { "@types/react": "*" } }, "@types/react-transition-group": { - "version": "4.4.8", - "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.8.tgz", - "integrity": "sha512-QmQ22q+Pb+HQSn04NL3HtrqHwYMf4h3QKArOy5F8U5nEVMaihBs3SR10WiOM1iwPz5jIo8x/u11al+iEGZZrvg==", + "version": "4.4.9", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.9.tgz", + "integrity": "sha512-ZVNmWumUIh5NhH8aMD9CR2hdW0fNuYInlocZHaZ+dgk/1K49j1w/HoAuK1ki+pgscQrOFRTlXeoURtuzEkV3dg==", "requires": { "@types/react": "*" } }, "@types/redux-logger": { - "version": "3.0.11", - "resolved": "https://registry.npmjs.org/@types/redux-logger/-/redux-logger-3.0.11.tgz", - "integrity": "sha512-lRys/mnrut+BynEsYX0KAWy/WJ4/xAKrEQCdtOGbGJE0iu4yHaUBqCsv7+AZVsIRr7AtsIzgLnpBH2zrw7WNFA==", + "version": "3.0.12", + "resolved": "https://registry.npmjs.org/@types/redux-logger/-/redux-logger-3.0.12.tgz", + "integrity": "sha512-5vAlwokZi/Unb1eGoZfVVzIBTPNDflwXiDzPLT1SynP6hdJfsOEf+w6ZOySOyboLWciCRYeE5DGYUnwVCq+Uyg==", "requires": { "redux": "^4.0.0" }, @@ -1318,14 +1318,14 @@ } }, "@types/scheduler": { - "version": "0.16.5", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.5.tgz", - "integrity": "sha512-s/FPdYRmZR8SjLWGMCuax7r3qCWQw9QKHzXVukAuuIJkXkDRwp+Pu5LMIVFi0Fxbav35WURicYr8u1QsoybnQw==" + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.6.tgz", + "integrity": "sha512-Vlktnchmkylvc9SnwwwozTv04L/e1NykF5vgoQ0XTmI8DD+wxfjQuHuvHS3p0r2jz2x2ghPs2h1FVeDirIteWA==" }, "@types/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ==" + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.5.tgz", + "integrity": "sha512-+d+WYC1BxJ6yVOgUgzK8gWvp5qF8ssV5r4nsDcZWKRWcDQLQ619tvWAxJQYGgBrO1MnLJC7a5GtiYsAoQ47dJg==" }, "@types/sinon": { "version": "10.0.20", @@ -1336,19 +1336,19 @@ } }, "@types/sinonjs__fake-timers": { - "version": "8.1.4", - "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.4.tgz", - "integrity": "sha512-GDV68H0mBSN449sa5HEj51E0wfpVQb8xNSMzxf/PrypMFcLTMwJMOM/cgXiv71Mq5drkOQmUGvL1okOZcu6RrQ==" + "version": "8.1.5", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", + "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==" }, "@types/store": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/store/-/store-2.0.4.tgz", - "integrity": "sha512-x7Pq0ASoOfu/1MrSVDvHihteHuJ/lAQfUsDGaK4+Tk+YM/rB155SBsNoNeKwn+3x+IgPJ/I5x1spVyZqwpfAuw==" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/store/-/store-2.0.5.tgz", + "integrity": "sha512-5NmTKe3GWdOaykzq7no+Ahf6mafJu0oLc9JNhJ3E26+0oFvd6GnksnZQpMXcH526mfG4xDYjFiKzyDL51PzeWQ==" }, "@types/webpack-env": { - "version": "1.18.3", - "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.18.3.tgz", - "integrity": "sha512-v4CH6FLBCftYGFAswDhzFLjKgucXsOkIf5Mzl8ZZhEtC6oye9whFInNPKszNB9AvX7JEZMtpXxWctih6addP+Q==" + "version": "1.18.4", + "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.18.4.tgz", + "integrity": "sha512-I6e+9+HtWADAWeeJWDFQtdk4EVSAbj6Rtz4q8fJ7mSr1M0jzlFcs8/HZ+Xb5SHzVm1dxH7aUiI+A8kA8Gcrm0A==" }, "@typescript-eslint/eslint-plugin": { "version": "5.62.0", @@ -5871,14 +5871,14 @@ } }, "eslint": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", - "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", + "version": "8.53.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.53.0.tgz", + "integrity": "sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag==", "requires": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.52.0", + "@eslint/eslintrc": "^2.1.3", + "@eslint/js": "8.53.0", "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -6602,9 +6602,9 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "fast-glob": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", - "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", diff --git a/server/cp/mgmt_api/companies.py b/server/cp/mgmt_api/companies.py index c0cfb5d..87f2102 100644 --- a/server/cp/mgmt_api/companies.py +++ b/server/cp/mgmt_api/companies.py @@ -1,13 +1,14 @@ from bson.objectid import ObjectId from flask import request, current_app as app +from cp.mgmt_api.utils import validate_product_refs import newsroom +import superdesk from newsroom.companies import CompaniesResource, CompaniesService from newsroom.companies.views import get_errors_company from newsroom.products.products import ProductsResource from newsroom.products.views import get_product_ref from newsroom.utils import find_one -import superdesk from superdesk.errors import SuperdeskApiError @@ -42,6 +43,8 @@ def on_create(self, docs): raise SuperdeskApiError.badRequestError( message=message, payload=message ) + if doc.get("products"): + validate_product_refs(doc["products"]) def on_created(self, docs): super().on_created(docs) @@ -49,6 +52,8 @@ def on_created(self, docs): app.cache.set(str(doc["_id"]), doc) def on_update(self, updates, original): + if updates.get("products"): + validate_product_refs(updates["products"]) super().on_update(updates, original) app.cache.delete(str(original["_id"])) diff --git a/server/cp/mgmt_api/users.py b/server/cp/mgmt_api/users.py index 5f61cd5..43cbdcc 100644 --- a/server/cp/mgmt_api/users.py +++ b/server/cp/mgmt_api/users.py @@ -2,9 +2,11 @@ import superdesk from bson.objectid import ObjectId +from flask import current_app as app from newsroom.users import UsersResource, UsersService from superdesk.errors import SuperdeskApiError -from flask import current_app as app + +from cp.mgmt_api.utils import validate_product_refs class CPUsersResource(newsroom.Resource): @@ -20,6 +22,10 @@ def init_app(app): class CPUsersService(UsersService): + def check_permissions(self, doc, updates=None): + """Avoid testing if user has permissions.""" + pass + def on_create(self, docs): super().on_create(docs) for doc in docs: @@ -32,7 +38,9 @@ def on_create(self, docs): raise SuperdeskApiError.badRequestError(message=message, payload=message) if doc.get('company'): doc['company'] = ObjectId(doc.get('company')) + if doc.get("products"): + validate_product_refs(doc["products"]) - def check_permissions(self, doc, updates=None): - """Avoid testing if user has permissions.""" - pass + def on_update(self, updates, original): + if updates.get("products"): + validate_product_refs(updates["products"]) diff --git a/server/cp/mgmt_api/utils.py b/server/cp/mgmt_api/utils.py new file mode 100644 index 0000000..2e9da76 --- /dev/null +++ b/server/cp/mgmt_api/utils.py @@ -0,0 +1,14 @@ +import superdesk + + +def validate_product_refs(products): + products_service = superdesk.get_resource_service("products") + for product_spec in products: + product = products_service.find_one(req=None, _id=product_spec["_id"]) + assert product is not None and product["product_type"] == product_spec.get( + "section" + ), ( + f"invalid product type for product {product_spec['_id']}, should be {product['product_type']}" + if product + else f"unknown product {product_spec['_id']}" + ) diff --git a/server/data/ui_config.json b/server/data/ui_config.json index 5b6e1e5..8b94079 100644 --- a/server/data/ui_config.json +++ b/server/data/ui_config.json @@ -121,13 +121,14 @@ }, { "_id": "agenda", - "init_version": 7, + "init_version": 8, "multi_select_topics": false, "open_coverage_content_in_same_page": true, "enable_global_topics": true, "subnav": { "filters": [ "item_type", + "location", "coverage_type", "coverage_status" ] diff --git a/server/features/mgmt_api_companies.feature b/server/features/mgmt_api_companies.feature index c13cf8d..dbf907c 100644 --- a/server/features/mgmt_api_companies.feature +++ b/server/features/mgmt_api_companies.feature @@ -81,4 +81,62 @@ Feature: Management API - Companies ] } """ - \ No newline at end of file + + Scenario: Validate company products section + Given "products" + """ + [ + {"name": "test", "query": "test", "product_type": "agenda"} + ] + """ + + When we post to "/companies" + """ + { + "name": "zzz company", + "contact_name": "zzz company", + "contact_email": "contact@zzz.com", + "phone": "99999999", + "products": [ + {"_id": "#products._id#", "section": "wire"} + ] + } + """ + Then we get error 400 + """ + {"code": 400, "message": "invalid product type for product #products._id#, should be agenda"} + """ + + When we post to "/companies" + """ + { + "name": "zzz company", + "contact_name": "zzz company", + "contact_email": "contact@zzz.com", + "phone": "99999999", + "products": [ + {"_id": "#products._id#", "section": "agenda"} + ] + } + """ + Then we get response code 201 + + When we patch "/companies/#companies._id#" + """ + { + "products": [ + {"_id": "#products._id#", "section": "wire"} + ] + } + """ + Then we get error 400 + + When we patch "/companies/#companies._id#" + """ + { + "products": [ + {"_id": "#products._id#", "section": "agenda"} + ] + } + """ + Then we get response code 200 diff --git a/server/features/mgmt_api_products.feature b/server/features/mgmt_api_products.feature index a7de810..397b93d 100644 --- a/server/features/mgmt_api_products.feature +++ b/server/features/mgmt_api_products.feature @@ -14,7 +14,7 @@ Feature: Management API - Products "name": "A fishy Product", "description": "a product for those interested in fish", "query": "fish", - "product_type": "news_api" + "product_type": "agenda" }] """ Then we get response code 201 @@ -52,7 +52,7 @@ Feature: Management API - Products "name": "A fishy Product", "description": "new description", "query": "fish", - "product_type": "news_api", + "product_type": "agenda", "seats": 5 } ]} @@ -62,7 +62,7 @@ Feature: Management API - Products Then we get existing resource """ {"products": [ - {"_id": "#products._id#", "section": "news_api", "seats": 5} + {"_id": "#products._id#", "section": "agenda", "seats": 5} ]} """ diff --git a/server/features/mgmt_api_users.feature b/server/features/mgmt_api_users.feature index e0095b2..24b1207 100644 --- a/server/features/mgmt_api_users.feature +++ b/server/features/mgmt_api_users.feature @@ -110,3 +110,74 @@ Feature: Management API - Users """ When we delete latest Then we get ok response + + Scenario: Validate product type + Scenario: Create a user + Given empty "users" + And "products" + """ + [ + {"name": "test", "query": "test", "product_type": "agenda"} + ] + """ + And "companies" + """ + [{"name": "zzz company"}] + """ + + When we post to "/users" + """ + { + "first_name": "John", + "last_name": "Cena", + "email": "johncena@wwe.com", + "company": "#companies._id#", + "sections": { + "agenda": true + }, + "products": [ + {"_id": "#products._id#", "section": "wire"} + ] + } + """ + Then we get error 400 + """ + {"code": 400, "message": "invalid product type for product #products._id#, should be agenda"} + """ + + When we post to "/users" + """ + { + "first_name": "John", + "last_name": "Cena", + "email": "johncena@wwe.com", + "company": "#companies._id#", + "sections": { + "agenda": true + }, + "products": [ + {"section": "agenda", "_id": "#products._id#"} + ] + } + """ + Then we get response code 201 + + When we patch "/users/#users._id#" + """ + { + "products": [ + {"section": "wire", "_id": "#products._id#"} + ] + } + """ + Then we get error 400 + + When we patch "/users/#users._id#" + """ + { + "products": [ + {"section": "agenda", "_id": "#products._id#"} + ] + } + """ + Then we get response code 200 diff --git a/server/theme/login.html b/server/theme/login.html index eeca1e4..24800c2 100644 --- a/server/theme/login.html +++ b/server/theme/login.html @@ -28,7 +28,11 @@
{{ gettext("Login") }}
{% endif %}