Skip to content

Commit

Permalink
Merge pull request #12 from fleetbase/dev-v0.0.13
Browse files Browse the repository at this point in the history
Implemented permission based restrictions and controls
  • Loading branch information
roncodes authored Aug 30, 2024
2 parents 856b720 + 405ca4b commit e75b37f
Show file tree
Hide file tree
Showing 32 changed files with 2,572 additions and 2,193 deletions.
10 changes: 8 additions & 2 deletions addon/components/extension-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class ExtensionCardComponent extends Component {
@service fetch;
@service stripe;
@service urlSearchParams;
@service abilities;
@tracked extension;

constructor(owner, { extension }) {
Expand All @@ -45,6 +46,11 @@ export default class ExtensionCardComponent extends Component {
const isAlreadyPurchased = this.extension.is_purchased === true;
const isAlreadyInstalled = this.extension.is_installed === true;
const isPaymentRequired = !isAuthor && this.extension.payment_required === true && isAlreadyPurchased === false;
const userCannotPurchase = isPaymentRequired && this.abilities.cannot('registry-bridge purchase extension');
let acceptButtonText = isPaymentRequired ? `Purchase for ${formatCurrency(this.extension.price, this.extension.currency)}` : isAlreadyInstalled ? 'Installed' : 'Install';
if (this.abilities.cannot('registry-bridge install extension')) {
acceptButtonText = 'Unauthorized to Install';
}
const goBack = async (modal) => {
await modal.done();
later(
Expand All @@ -65,9 +71,9 @@ export default class ExtensionCardComponent extends Component {
titleComponent: 'extension-modal-title',
modalClass: 'flb--extension-modal modal-lg',
modalHeaderClass: 'flb--extension-modal-header',
acceptButtonText: isPaymentRequired ? `Purchase for ${formatCurrency(this.extension.price, this.extension.currency)}` : isAlreadyInstalled ? 'Installed' : 'Install',
acceptButtonText,
acceptButtonIcon: isPaymentRequired ? 'credit-card' : isAlreadyInstalled ? 'check' : 'download',
acceptButtonDisabled: isAlreadyInstalled,
acceptButtonDisabled: this.abilities.cannot('registry-bridge install extension') || isAlreadyInstalled || userCannotPurchase,
acceptButtonScheme: isPaymentRequired ? 'success' : 'primary',
declineButtonText: 'Done',
process: null,
Expand Down
11 changes: 7 additions & 4 deletions addon/components/modals/extension-details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
</EmberWormhole>
{{/if}}
{{/if}}
<div>
<h3 class="dark:text-white font-semibold mb-1">{{t "registry-bridge.component.extension-details-modal.overview"}}</h3>
<div class="space-y-1">
<div class="space-y-3">
<div>
<h3 class="dark:text-white font-semibold mb-1">{{t "registry-bridge.component.extension-details-modal.description"}}</h3>
<p class="dark:text-gray-200 text-sm">{{this.extension.description}}</p>
<p class="dark:text-gray-200 text-sm">{{html-safe this.extension.promotional_text}}</p>
</div>
<div>
<h3 class="dark:text-white font-semibold mb-1">{{t "registry-bridge.component.extension-details-modal.overview"}}</h3>
<div class="extension-details-promo-content dark:text-gray-200 text-sm">{{html-safe this.extension.promotional_text}}</div>
</div>
</div>
<div>
Expand Down
2 changes: 2 additions & 0 deletions addon/controllers/installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class InstalledController extends Controller {
@service notifications;
@service socket;
@service hostRouter;
@service abilities;

@action about(extension) {
this.modalsManager.show('modals/extension-details', {
Expand All @@ -31,6 +32,7 @@ export default class InstalledController extends Controller {
acceptButtonText: 'Uninstall',
acceptButtonIcon: 'trash',
acceptButtonScheme: 'danger',
acceptButtonDisabled: this.abilities.cannot('registry-bridge uninstall extension'),
process: null,
step: null,
stepDescription: 'Awaiting uninstall to begin...',
Expand Down
2 changes: 1 addition & 1 deletion addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class RegistryBridgeEngine extends Engine {
};
setupExtension = function (app, engine, universe) {
// Register menu item in header
universe.registerHeaderMenuItem('Extensions', 'console.extensions', { icon: 'shapes', priority: 99 });
universe.registerHeaderMenuItem('Extensions', 'console.extensions', { icon: 'shapes', priority: 99, slug: 'registry-bridge' });
// Register admin controls
universe.registerAdminMenuPanel(
'Extensions Registry',
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/application.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 ApplicationRoute extends Route {
@service fetch;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

async setupController(controller) {
super.setupController(...arguments);
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/developers/analytics.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 DevelopersAnalyticsRoute extends Route {
@service store;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model() {
return this.store.query('registry-extension', { is_author: 1 });
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/developers/credentials.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 DevelopersCredentialsRoute extends Route {
@service fetch;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model() {
return this.fetch.get('auth/registry-tokens', {}, { namespace: '~registry/v1' });
Expand Down
15 changes: 14 additions & 1 deletion addon/routes/developers/extensions.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 DevelopersExtensionsRoute extends Route {}
export default class DevelopersExtensionsRoute extends Route {
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

beforeModel() {
if (this.abilities.cannot('registry-bridge list extension-bundle')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console');
}
}
}
11 changes: 11 additions & 0 deletions addon/routes/developers/extensions/edit.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 DevelopersExtensionsEditRoute extends Route {
@service store;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model(params) {
return this.store.queryRecord('registry-extension', { public_id: params.public_id, single: true });
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/developers/extensions/index.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 DevelopersExtensionsIndexRoute extends Route {
@service store;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model() {
return this.store.query('registry-extension', { is_author: 1 });
Expand Down
15 changes: 14 additions & 1 deletion addon/routes/developers/extensions/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 DevelopersExtensionsNewRoute extends Route {}
export default class DevelopersExtensionsNewRoute extends Route {
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

beforeModel() {
if (this.abilities.cannot('registry-bridge create extension-bundle')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console');
}
}
}
15 changes: 14 additions & 1 deletion addon/routes/developers/payments.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 DevelopersPaymentsRoute extends Route {}
export default class DevelopersPaymentsRoute extends Route {
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

beforeModel() {
if (this.abilities.cannot('registry-bridge list extension-payment')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console');
}
}
}
11 changes: 11 additions & 0 deletions addon/routes/developers/payments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { inject as service } from '@ember/service';

export default class DevelopersPaymentsIndexRoute extends Route {
@service fetch;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

queryParams = {
page: { refreshModel: true },
Expand All @@ -11,6 +15,13 @@ export default class DevelopersPaymentsIndexRoute extends Route {
query: { refreshModel: true },
};

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

model() {
return this.fetch.get('payments/author-received', {}, { namespace: '~registry/v1' });
}
Expand Down
9 changes: 8 additions & 1 deletion addon/routes/developers/payments/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import { inject as service } from '@ember/service';

export default class DevelopersPaymentsOnboardRoute extends Route {
@service fetch;
@service hostRouter;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

async beforeModel() {
if (this.abilities.cannot('registry-bridge onboard extension-payment')) {
this.notifications.warning(this.intl.t('common.unauthorized-access'));
return this.hostRouter.transitionTo('console');
}

try {
const { hasStripeConnectAccount } = await this.fetch.get('payments/has-stripe-connect-account', {}, { namespace: '~registry/v1' });
if (hasStripeConnectAccount) {
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/explore/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import { inject as service } from '@ember/service';

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

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

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

model({ slug }) {
return this.store.queryRecord('category', { slug, for: 'extension_category', core_category: 1, single: 1 });
}
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/explore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import { inject as service } from '@ember/service';

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

queryParams = {
query: {
refreshModel: true,
},
};

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

model(params) {
const { query } = params;
return this.store.query('registry-extension', { explore: 1, query });
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/installed.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 InstalledRoute extends Route {
@service fetch;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model(params = {}) {
return this.fetch.get('registry-extensions/installed', params, { namespace: '~registry/v1', normalizeToEmberData: true, modelType: 'registry-extension' });
Expand Down
11 changes: 11 additions & 0 deletions addon/routes/purchased.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 PurchasedRoute extends Route {
@service fetch;
@service notifications;
@service hostRouter;
@service abilities;
@service intl;

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

model(params = {}) {
return this.fetch.get('registry-extensions/purchased', params, { namespace: '~registry/v1', normalizeToEmberData: true, modelType: 'registry-extension' });
Expand Down
Loading

0 comments on commit e75b37f

Please sign in to comment.