From bad17bbbef52f1102bab9528db390f2d7489a79d Mon Sep 17 00:00:00 2001 From: vienthuong Date: Mon, 31 May 2021 22:50:22 +0700 Subject: [PATCH] 6.4 compatibility --- CHANGELOG_de-DE.md | 3 +++ CHANGELOG_en-GB.md | 3 +++ composer.json | 4 ++-- src/Resources/public/administration/js/impersonation.js | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index 1e3fe2e..1bb13e7 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,3 +1,6 @@ +# 1.1.0 - 6.4 Compatibility +- Add compatible with shopware 6.4 + # 1.0.0 - Erste Veröffentlichung - Erlauben Sie nur Administratoren, sich auszugeben. diff --git a/CHANGELOG_en-GB.md b/CHANGELOG_en-GB.md index 70d9e73..5baf084 100644 --- a/CHANGELOG_en-GB.md +++ b/CHANGELOG_en-GB.md @@ -1,3 +1,6 @@ +# 1.1.0 - 6.4 Compatibility +- Add compatible with shopware 6.4 + # 1.0.0 - First release - Only allow administrators to impersonate. diff --git a/composer.json b/composer.json index 939b488..1e6c21b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "vienthuong/impersonation", "description": "A Shopware 6 Impersonation plugin", - "version": "1.0.0", + "version": "1.1.0", "type": "shopware-platform-plugin", "license": "MIT", "authors": [ @@ -16,7 +16,7 @@ } }, "require": { - "shopware/core": "~6.3.0" + "shopware/core": "^6.3.0" }, "extra": { "shopware-plugin-class": "VienThuong\\Impersonation\\Impersonation", diff --git a/src/Resources/public/administration/js/impersonation.js b/src/Resources/public/administration/js/impersonation.js index 00fe301..1f99df0 100644 --- a/src/Resources/public/administration/js/impersonation.js +++ b/src/Resources/public/administration/js/impersonation.js @@ -1 +1 @@ -(this.webpackJsonp=this.webpackJsonp||[]).push([["impersonation"],{"/3U3":function(t,e,i){"use strict";i.d(e,"a",(function(){return l})),i.d(e,"b",(function(){return p}));var n=i("lwsE"),o=i.n(n),s=i("W8MJ"),r=i.n(s),a=Shopware,c=a.Application,u=a.WorkerNotification,l=3e4,p=5e3,f=function(){function t(e){o()(this,t),this._context=e,this._isRunning=!1,this._isRequestRunning=!1,this._interval=l,this._isIntervalWatcherSetup=!1,this._timeoutId=null,this._applicationRoot=null,this._middlewareHelper=null}return r()(t,[{key:"start",value:function(){this._isRunning=!0,this._middlewareHelper=u.initialize(),this._timeoutId=setTimeout(this._checkQueue.bind(this),this._interval),this.setupIntervalWatcher()}},{key:"terminate",value:function(){this._isRunning=!1,null!==this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=null)}},{key:"setupIntervalWatcher",value:function(){this._isIntervalWatcherSetup||(Shopware.State.watch((function(t){return t.notification.workerProcessPollInterval}),this._onPollIntervalChanged.bind(this)),this._isIntervalWatcherSetup=!0)}},{key:"getMessageQueueStatsRepository",value:function(){return Shopware.Service().get("repositoryFactory").create("message_queue_stats")}},{key:"_checkQueue",value:function(){var t=this;this._isRequestRunning=!0,this.getMessageQueueStatsRepository().search(new Shopware.Data.Criteria(1,25),this._context).then((function(e){t._isRequestRunning=!1,t._timeoutId=null,t.runNotificationMiddleware(e),t._isRunning&&(t._interval=t._getApplicationRootReference().$store.state.notification.workerProcessPollInterval,t._timeoutId=setTimeout(t._checkQueue.bind(t),t._interval))}))}},{key:"_onPollIntervalChanged",value:function(t){this._interval=t,this._isRequestRunning||(null!==this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=null),t!==p?this._timeoutId=setTimeout(this._checkQueue.bind(this),this._interval):this._checkQueue())}},{key:"runNotificationMiddleware",value:function(t){var e=this._getApplicationRootReference(),i={$root:e,notification:{create:function(t){return e.$store.dispatch("notification/createNotification",t)},update:function(t){return e.$store.dispatch("notification/updateNotification",t)}},queue:t};this._middlewareHelper.go(i)}},{key:"_getApplicationRootReference",value:function(){return this._applicationRoot||(this._applicationRoot=c.getApplicationRoot()),this._applicationRoot}}]),t}();e.c=f},JXUN:function(t,e){t.exports='{% block sw_page_top_bar_actions %}\n
\n {% block sw_page_leave_impersonation_button %}\n {{ $tc(\'impersonation.actions.leaveImpersonation\') }}\n {% endblock %}\n\n {% block sw_page_notification_center %}\n \n {% endblock %}\n
\n{% endblock %}\n'},MYA2:function(t,e,i){},Vx7a:function(t,e){t.exports='{% block sw_settings_user_list_actions_edit %}\n {% parent() %}\n\n {% block sw_settings_user_list_actions_impersonate %}\n \n {{ $tc(\'impersonation.actions.impersonate\') }}\n \n {% endblock %}\n{% endblock %}\n'},f1yM:function(t,e,i){"use strict";i.d(e,"b",(function(){return d}));var n=i("lSNA"),o=i.n(n),s=i("/3U3");function r(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function a(t){for(var e=1;e=0;s-=1){var r=n[s];o[r]=a({},i[r],{timestamp:new Date(i[r].timestamp)})}return n.length>50&&g(o),o}function g(t){var e=m();if(e){var i={};Object.keys(t).forEach((function(e){!1===t[e].isLoading&&(i[e]=a({},t[e],{timestamp:t[e].timestamp.toJSON()}))})),localStorage.setItem(e,JSON.stringify(i))}}e.a={namespaced:!0,state:{notifications:{},growlNotifications:{},threshold:5,workerProcessPollInterval:s.a,notificationDefaults:{visited:!1,metadata:{},isLoading:!1},growlNotificationDefaults:{system:!1,variant:"info",autoClose:!0,duration:5e3}},getters:{getNotifications:function(t){return Object.values(t.notifications).reverse()},getGrowlNotifications:function(t){return Object.values(t.growlNotifications)}},mutations:{setThreshold:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;t.threshold=e,t.growlNotifications.length>t.threshold&&t.growlNotifications.splice(e,t.growlNotifications.length-t.threshold)},setWorkerProcessPollInterval:function(t,e){t.workerProcessPollInterval=e},setNotificationsForCurrentUser:function(t){t.notifications=h()},clearNotificationsForCurrentUser:function(t){t.notifications={};var e=m();e&&localStorage.removeItem(e)},clearGrowlNotificationsForCurrentUser:function(t){t.growlNotifications={}},setNotifications:function(t,e){Object.keys(e).forEach((function(i){u.view.setReactive(t.notifications,e[i].uuid,e[i])}))},upsertNotification:function(t,e){var i=t.notifications[e.uuid];void 0===i?(u.view.setReactive(t.notifications,e.uuid,e),g(t.notifications)):Object.assign(i,e)},removeNotification:function(t,e){u.view.deleteReactive(t.notifications,e.uuid),g(t.notifications)},setAllNotificationsVisited:function(t){Object.keys(t.notifications).forEach((function(e){t.notifications[e].visited=!0})),g(t.notifications)},upsertGrowlNotification:function(t,e){var i=t.growlNotifications[e.uuid];if(void 0===i){u.view.setReactive(t.growlNotifications,e.uuid,e);var n=Object.keys(t.growlNotifications);n.length>t.threshold&&u.view.deleteReactive(t.growlNotifications,n[0])}else Object.assign(i,e)},removeGrowlNotification:function(t,e){u.view.deleteReactive(t.growlNotifications,e.uuid)}},actions:{createNotification:function(t,e){var i=t.state,n=t.commit,o=t.dispatch;if(!e.message)return p.warn("NotificationStore","A message must be specified",e),null;void 0!==e.growl&&!0!==e.growl||o("createGrowlNotification",e),delete e.growl;var s=Object.assign({},i.notificationDefaults,e,{uuid:f.createId(),timestamp:new Date});return"success"===s.variant?null:(n("upsertNotification",s),s.uuid)},createGrowlNotification:function(t,e){var i=t.state,n=t.commit,o=Object.assign({},i.growlNotificationDefaults,e,{uuid:f.createId(),timestamp:new Date});delete o.growl,n("upsertGrowlNotification",o),o.autoClose&&setTimeout((function(){n("removeGrowlNotification",o)}),o.duration)},updateNotification:function(t,e){var i=t.state,n=t.commit,o=t.dispatch;if(!e.uuid)return p.warn("NotificationStore","Update to an notification must contain the uuid",e),null;var s=function(t,e){var i=e.notifications[t];return void 0===i&&(i=Object.assign({},e.notificationDefaults,{uuid:t,timestamp:new Date})),i}(e.uuid,i),r=function(t,e){return Object.assign({},t,{visited:e.metadata?JSON.stringify(t.metadata)===JSON.stringify(e.metadata):t.visited},e)}(s,e);return n("upsertNotification",r),void 0!==e.growl&&!0===e.growl&&o("createGrowlNotification",r),s.uuid},setAllNotificationsVisited:function(t){(0,t.commit)("setAllNotificationsVisited")}}}},mUXG:function(t,e,i){"use strict";i.r(e);var n=i("f1yM");const{State:o}=Shopware;var s=class{constructor(t,e,i){this.name="impersonationService";const{userService:n,localeHelper:o,loginService:s}=e;this.userService=n,this.localeHelper=o,this.loginService=s,this.impersonatingUser=t,this.httpClient=i,this._initializeService()}async impersonate(t){localStorage.setItem("impersonated-user-id",t);const e=await this.userService.getUser({},{"impersonated-user-id":t}),{data:{password:i,...n}}=e;await this._initializeUser(n)}async leaveImpersonation(){localStorage.removeItem("impersonated-user-id"),await this._initializeUser(this.impersonatingUser)}isImpersonating(){return!!localStorage.getItem("impersonated-user-id")}async _initializeUser(t){o.commit("setCurrentUser",t),await this.localeHelper.setLocaleWithId(t.localeId),o.commit("context/setApiLanguageId",o.get("session").languageId),Object(n.b)()}_initializeService(){this.httpClient.interceptors.request.use(t=>(this.isImpersonating()&&(t.headers=t.headers||{},t.headers["impersonated-user-id"]=localStorage.getItem("impersonated-user-id")),t)),this._registerLogInListener(),this.isImpersonating()&&this.impersonate(localStorage.getItem("impersonated-user-id"))}_registerLogInListener(){this.loginService.addOnLoginListener(async()=>{this.isImpersonating()&&await this.leaveImpersonation()})}};const{State:r,Application:a}=Shopware,c=a.getContainer("init"),u=r.get("session").currentUser,l=c.httpClient;a.addServiceProvider("impersonationService",t=>new s(u,t,l));var p=i("Vx7a"),f=i.n(p);const{Component:d,Service:m,State:h}=Shopware,g={computed:{impersonationService:()=>m("impersonationService"),currentUser:()=>h.get("session").currentUser,canImpersonate(){return!!this.currentUser.admin},isImpersonating(){return this.impersonationService.isImpersonating()}},methods:{async impersonate(t){this.canImpersonate&&(this.isLoading=!0,await this.impersonationService.impersonate(t),this.isLoading=!1,this.$router.push({name:"sw.dashboard.index"}))}}};d.getComponentRegistry().has("sw-settings-user-list")?d.override("sw-settings-user-list",{template:f.a,deprecated:{version:"6.4.0",comment:"Use sw-users-permissions-user-listing instead"},...g}):d.override("sw-users-permissions-user-listing",{template:f.a,...g});var v=i("JXUN"),w=i.n(v);i("vUXJ");const{Component:_,State:S,Service:b}=Shopware;_.override("sw-page",{template:w.a,data:()=>({isLoading:!1}),computed:{currentUser:()=>S.get("session").currentUser,pageClasses(){const t=this.$super("pageClasses");return t["has--leave-impersonation-button"]=this.isImpersonating,t},impersonationService:()=>b("impersonationService"),isImpersonating(){return this.impersonationService.isImpersonating()}},methods:{async leaveImpersonation(){this.isLoading=!0,await this.impersonationService.leaveImpersonation(),this.isLoading=!1,"sw.users.permissions.index"===this.$route.name?this.$router.go():this.$router.push({name:"sw.users.permissions.index"})}}}),Shopware.Module.register("impersonation",{type:"plugin",name:"Impersonation",version:"1.0.0",targetVersion:"1.0.0"})},vUXJ:function(t,e,i){var n=i("MYA2");"string"==typeof n&&(n=[[t.i,n,""]]),n.locals&&(t.exports=n.locals);(0,i("SZ7m").default)("26b242b5",n,!0,{})}},[["mUXG","runtime","vendors-node"]]]); \ No newline at end of file +(this.webpackJsonp=this.webpackJsonp||[]).push([["impersonation"],{"/3U3":function(e,t,i){"use strict";i.d(t,"a",(function(){return l})),i.d(t,"b",(function(){return f}));var n=i("lwsE"),r=i.n(n),o=i("W8MJ"),s=i.n(o),a=Shopware,c=a.Application,u=a.WorkerNotification,l=3e4,f=5e3,p=function(){function e(t){r()(this,e),this._context=t,this._isRunning=!1,this._isRequestRunning=!1,this._interval=l,this._isIntervalWatcherSetup=!1,this._timeoutId=null,this._applicationRoot=null,this._middlewareHelper=null}return s()(e,[{key:"start",value:function(){this._isRunning=!0,this._middlewareHelper=u.initialize(),this._timeoutId=setTimeout(this._checkQueue.bind(this),this._interval),this.setupIntervalWatcher()}},{key:"terminate",value:function(){this._isRunning=!1,null!==this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=null)}},{key:"setupIntervalWatcher",value:function(){this._isIntervalWatcherSetup||(Shopware.State.watch((function(e){return e.notification.workerProcessPollInterval}),this._onPollIntervalChanged.bind(this)),this._isIntervalWatcherSetup=!0)}},{key:"getMessageQueueStatsRepository",value:function(){return Shopware.Service().get("repositoryFactory").create("message_queue_stats")}},{key:"_checkQueue",value:function(){var e=this;this._isRequestRunning=!0,this.getMessageQueueStatsRepository().search(new Shopware.Data.Criteria(1,25),this._context).then((function(t){e._isRequestRunning=!1,e._timeoutId=null,e.runNotificationMiddleware(t),e._isRunning&&(e._interval=e._getApplicationRootReference().$store.state.notification.workerProcessPollInterval,e._timeoutId=setTimeout(e._checkQueue.bind(e),e._interval))}))}},{key:"_onPollIntervalChanged",value:function(e){this._interval=e,this._isRequestRunning||(null!==this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=null),e!==f?this._timeoutId=setTimeout(this._checkQueue.bind(this),this._interval):this._checkQueue())}},{key:"runNotificationMiddleware",value:function(e){var t=this._getApplicationRootReference(),i={$root:t,notification:{create:function(e){return t.$store.dispatch("notification/createNotification",e)},update:function(e){return t.$store.dispatch("notification/updateNotification",e)}},queue:e};this._middlewareHelper.go(i)}},{key:"_getApplicationRootReference",value:function(){return this._applicationRoot||(this._applicationRoot=c.getApplicationRoot()),this._applicationRoot}}]),e}();t.c=p},JXUN:function(e,t){e.exports='{% block sw_page_top_bar_actions %}\n
\n {% block sw_page_leave_impersonation_button %}\n {{ $tc(\'impersonation.actions.leaveImpersonation\') }}\n {% endblock %}\n\n {% block sw_page_notification_center %}\n \n {% endblock %}\n
\n{% endblock %}\n'},Vx7a:function(e,t){e.exports='{% block sw_settings_user_list_actions_edit %}\n {% parent() %}\n\n {% block sw_settings_user_list_actions_impersonate %}\n \n {{ $tc(\'impersonation.actions.impersonate\') }}\n \n {% endblock %}\n{% endblock %}\n'},f1yM:function(e,t,i){"use strict";i.d(t,"b",(function(){return m}));var n=i("lSNA"),r=i.n(n),o=i("/3U3");function s(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function a(e){for(var t=1;t=0;o-=1){var s=n[o];r[s]=a(a({},i[s]),{},{timestamp:new Date(i[s].timestamp)})}return n.length>50&&g(r),r}function g(e){var t=v();if(t){var i={};Object.keys(e).forEach((function(t){!1===e[t].isLoading&&(i[t]=a(a({},e[t]),{},{timestamp:e[t].timestamp.toJSON()}))})),localStorage.setItem(t,JSON.stringify(i))}}t.a={namespaced:!0,state:{notifications:{},growlNotifications:{},threshold:5,workerProcessPollInterval:o.a,notificationDefaults:{visited:!1,metadata:{},isLoading:!1},growlNotificationDefaults:{system:!1,variant:"info",autoClose:!0,duration:5e3}},getters:{getNotifications:function(e){return Object.values(e.notifications).reverse()},getGrowlNotifications:function(e){return Object.values(e.growlNotifications)}},mutations:{setThreshold:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;e.threshold=t,e.growlNotifications.length>e.threshold&&e.growlNotifications.splice(t,e.growlNotifications.length-e.threshold)},setWorkerProcessPollInterval:function(e,t){e.workerProcessPollInterval=t},setNotificationsForCurrentUser:function(e){e.notifications=d()},clearNotificationsForCurrentUser:function(e){e.notifications={};var t=v();t&&localStorage.removeItem(t)},clearGrowlNotificationsForCurrentUser:function(e){e.growlNotifications={}},setNotifications:function(e,t){Object.keys(t).forEach((function(i){u.view.setReactive(e.notifications,t[i].uuid,t[i])}))},upsertNotification:function(e,t){var i=e.notifications[t.uuid];void 0===i?(u.view.setReactive(e.notifications,t.uuid,t),g(e.notifications)):Object.assign(i,t)},removeNotification:function(e,t){u.view.deleteReactive(e.notifications,t.uuid),g(e.notifications)},setAllNotificationsVisited:function(e){Object.keys(e.notifications).forEach((function(t){e.notifications[t].visited=!0})),g(e.notifications)},upsertGrowlNotification:function(e,t){var i=e.growlNotifications[t.uuid];if(void 0===i){u.view.setReactive(e.growlNotifications,t.uuid,t);var n=Object.keys(e.growlNotifications);n.length>e.threshold&&u.view.deleteReactive(e.growlNotifications,n[0])}else Object.assign(i,t)},removeGrowlNotification:function(e,t){u.view.deleteReactive(e.growlNotifications,t.uuid)}},actions:{createNotification:function(e,t){var i=e.state,n=e.commit,r=e.dispatch;if(!t.message)return f.warn("NotificationStore","A message must be specified",t),null;void 0!==t.growl&&!0!==t.growl||r("createGrowlNotification",t),delete t.growl;var o=Object.assign({},i.notificationDefaults,t,{uuid:p.createId(),timestamp:new Date});return"success"===o.variant?null:(n("upsertNotification",o),o.uuid)},createGrowlNotification:function(e,t){var i=e.state,n=e.commit,r=Object.assign({},i.growlNotificationDefaults,t,{uuid:p.createId(),timestamp:new Date});delete r.growl,n("upsertGrowlNotification",r),r.autoClose&&setTimeout((function(){n("removeGrowlNotification",r)}),r.duration)},updateNotification:function(e,t){var i=e.state,n=e.commit,r=e.dispatch;if(!t.uuid)return f.warn("NotificationStore","Update to an notification must contain the uuid",t),null;var o=function(e,t){var i=t.notifications[e];return void 0===i&&(i=Object.assign({},t.notificationDefaults,{uuid:e,timestamp:new Date})),i}(t.uuid,i),s=function(e,t){return Object.assign({},e,{visited:t.metadata?JSON.stringify(e.metadata)===JSON.stringify(t.metadata):e.visited},t)}(o,t);return n("upsertNotification",s),void 0!==t.growl&&!0===t.growl&&r("createGrowlNotification",s),o.uuid},setAllNotificationsVisited:function(e){(0,e.commit)("setAllNotificationsVisited")}}}},gKsz:function(e,t,i){},mUXG:function(e,t,i){"use strict";i.r(t);var n="impersonated-user-id",r=i("f1yM");function o(e,t){if(null==e)return{};var i,n,r=function(e,t){if(null==e)return{};var i,n,r={},o=Object.keys(e);for(n=0;n=0||(r[i]=e[i]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,i)&&(r[i]=e[i])}return r}function s(e,t,i,n,r,o,s){try{var a=e[o](s),c=a.value}catch(e){return void i(e)}a.done?t(c):Promise.resolve(c).then(n,r)}function a(e){return function(){var t=this,i=arguments;return new Promise((function(n,r){var o=e.apply(t,i);function a(e){s(o,n,r,a,c,"next",e)}function c(e){s(o,n,r,a,c,"throw",e)}a(void 0)}))}}function c(e,t){for(var i=0;i