Skip to content

Commit

Permalink
Merge pull request #32 from fleetbase/dev-v0.3.14
Browse files Browse the repository at this point in the history
v0.3.14 - implementing permission based locks into ui
  • Loading branch information
roncodes authored Aug 30, 2024
2 parents f148c4f + 16bcc68 commit 720a81a
Show file tree
Hide file tree
Showing 45 changed files with 13,134 additions and 9,436 deletions.
6 changes: 3 additions & 3 deletions addon/components/add-product-as-entity-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export default class AddProductAsEntityButtonComponent extends Component {
this.order.meta.pushObjects([
{
key: 'storefront',
value: selectedStorefront.name
value: selectedStorefront.name,
},
{
key: 'storefront_id',
value: selectedStorefront.public_id
}
value: selectedStorefront.public_id,
},
]);
}
})
Expand Down
4 changes: 3 additions & 1 deletion addon/components/modals/create-first-store.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
@name={{t "storefront.component.modals.create-first-store.storefront-name"}}
@value={{@options.store.name}}
@helpText={{t "storefront.component.modals.create-first-store.enter-name"}}
@disabled={{cannot "storefront create store"}}
/>
<InputGroup
@name={{t "storefront.component.modals.create-first-store.description"}}
@value={{@options.store.description}}
@helpText={{t "storefront.component.modals.create-first-store.brief-description"}}
@disabled={{cannot "storefront create store"}}
/>
<InputGroup
@name={{t "storefront.component.modals.create-first-store.currency"}}
@value={{@options.store.currency}}
@helpText={{t "storefront.component.modals.create-first-store.select-currency"}}
>
<CurrencySelect @currency={{@options.store.currency}} @onCurrencyChange={{fn (mut @options.store.currency)}} @triggerClass="w-full form-select" />
<CurrencySelect @currency={{@options.store.currency}} @onCurrencyChange={{fn (mut @options.store.currency)}} @triggerClass="w-full form-select" @disabled={{cannot "storefront create store"}} />
</InputGroup>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion addon/components/widget/storefront-key-metrics.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{else}}
<div class="grid grid-cols-2 lg:grid-cols-12 gap-4">
{{#each-in this.metrics as |title options|}}
<Dashboard::Count @title={{smart-humanize title}} @options={{options}} />
<Widget::Count @title={{smart-humanize title}} @options={{options}} class="lg:col-span-2 h-full" />
{{/each-in}}
</div>
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion addon/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class ApplicationController extends Controller {
@action createNewStorefront() {
return this.storefront.createNewStorefront({
onSuccess: () => {
const loader = this.loader.show({ loadingMessage: `Switching to newly created store...` });
const loader = this.loader.show({ loadingMessage: 'Switching to newly created store...' });

this.hostRouter.refresh().then(() => {
this.notifyPropertyChange('activeStore');
Expand Down
1 change: 1 addition & 0 deletions addon/controllers/products/index/category/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class ProductsIndexCategoryEditController extends ProductsIndexCa
@tracked overlayActionButtonTitle = 'Save Changes';
@tracked overlayActionButtonIcon = 'save';
@tracked overlayExitButtonTitle = 'Done';
abilityPermission = 'storefront update product';

get overlayTitle() {
return `Edit ${this.product.name}`;
Expand Down
8 changes: 6 additions & 2 deletions addon/controllers/products/index/category/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class ProductsIndexCategoryNewController extends BaseController {
@tracked uploadedFiles = [];
@tracked primaryFile = null;
@tracked isSaving = false;
abilityPermission = 'storefront create product';

/** overlay options */
@tracked overlayTitle = 'New Product';
Expand Down Expand Up @@ -66,10 +67,13 @@ export default class ProductsIndexCategoryNewController extends BaseController {

this.loader.removeLoader(loader);
this.notifications.success(this.intl.t('storefront.products.index.new.new-product-created-success'));

try {
yield this.transitionToRoute('products.index.category', category.slug);
} catch (error) {}
} catch (error) {
this.notifications.serverError(error);
}

this.reset();
}

Expand Down
17 changes: 14 additions & 3 deletions addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ export default class ApplicationRoute extends Route {
@service loader;
@service currentUser;
@service modalsManager;
// @service theme;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;
@service storefront;

@action loading(transition) {
this.loader.showOnInitialTransition(transition, 'section.next-view-section', { loadingMessage: 'Loading storefront...' });
}

@action error(error) {
this.notifications.serverError(error);
}

@action willTransition() {
this.modalsManager.done();
}

beforeModel() {
this.disableSandbox();
if (this.abilities.cannot('storefront see extension')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console');
}

this.disableSandbox();
return this.fetch.get('actions/store-count', {}, { namespace: 'storefront/int/v1' }).then(({ storeCount }) => {
// if no store count prompt to create a store
if (!storeCount) {
Expand All @@ -40,7 +51,7 @@ export default class ApplicationRoute extends Route {
}
}

@action disableSandbox() {
disableSandbox() {
this.currentUser.setOption('sandbox', false);
// this.theme.setEnvironment();
}
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/customers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import isNestedRouteTransition from '@fleetbase/ember-core/utils/is-nested-route
export default class CustomersIndexRoute extends Route {
@service store;
@service storefront;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

queryParams = {
page: { refreshModel: true },
Expand All @@ -29,6 +33,13 @@ export default class CustomersIndexRoute extends Route {
}
}

beforeModel() {
if (this.abilities.cannot('storefront list customer')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model(params) {
return this.store.query('customer', { ...params, storefront: this.storefront.getActiveStore('public_id') });
}
Expand Down
15 changes: 14 additions & 1 deletion addon/routes/customers/index/edit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class CustomersIndexEditRoute extends Route {}
export default class CustomersIndexEditRoute extends Route {
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

beforeModel() {
if (this.abilities.cannot('storefront update customer')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}
}
11 changes: 11 additions & 0 deletions addon/routes/customers/index/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import { inject as service } from '@ember/service';

export default class CustomersIndexViewRoute extends Route {
@service store;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

queryParams = {
view: { refreshModel: false },
};

beforeModel() {
if (this.abilities.cannot('storefront view customer')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model({ public_id }) {
return this.store.findRecord('contact', public_id);
}
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/networks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import isNestedRouteTransition from '@fleetbase/ember-core/utils/is-nested-route

export default class NetworksIndexRoute extends Route {
@service store;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

queryParams = {
page: { refreshModel: true },
Expand All @@ -22,6 +26,13 @@ export default class NetworksIndexRoute extends Route {
}
}

beforeModel() {
if (this.abilities.cannot('storefront list network')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model(params) {
return this.store.query('network', { with_gateways: 1, with_notification_channels: 1, ...params });
}
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/networks/index/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { inject as service } from '@ember/service';

export default class NetworksIndexNetworkRoute extends Route {
@service store;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

beforeModel() {
if (this.abilities.cannot('storefront view network')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model({ public_id }) {
return this.store.findRecord('network', public_id);
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import isNestedRouteTransition from '@fleetbase/ember-core/utils/is-nested-route
export default class OrdersIndexRoute extends Route {
@service store;
@service storefront;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

queryParams = {
page: { refreshModel: true },
Expand Down Expand Up @@ -33,6 +37,13 @@ export default class OrdersIndexRoute extends Route {
}
}

beforeModel() {
if (this.abilities.cannot('storefront list order')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model(params) {
return this.store.query('order', { ...params, storefront: this.storefront.getActiveStore('public_id') });
}
Expand Down
15 changes: 14 additions & 1 deletion addon/routes/orders/index/edit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class OrdersIndexEditRoute extends Route {}
export default class OrdersIndexEditRoute extends Route {
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

beforeModel() {
if (this.abilities.cannot('storefront update order')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}
}
15 changes: 14 additions & 1 deletion addon/routes/orders/index/new.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class OrdersIndexNewRoute extends Route {}
export default class OrdersIndexNewRoute extends Route {
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

beforeModel() {
if (this.abilities.cannot('storefront create order')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}
}
10 changes: 10 additions & 0 deletions addon/routes/orders/index/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ export default class OrdersIndexViewRoute extends Route {
@service notifications;
@service store;
@service socket;
@service intl;
@service abilities;
@service hostRouter;

@action error(error) {
this.notifications.serverError(error);
}

beforeModel() {
if (this.abilities.cannot('storefront view order')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model({ public_id }) {
const order = this.store.queryRecord('order', {
public_id,
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/products/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import isNestedRouteTransition from '@fleetbase/ember-core/utils/is-nested-route
export default class ProductsIndexRoute extends Route {
@service store;
@service currentUser;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;

@action willTransition(transition) {
this.controller.category = null;
Expand All @@ -16,6 +20,13 @@ export default class ProductsIndexRoute extends Route {
}
}

beforeModel() {
if (this.abilities.cannot('storefront list product')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model(params = {}) {
return this.store.query('category', {
for: 'storefront_product',
Expand Down
13 changes: 12 additions & 1 deletion addon/routes/products/index/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default class ProductsIndexCategoryRoute extends Route {
@service store;
@service currentUser;
@service loader;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;
@tracked categorySlug;

queryParams = {
Expand All @@ -26,10 +30,17 @@ export default class ProductsIndexCategoryRoute extends Route {
}
}

loading(transition) {
@action loading(transition) {
this.loader.showOnInitialTransition(transition, 'section.next-view-section', { loadingMessage: 'Loading products...' });
}

beforeModel() {
if (this.abilities.cannot('storefront list product')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model({ slug, ...params }) {
this.categorySlug = slug;

Expand Down
11 changes: 11 additions & 0 deletions addon/routes/products/index/category/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ import { filterHasManyForNewRecords } from '../../../../serializers/product';

export default class ProductsIndexCategoryEditRoute extends Route {
@service store;
@service intl;
@service abilities;
@service hostRouter;
@service notifications;
templateName = 'products.index.category.new';

beforeModel() {
if (this.abilities.cannot('storefront update product')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console.storefront');
}
}

model({ public_id }) {
return this.store.queryRecord('product', {
public_id,
Expand Down
Loading

0 comments on commit 720a81a

Please sign in to comment.