mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 17:06:01 +00:00
admin access token
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
}
|
||||
const { accessToken } = resp;
|
||||
if (accessToken) {
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
localStorage.setItem(isAdminPage ? 'adminAccessToken' : 'accessToken', accessToken);
|
||||
if (isAdminPage) {
|
||||
internalRedirectTo('/?page=admin');
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiCall, enableApi } from './utility/api';
|
||||
import { getConfig } from './utility/metadataLoaders';
|
||||
import { isAdminPage } from './utility/pageDefs';
|
||||
|
||||
export function isOauthCallback() {
|
||||
const params = new URLSearchParams(location.search);
|
||||
@@ -41,7 +42,7 @@ export function handleOauthCallback() {
|
||||
|
||||
export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||
if (config.isAdminLoginForm && isAdminPage) {
|
||||
if (localStorage.getItem('accessToken')) {
|
||||
if (localStorage.getItem('adminAccessToken')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,15 +108,15 @@ export async function doLogout() {
|
||||
enableApi();
|
||||
const config = await getConfig();
|
||||
if (config.oauth) {
|
||||
localStorage.removeItem('accessToken');
|
||||
localStorage.removeItem(isAdminPage() ? 'adminAccessToken' : 'accessToken');
|
||||
if (config.oauthLogout) {
|
||||
window.location.href = config.oauthLogout;
|
||||
} else {
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
}
|
||||
} else if (config.isLoginForm) {
|
||||
localStorage.removeItem('accessToken');
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
localStorage.removeItem(isAdminPage() ? 'adminAccessToken' : 'accessToken');
|
||||
internalRedirectTo(`/?page=not-logged&is-admin=${isAdminPage() ? 'true' : ''}`);
|
||||
} else {
|
||||
window.location.href = 'config/logout';
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { getSettings, useConfig, useSettings } from './utility/metadataLoaders';
|
||||
import _ from 'lodash';
|
||||
import { safeJsonParse } from 'dbgate-tools';
|
||||
import { apiCall } from './utility/api';
|
||||
import { getOpenedTabsStorageName } from './utility/pageDefs';
|
||||
|
||||
export interface TabDefinition {
|
||||
title: string;
|
||||
@@ -86,7 +87,7 @@ export const temporaryOpenedConnections = writable([]);
|
||||
export const openedSingleDatabaseConnections = writable([]);
|
||||
export const expandedConnections = writable([]);
|
||||
export const currentDatabase = writable(null);
|
||||
export const openedTabs = writableWithForage<TabDefinition[]>([], 'openedTabs', x => [...(x || [])]);
|
||||
export const openedTabs = writableWithForage<TabDefinition[]>([], getOpenedTabsStorageName(), x => [...(x || [])]);
|
||||
export const copyRowsFormat = writableWithStorage('textWithoutHeaders', 'copyRowsFormat');
|
||||
export const extensions = writable<ExtensionsDirectory>(null);
|
||||
export const visibleCommandPalette = writable(null);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import _ from 'lodash';
|
||||
import { TabDefinition } from '../stores';
|
||||
import getElectron from './getElectron';
|
||||
import { getOpenedTabsStorageName } from './pageDefs';
|
||||
|
||||
let counter = 0;
|
||||
$: counterCopy = counter;
|
||||
@@ -26,15 +27,15 @@
|
||||
)
|
||||
) {
|
||||
try {
|
||||
let openedTabs = (await localforage.getItem<TabDefinition[]>('openedTabs')) || [];
|
||||
let openedTabs = (await localforage.getItem<TabDefinition[]>(getOpenedTabsStorageName())) || [];
|
||||
if (!_.isArray(openedTabs)) openedTabs = [];
|
||||
openedTabs = openedTabs
|
||||
.map(tab => (tab.closedTime ? tab : { ...tab, closedTime: new Date().getTime() }))
|
||||
.map(tab => ({ ...tab, selected: false }));
|
||||
await localforage.setItem('openedTabs', openedTabs);
|
||||
await localforage.setItem(getOpenedTabsStorageName(), openedTabs);
|
||||
await localStorage.setItem('selectedWidget', 'history');
|
||||
} catch (err) {
|
||||
localforage.removeItem('openedTabs');
|
||||
localforage.removeItem(getOpenedTabsStorageName());
|
||||
}
|
||||
// try {
|
||||
// await localforage.clear();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { getOpenedTabs, openedTabs } from '../stores';
|
||||
import _ from 'lodash';
|
||||
import getElectron from './getElectron';
|
||||
|
||||
export class LoadingToken {
|
||||
isCanceled = false;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import moment from 'moment';
|
||||
import localforage from 'localforage';
|
||||
import { getOpenedTabsStorageName } from './pageDefs';
|
||||
|
||||
export default async function localStorageGarbageCollector() {
|
||||
const openedTabsJson = await localforage.getItem('openedTabs');
|
||||
const openedTabsJson = await localforage.getItem(getOpenedTabsStorageName());
|
||||
let openedTabs = openedTabsJson ?? [];
|
||||
|
||||
const closeLimit = moment().add(-7, 'day').valueOf();
|
||||
|
||||
openedTabs = openedTabs.filter(x => !x.closedTime || x.closedTime > closeLimit);
|
||||
await localforage.setItem('openedTabs', openedTabs);
|
||||
await localforage.setItem(getOpenedTabsStorageName(), openedTabs);
|
||||
|
||||
const toRemove = [];
|
||||
for (const key in localStorage) {
|
||||
|
||||
15
packages/web/src/utility/pageDefs.ts
Normal file
15
packages/web/src/utility/pageDefs.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
let isAdminPageCache;
|
||||
|
||||
export function isAdminPage() {
|
||||
if (isAdminPageCache == null) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const urlPage = params.get('page');
|
||||
|
||||
isAdminPageCache = urlPage == 'admin';
|
||||
}
|
||||
return isAdminPageCache;
|
||||
}
|
||||
|
||||
export function getOpenedTabsStorageName() {
|
||||
return isAdminPage() ? 'adminOpenedTabs' : 'openedTabs';
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import getElectron from './getElectron';
|
||||
import { isAdminPage } from './pageDefs';
|
||||
|
||||
let apiUrl = null;
|
||||
try {
|
||||
@@ -16,7 +17,7 @@ export function resolveApiHeaders() {
|
||||
const electron = getElectron();
|
||||
|
||||
const res = {};
|
||||
const accessToken = localStorage.getItem('accessToken');
|
||||
const accessToken = localStorage.getItem(isAdminPage() ? 'adminAccessToken' : 'accessToken');
|
||||
if (accessToken) {
|
||||
res['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
|
||||
@@ -12,17 +12,20 @@
|
||||
} from '../stores';
|
||||
import mainMenuDefinition from '../../../../app/src/mainMenuDefinition';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
import { isAdminPage } from '../utility/pageDefs';
|
||||
|
||||
let domSettings;
|
||||
let domMainMenu;
|
||||
|
||||
const isAdmin = isAdminPage();
|
||||
|
||||
const widgets = [
|
||||
getCurrentConfig().storageDatabase && {
|
||||
icon: 'icon admin',
|
||||
name: 'admin',
|
||||
title: 'Administration',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon database',
|
||||
name: 'database',
|
||||
title: 'Database connections',
|
||||
@@ -31,32 +34,32 @@
|
||||
// icon: 'fa-table',
|
||||
// name: 'table',
|
||||
// },
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon file',
|
||||
name: 'file',
|
||||
title: 'Favorites & Saved files',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon history',
|
||||
name: 'history',
|
||||
title: 'Query history & Closed tabs',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon archive',
|
||||
name: 'archive',
|
||||
title: 'Archive (saved tabular data)',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon plugin',
|
||||
name: 'plugins',
|
||||
title: 'Extensions & Plugins',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon cell-data',
|
||||
name: 'cell-data',
|
||||
title: 'Selected cell data detail view',
|
||||
},
|
||||
{
|
||||
!isAdmin && {
|
||||
icon: 'icon app',
|
||||
name: 'app',
|
||||
title: 'Application layers',
|
||||
@@ -116,15 +119,17 @@
|
||||
|
||||
<div class="flex1"> </div>
|
||||
|
||||
<div
|
||||
class="wrapper"
|
||||
title={`Toggle whether tabs from all databases are visible. Currently - ${$lockedDatabaseMode ? 'NO' : 'YES'}`}
|
||||
on:click={() => {
|
||||
$lockedDatabaseMode = !$lockedDatabaseMode;
|
||||
}}
|
||||
>
|
||||
<FontIcon icon={$lockedDatabaseMode ? 'icon locked-database-mode' : 'icon unlocked-database-mode'} />
|
||||
</div>
|
||||
{#if !isAdmin}
|
||||
<div
|
||||
class="wrapper"
|
||||
title={`Toggle whether tabs from all databases are visible. Currently - ${$lockedDatabaseMode ? 'NO' : 'YES'}`}
|
||||
on:click={() => {
|
||||
$lockedDatabaseMode = !$lockedDatabaseMode;
|
||||
}}
|
||||
>
|
||||
<FontIcon icon={$lockedDatabaseMode ? 'icon locked-database-mode' : 'icon unlocked-database-mode'} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="wrapper" on:click={handleSettingsMenu} bind:this={domSettings}>
|
||||
<FontIcon icon="icon settings" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user