mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
improvements
This commit is contained in:
1 parent
e92273d5f8
commit
130e62fbbf
5 files changed
+28
-15
No files matched your search
@@ -32,6 +32,7 @@ import { last } from '$lib/helpers/array';
|
||||
import { sizeToBytes, type Size } from '$lib/helpers/sizeConvertion';
|
||||
import { user } from './user';
|
||||
import { browser } from '$app/environment';
|
||||
import { canSeeBilling } from './roles';
|
||||
|
||||
export type Tier = 'tier-0' | 'tier-1' | 'tier-2';
|
||||
|
||||
@@ -116,6 +117,7 @@ export const failedInvoice = cachedStore<
|
||||
return {
|
||||
load: async (orgId) => {
|
||||
if (!isCloud) set(null);
|
||||
if(!get(canSeeBilling)) set(null);
|
||||
const invoices = await sdk.forConsole.billing.listInvoices(orgId);
|
||||
const failedInvoices = invoices.invoices.filter((i) => i.status === 'failed');
|
||||
// const failedInvoices = invoices.invoices;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { page } from '$app/stores';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export const roles = derived(page, ($page) => $page.data.roles);
|
||||
export const scopes = derived(page, ($page) => $page.data.scopes);
|
||||
export const roles = derived(page, ($page) => $page.data?.roles ?? []);
|
||||
export const scopes = derived(page, ($page) => $page.data?.scopes ?? []);
|
||||
|
||||
export const isDeveloper = derived(roles, ($roles) => $roles.includes('developer'));
|
||||
export const isBilling = derived(roles, ($roles) => $roles.includes('billing'));
|
||||
@@ -37,7 +37,10 @@ export const canWriteVcs = derived(scopes, ($scopes) => $scopes.includes('vcs.wr
|
||||
export const canWriteTopics = derived(scopes, ($scopes) => $scopes.includes('topics.write'));
|
||||
|
||||
export const canSeeBilling = derived(scopes, ($scopes) => $scopes.includes('billing.read'));
|
||||
export const canSeeProjects = derived(scopes, ($scopes) => $scopes.includes('projects.read'));
|
||||
export const canSeeProjects = derived(scopes, function ($scopes) {
|
||||
console.log($scopes);
|
||||
return $scopes.includes('projects.read');
|
||||
});
|
||||
export const canSeeDatabases = derived(scopes, ($scopes) => $scopes.includes('databases.read'));
|
||||
export const canSeeFunctions = derived(scopes, ($scopes) => $scopes.includes('functions.read'));
|
||||
export const canSeeBuckets = derived(scopes, ($scopes) => $scopes.includes('buckets.read'));
|
||||
|
||||
@@ -11,6 +11,7 @@ import ProjectsAtRisk from '$lib/components/billing/alerts/projectsAtRisk.svelte
|
||||
import { get } from 'svelte/store';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import { canSeeBilling } from '$lib/stores/roles';
|
||||
|
||||
export const load: LayoutLoad = async ({ params, depends }) => {
|
||||
depends(Dependencies.ORGANIZATION);
|
||||
@@ -21,15 +22,16 @@ export const load: LayoutLoad = async ({ params, depends }) => {
|
||||
|
||||
try {
|
||||
if (isCloud) {
|
||||
await failedInvoice.load(params.organization);
|
||||
|
||||
if (get(failedInvoice)) {
|
||||
headerAlert.add({
|
||||
show: true,
|
||||
component: ProjectsAtRisk,
|
||||
id: 'projectsAtRisk',
|
||||
importance: 1
|
||||
});
|
||||
if(get(canSeeBilling)) {
|
||||
await failedInvoice.load(params.organization);
|
||||
if (get(failedInvoice)) {
|
||||
headerAlert.add({
|
||||
show: true,
|
||||
component: ProjectsAtRisk,
|
||||
id: 'projectsAtRisk',
|
||||
importance: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const res = await sdk.forConsole.billing.getRoles(params.organization);
|
||||
|
||||
@@ -4,15 +4,17 @@ import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
|
||||
import { CARD_LIMIT, Dependencies } from '$lib/constants';
|
||||
import type { PageLoad } from './$types';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { canSeeProjects } from '$lib/stores/roles';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export const load: PageLoad = async ({ params, url, route, depends, parent }) => {
|
||||
const parentData = await parent();
|
||||
await parent();
|
||||
depends(Dependencies.ORGANIZATION);
|
||||
const page = getPage(url);
|
||||
const limit = getLimit(url, route, CARD_LIMIT);
|
||||
const offset = pageToOffset(page, limit);
|
||||
|
||||
if (!parentData.scopes.includes('projects.read')) {
|
||||
if (get(canSeeProjects)) {
|
||||
return redirect(301, `/console/organization-${params.organization}/billing`);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import { preferences } from '$lib/stores/preferences';
|
||||
import { failedInvoice } from '$lib/stores/billing';
|
||||
import { isCloud } from '$lib/system';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import { get } from 'svelte/store';
|
||||
import { canSeeBilling } from '$lib/stores/roles';
|
||||
|
||||
export const load: LayoutLoad = async ({ params, depends }) => {
|
||||
depends(Dependencies.PROJECT);
|
||||
@@ -19,7 +21,9 @@ export const load: LayoutLoad = async ({ params, depends }) => {
|
||||
var roles = [];
|
||||
var scopes = [];
|
||||
if (isCloud) {
|
||||
await failedInvoice.load(project.teamId);
|
||||
if(get(canSeeBilling)) {
|
||||
await failedInvoice.load(project.teamId);
|
||||
}
|
||||
const res = await sdk.forConsole.billing.getRoles(project.teamId);
|
||||
roles = res.roles;
|
||||
scopes = res.scopes;
|
||||
|
||||
Reference in new issue
Block a user