From 5249307f27ed73d16dce1407ae1d1c6432fdaa36 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 1 Aug 2018 16:29:40 +0530 Subject: [PATCH] Prevent access of registered routes --- erpnext/public/js/hub/marketplace.js | 32 +++++++++++---- erpnext/public/js/hub/pages/item.js | 54 ++++++++++++------------- erpnext/public/js/hub/pages/messages.js | 7 ++++ 3 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 erpnext/public/js/hub/pages/messages.js diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index ab0d4f7e71..d393605d05 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -8,6 +8,7 @@ import './pages/register'; import './pages/profile'; import './pages/publish'; import './pages/published_products'; +import './pages/messages'; import './pages/not_found'; // helpers @@ -62,11 +63,17 @@ erpnext.hub.Marketplace = class Marketplace { $nav_group.empty(); const user_specific_items_html = this.registered - ? `
  • + ? `
  • + ${__('Favorites')} +
  • +
  • ${__('Your Profile')}
  • ${__('Publish Products')} +
  • +
  • + ${__('Messages')}
  • ` : `
  • @@ -77,9 +84,6 @@ erpnext.hub.Marketplace = class Marketplace {
  • ${__('Browse')}
  • -
  • - ${__('Favorites')} -
  • ${user_specific_items_html} `); } @@ -148,10 +152,6 @@ erpnext.hub.Marketplace = class Marketplace { this.subpages.home = new erpnext.hub.Home(this.$body); } - if (route[1] === 'favourites' && !this.subpages.favourites) { - this.subpages.favourites = new erpnext.hub.Favourites(this.$body); - } - if (route[1] === 'search' && !this.subpages.search) { this.subpages.search = new erpnext.hub.SearchPage(this.$body); } @@ -172,6 +172,11 @@ erpnext.hub.Marketplace = class Marketplace { this.subpages.register = new erpnext.hub.Register(this.$body); } + // registered seller routes + if (route[1] === 'favourites' && !this.subpages.favourites) { + this.subpages.favourites = new erpnext.hub.Favourites(this.$body); + } + if (route[1] === 'profile' && !this.subpages.profile) { this.subpages.profile = new erpnext.hub.Profile(this.$body); } @@ -184,6 +189,17 @@ erpnext.hub.Marketplace = class Marketplace { this.subpages['my-products'] = new erpnext.hub.PublishedProducts(this.$body); } + if (route[1] === 'messages' && !this.subpages['messages']) { + this.subpages['messages'] = new erpnext.hub.Messages(this.$body); + } + + // dont allow unregistered users to access registered routes + const registered_routes = ['favourites', 'profile', 'publish', 'my-products', 'messages']; + if (!hub.settings.registered && registered_routes.includes(route[1])) { + frappe.set_route('marketplace', 'home'); + return; + } + if (!Object.keys(this.subpages).includes(route[1])) { if (!this.subpages.not_found) { this.subpages.not_found = new erpnext.hub.NotFound(this.$body); diff --git a/erpnext/public/js/hub/pages/item.js b/erpnext/public/js/hub/pages/item.js index b3c63c85f2..559a4d6d6a 100644 --- a/erpnext/public/js/hub/pages/item.js +++ b/erpnext/public/js/hub/pages/item.js @@ -2,11 +2,6 @@ import SubPage from './subpage'; import { get_rating_html } from '../helpers'; erpnext.hub.Item = class Item extends SubPage { - make_wrapper() { - super.make_wrapper(); - this.setup_events(); - } - refresh() { this.show_skeleton(); this.hub_item_code = frappe.get_route()[2]; @@ -45,29 +40,6 @@ erpnext.hub.Item = class Item extends SubPage { this.$wrapper.html(skeleton); } - setup_events() { - this.$wrapper.on('click', '.btn-contact-seller', () => { - const d = new frappe.ui.Dialog({ - title: __('Send a message'), - fields: [ - { - fieldname: 'to', - fieldtype: 'Read Only', - label: __('To'), - default: this.item.company - }, - { - fieldtype: 'Text', - fieldname: 'message', - label: __('Message') - } - ] - }); - - d.show(); - }); - } - get_item(hub_item_code) { return hub.call('get_item_details', { hub_item_code }); } @@ -150,7 +122,7 @@ erpnext.hub.Item = class Item extends SubPage {
    -
    @@ -204,6 +176,30 @@ erpnext.hub.Item = class Item extends SubPage { this.unpublish_dialog.show(); } + contact_seller() { + const d = new frappe.ui.Dialog({ + title: __('Send a message'), + fields: [ + { + fieldname: 'to', + fieldtype: 'Read Only', + label: __('To'), + default: this.item.company + }, + { + fieldtype: 'Text', + fieldname: 'message', + label: __('Message') + } + ], + primary_action: ({ message }) => { + if (!message) return; + } + }); + + d.show(); + } + make_review_area() { this.comment_area = new frappe.ui.ReviewArea({ parent: this.$wrapper.find('.timeline-head').empty(), diff --git a/erpnext/public/js/hub/pages/messages.js b/erpnext/public/js/hub/pages/messages.js new file mode 100644 index 0000000000..ac2057dcf3 --- /dev/null +++ b/erpnext/public/js/hub/pages/messages.js @@ -0,0 +1,7 @@ +import SubPage from './subpage'; + +erpnext.hub.Messages = class Messages extends SubPage { + refresh() { + + } +} \ No newline at end of file