mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: select definer in view creation/edit
This commit is contained in:
@ -4,6 +4,7 @@ import views from './views';
|
|||||||
import updates from './updates';
|
import updates from './updates';
|
||||||
import application from './application';
|
import application from './application';
|
||||||
import database from './database';
|
import database from './database';
|
||||||
|
import users from './users';
|
||||||
|
|
||||||
const connections = {};
|
const connections = {};
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ export default () => {
|
|||||||
tables(connections);
|
tables(connections);
|
||||||
views(connections);
|
views(connections);
|
||||||
database(connections);
|
database(connections);
|
||||||
|
users(connections);
|
||||||
updates();
|
updates();
|
||||||
application();
|
application();
|
||||||
};
|
};
|
||||||
|
15
src/main/ipc-handlers/users.js
Normal file
15
src/main/ipc-handlers/users.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { ipcMain } from 'electron';
|
||||||
|
|
||||||
|
export default (connections) => {
|
||||||
|
ipcMain.handle('get-users', async (event, uid) => {
|
||||||
|
try {
|
||||||
|
const result = await connections[uid].getUsers();
|
||||||
|
return { status: 'success', response: result };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (err.code === 'ER_TABLEACCESS_DENIED_ERROR')
|
||||||
|
return { status: 'success', response: [] };
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -145,9 +145,6 @@ export class MySQLClient extends AntaresCore {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// USERS
|
|
||||||
// TODO: SELECT `user`, `host`, IF(LENGTH(password)>0, password, authentication_string) AS `password` FROM `mysql`.`user`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: db.Database,
|
name: db.Database,
|
||||||
tables: remappedTables,
|
tables: remappedTables,
|
||||||
@ -267,6 +264,24 @@ export class MySQLClient extends AntaresCore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SELECT `user`, `host`, IF(LENGTH(password)>0, password, authentication_string) AS `password` FROM `mysql`.`user`
|
||||||
|
*
|
||||||
|
* @returns {Array.<Object>} users list
|
||||||
|
* @memberof MySQLClient
|
||||||
|
*/
|
||||||
|
async getUsers () {
|
||||||
|
const { rows } = await this.raw('SELECT `user`, `host`, IF(LENGTH(password)>0, password, authentication_string) AS `password` FROM `mysql`.`user`');
|
||||||
|
|
||||||
|
return rows.map(row => {
|
||||||
|
return {
|
||||||
|
name: row.user,
|
||||||
|
host: row.host,
|
||||||
|
password: row.password
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHOW CREATE VIEW
|
* SHOW CREATE VIEW
|
||||||
*
|
*
|
||||||
@ -308,7 +323,7 @@ export class MySQLClient extends AntaresCore {
|
|||||||
*/
|
*/
|
||||||
async alterView (params) {
|
async alterView (params) {
|
||||||
const { view } = params;
|
const { view } = params;
|
||||||
let sql = `ALTER ALGORITHM = ${view.algorithm} DEFINER=${view.definer} SQL SECURITY ${view.security} VIEW \`${view.oldName}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`;
|
let sql = `ALTER ALGORITHM = ${view.algorithm}${view.definer ? ` DEFINER=${view.definer}` : ''} SQL SECURITY ${view.security} VIEW \`${view.oldName}\` AS ${view.sql} ${view.updateOption ? `WITH ${view.updateOption} CHECK OPTION` : ''}`;
|
||||||
|
|
||||||
if (view.name !== view.oldName)
|
if (view.name !== view.oldName)
|
||||||
sql += `; RENAME TABLE \`${view.oldName}\` TO \`${view.name}\``;
|
sql += `; RENAME TABLE \`${view.oldName}\` TO \`${view.name}\``;
|
||||||
|
@ -27,13 +27,18 @@
|
|||||||
<div class="column col-6">
|
<div class="column col-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">{{ $t('word.definer') }}</label>
|
<label class="form-label">{{ $t('word.definer') }}</label>
|
||||||
<input
|
<select v-model="localView.definer" class="form-select">
|
||||||
v-model="localView.definer"
|
<option value="">
|
||||||
class="form-input"
|
{{ $t('message.currentUser') }}
|
||||||
type="text"
|
</option>
|
||||||
:placeholder="$t('message.currentUser')"
|
<option
|
||||||
readonly
|
v-for="user in workspace.users"
|
||||||
>
|
:key="`${user.name}@${user.host}`"
|
||||||
|
:value="`\`${user.name}\`@\`${user.host}\``"
|
||||||
|
>
|
||||||
|
{{ user.name }}@{{ user.host }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,12 +39,27 @@
|
|||||||
<div class="column col-3">
|
<div class="column col-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">{{ $t('word.definer') }}</label>
|
<label class="form-label">{{ $t('word.definer') }}</label>
|
||||||
<input
|
<select
|
||||||
|
v-if="workspace.users.length"
|
||||||
v-model="localView.definer"
|
v-model="localView.definer"
|
||||||
class="form-input"
|
class="form-select"
|
||||||
type="text"
|
|
||||||
readonly
|
|
||||||
>
|
>
|
||||||
|
<option value="">
|
||||||
|
{{ $t('message.currentUser') }}
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
v-for="user in workspace.users"
|
||||||
|
:key="`${user.name}@${user.host}`"
|
||||||
|
:value="`\`${user.name}\`@\`${user.host}\``"
|
||||||
|
>
|
||||||
|
{{ user.name }}@{{ user.host }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<select v-if="!workspace.users.length" class="form-select">
|
||||||
|
<option value="">
|
||||||
|
{{ $t('message.currentUser') }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
8
src/renderer/ipc-api/Users.js
Normal file
8
src/renderer/ipc-api/Users.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
'use strict';
|
||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
|
export default class {
|
||||||
|
static getUsers (params) {
|
||||||
|
return ipcRenderer.invoke('get-users', params);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import Connection from '@/ipc-api/Connection';
|
import Connection from '@/ipc-api/Connection';
|
||||||
import Database from '@/ipc-api/Database';
|
import Database from '@/ipc-api/Database';
|
||||||
|
import Users from '@/ipc-api/Users';
|
||||||
import { uidGen } from 'common/libs/uidGen';
|
import { uidGen } from 'common/libs/uidGen';
|
||||||
const tabIndex = [];
|
const tabIndex = [];
|
||||||
let lastBreadcrumbs = {};
|
let lastBreadcrumbs = {};
|
||||||
@ -100,6 +101,14 @@ export default {
|
|||||||
}
|
}
|
||||||
: workspace);
|
: workspace);
|
||||||
},
|
},
|
||||||
|
REFRESH_USERS (state, { uid, users }) {
|
||||||
|
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
|
||||||
|
? {
|
||||||
|
...workspace,
|
||||||
|
users
|
||||||
|
}
|
||||||
|
: workspace);
|
||||||
|
},
|
||||||
ADD_WORKSPACE (state, workspace) {
|
ADD_WORKSPACE (state, workspace) {
|
||||||
state.workspaces.push(workspace);
|
state.workspaces.push(workspace);
|
||||||
},
|
},
|
||||||
@ -221,6 +230,7 @@ export default {
|
|||||||
dispatch('refreshCollations', connection.uid);
|
dispatch('refreshCollations', connection.uid);
|
||||||
dispatch('refreshVariables', connection.uid);
|
dispatch('refreshVariables', connection.uid);
|
||||||
dispatch('refreshEngines', connection.uid);
|
dispatch('refreshEngines', connection.uid);
|
||||||
|
dispatch('refreshUsers', connection.uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -275,6 +285,18 @@ export default {
|
|||||||
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
|
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async refreshUsers ({ dispatch, commit }, uid) {
|
||||||
|
try {
|
||||||
|
const { status, response } = await Users.getUsers(uid);
|
||||||
|
if (status === 'error')
|
||||||
|
dispatch('notifications/addNotification', { status, message: response }, { root: true });
|
||||||
|
else
|
||||||
|
commit('REFRESH_USERS', { uid, users: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true });
|
||||||
|
}
|
||||||
|
},
|
||||||
removeConnected ({ commit }, uid) {
|
removeConnected ({ commit }, uid) {
|
||||||
Connection.disconnect(uid);
|
Connection.disconnect(uid);
|
||||||
commit('REMOVE_CONNECTED', uid);
|
commit('REMOVE_CONNECTED', uid);
|
||||||
@ -300,6 +322,7 @@ export default {
|
|||||||
structure: {},
|
structure: {},
|
||||||
variables: [],
|
variables: [],
|
||||||
collations: [],
|
collations: [],
|
||||||
|
users: [],
|
||||||
breadcrumbs: {}
|
breadcrumbs: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user