[marketplace] Disallow unregistered routes if not registered

This commit is contained in:
Prateeksha Singh 2018-09-03 15:22:13 +05:30
parent 47cc30da85
commit 18e3c61109

View File

@ -20,23 +20,29 @@ import Messages from './pages/Messages.vue';
import Profile from './pages/Profile.vue'; import Profile from './pages/Profile.vue';
import NotFound from './pages/NotFound.vue'; import NotFound from './pages/NotFound.vue';
const route_map = { function get_route_map() {
'marketplace/home': Home, const read_only_routes = {
'marketplace/search/:keyword': Search, 'marketplace/home': Home,
'marketplace/category/:category': Category, 'marketplace/search/:keyword': Search,
'marketplace/item/:item': Item, 'marketplace/category/:category': Category,
'marketplace/seller/:seller': Seller, 'marketplace/item/:item': Item,
'marketplace/not-found': NotFound, 'marketplace/seller/:seller': Seller,
'marketplace/not-found': NotFound,
// Registered seller routes }
'marketplace/profile': Profile, const registered_routes = {
'marketplace/saved-items': SavedItems, 'marketplace/profile': Profile,
'marketplace/publish': Publish, 'marketplace/saved-items': SavedItems,
'marketplace/published-items': PublishedItems, 'marketplace/publish': Publish,
'marketplace/buying': Buying, 'marketplace/published-items': PublishedItems,
'marketplace/buying/:item': Messages, 'marketplace/buying': Buying,
'marketplace/selling': Selling, 'marketplace/buying/:item': Messages,
'marketplace/selling/:buyer/:item': Messages 'marketplace/selling': Selling,
'marketplace/selling/:buyer/:item': Messages
}
const hub_registered = hub.settings.registered;
return hub_registered
? Object.assign({}, read_only_routes, registered_routes)
: read_only_routes;
} }
export default { export default {
@ -56,6 +62,7 @@ export default {
this.current_page = this.get_current_page(); this.current_page = this.get_current_page();
}, },
get_current_page() { get_current_page() {
const route_map = get_route_map();
const curr_route = frappe.get_route_str(); const curr_route = frappe.get_route_str();
let route = Object.keys(route_map).filter(route => route == curr_route)[0]; let route = Object.keys(route_map).filter(route => route == curr_route)[0];
if (!route) { if (!route) {