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