aboutsummaryrefslogtreecommitdiff
path: root/src/site/store/admin.js
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-09 02:24:40 +0300
committerZephyrrus <[email protected]>2020-07-09 02:24:40 +0300
commitfd3f6de51a082dcd72c2ef557747e031ef7b9c4a (patch)
tree78e655286f6984b171604f3bc15e41eb52b01cef /src/site/store/admin.js
parentfix: register handler as a plugin (diff)
downloadhost.fuwn.me-fd3f6de51a082dcd72c2ef557747e031ef7b9c4a.tar.xz
host.fuwn.me-fd3f6de51a082dcd72c2ef557747e031ef7b9c4a.zip
refactor: refactor most of the admin pages to use the store instead of internal states
Diffstat (limited to 'src/site/store/admin.js')
-rw-r--r--src/site/store/admin.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/site/store/admin.js b/src/site/store/admin.js
index e69de29..2586a18 100644
--- a/src/site/store/admin.js
+++ b/src/site/store/admin.js
@@ -0,0 +1,93 @@
+export const state = () => ({
+ users: [],
+ user: {
+ id: null,
+ username: null,
+ enabled: false,
+ createdAt: null,
+ editedAt: null,
+ apiKeyEditedAt: null,
+ isAdmin: null,
+ files: [],
+ },
+ file: {},
+ settings: {},
+});
+
+export const actions = {
+ async fetchUsers({ commit }) {
+ const response = await this.$axios.$get('admin/users');
+ commit('setUsers', response);
+
+ return response;
+ },
+ async fetchUser({ commit }, id) {
+ const response = await this.$axios.$get(`/admin/users/${id}`);
+ commit('setUserInfo', response);
+
+ return response;
+ },
+ async enableUser({ commit }, id) {
+ const response = await this.$axios.$post('admin/users/enable', { id });
+
+ commit('changeUserState', { userId: id, enabled: true });
+
+ return response;
+ },
+ async disableUser({ commit }, id) {
+ const response = await this.$axios.$post('admin/users/disable', { id });
+
+ commit('changeUserState', { userId: id, enabled: false });
+
+ return response;
+ },
+ async promoteUser({ commit }, id) {
+ const response = await this.$axios.$post('admin/users/promote', { id });
+
+ commit('changeUserState', { userId: id, isAdmin: true });
+
+ return response;
+ },
+ async demoteUser({ commit }, id) {
+ const response = await this.$axios.$post('admin/users/demote', { id });
+
+ commit('changeUserState', { userId: id, isAdmin: false });
+
+ return response;
+ },
+ async purgeUserFiles(_, id) {
+ const response = await this.$axios.$post('admin/users/purge', { id });
+
+ return response;
+ },
+};
+
+export const mutations = {
+ setUsers(state, { users }) {
+ state.users = users;
+ },
+ setUserInfo(state, { user, files }) {
+ state.user = { ...state.user, ...user };
+ state.user.files = files || [];
+ },
+ changeUserState(state, { userId, enabled, isAdmin }) {
+ const foundIndex = state.users.findIndex(({ id }) => id === userId);
+ if (foundIndex > -1) {
+ if (enabled !== undefined) {
+ state.users[foundIndex].enabled = enabled;
+ }
+ if (isAdmin !== undefined) {
+ state.users[foundIndex].isAdmin = isAdmin;
+ }
+ }
+
+ if (state.user.id === userId) {
+ if (enabled !== undefined) {
+ state.user.enabled = enabled;
+ }
+ if (isAdmin !== undefined) {
+ state.user.isAdmin = isAdmin;
+ }
+ }
+ },
+};