Prevent access of registered routes

This commit is contained in:
Faris Ansari 2018-08-01 16:29:40 +05:30
parent 2de046fbed
commit 5249307f27
3 changed files with 56 additions and 37 deletions

View File

@ -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
? `<li class="hub-sidebar-item text-muted" data-route="marketplace/profile">
? `<li class="hub-sidebar-item" data-route="marketplace/favourites">
${__('Favorites')}
</li>
<li class="hub-sidebar-item text-muted" data-route="marketplace/profile">
${__('Your Profile')}
</li>
<li class="hub-sidebar-item text-muted" data-route="marketplace/publish">
${__('Publish Products')}
</li>
<li class="hub-sidebar-item text-muted" data-route="marketplace/messages">
${__('Messages')}
</li>`
: `<li class="hub-sidebar-item text-muted" data-route="marketplace/register">
@ -77,9 +84,6 @@ erpnext.hub.Marketplace = class Marketplace {
<li class="hub-sidebar-item" data-route="marketplace/home">
${__('Browse')}
</li>
<li class="hub-sidebar-item" data-route="marketplace/favourites">
${__('Favorites')}
</li>
${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);

View File

@ -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 {
</div>
<div class="col-md-8">
<div class="margin-bottom"><a href="#marketplace/seller/${seller}" class="bold">${seller}</a></div>
<button class="btn btn-xs btn-default text-muted btn-contact-seller">
<button class="btn btn-xs btn-default text-muted" data-action="contact_seller">
${__('Contact Seller')}
</button>
</div>
@ -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(),

View File

@ -0,0 +1,7 @@
import SubPage from './subpage';
erpnext.hub.Messages = class Messages extends SubPage {
refresh() {
}
}