feat: warn user if it doesn't have message persistence permission
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Form, Label, Modal, Pagination, Table } from 'semantic-ui-react';
|
||||
import { API, openPage, showError, showSuccess } from '../helpers';
|
||||
import { API, openPage, showError, showSuccess, showWarning } from '../helpers';
|
||||
|
||||
import { ITEMS_PER_PAGE } from '../constants';
|
||||
|
||||
@@ -149,14 +149,36 @@ const MessagesTable = () => {
|
||||
})();
|
||||
};
|
||||
|
||||
const checkPermission = async () => {
|
||||
// Check global permission
|
||||
let res = await API.get('/api/status');
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
if (data.message_persistence) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check user permission
|
||||
{
|
||||
let res = await API.get('/api/user/self');
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (data.save_message_to_database !== 1) {
|
||||
showWarning('您没有消息持久化的权限,消息未保存,请联系管理员。');
|
||||
}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// TODO: Prompt the user if message persistence is disabled
|
||||
// TODO: Allow set persistence permission for each user
|
||||
loadMessages(0)
|
||||
.then()
|
||||
.catch((reason) => {
|
||||
showError(reason);
|
||||
});
|
||||
checkPermission().then();
|
||||
}, []);
|
||||
|
||||
const viewMessage = async (id) => {
|
||||
|
||||
@@ -85,6 +85,7 @@ const UsersTable = () => {
|
||||
newUsers[realIdx].status = user.status;
|
||||
newUsers[realIdx].role = user.role;
|
||||
newUsers[realIdx].send_email_to_others = user.send_email_to_others;
|
||||
newUsers[realIdx].save_message_to_database = user.save_message_to_database;
|
||||
}
|
||||
setUsers(newUsers);
|
||||
} else {
|
||||
@@ -295,6 +296,21 @@ const UsersTable = () => {
|
||||
? '撤回发送任意邮件的权限'
|
||||
: '授予发送任意邮件的权限'}
|
||||
</Dropdown.Item>
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
manageUser(
|
||||
user.username,
|
||||
user.save_message_to_database === 1
|
||||
? 'disallow_save_message_to_database'
|
||||
: 'allow_save_message_to_database',
|
||||
idx
|
||||
);
|
||||
}}
|
||||
>
|
||||
{user.save_message_to_database === 1
|
||||
? '撤回消息持久化的权限'
|
||||
: '授予消息持久化的权限'}
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</div>
|
||||
|
||||
@@ -2,5 +2,6 @@ export const toastConstants = {
|
||||
SUCCESS_TIMEOUT: 500,
|
||||
INFO_TIMEOUT: 3000,
|
||||
ERROR_TIMEOUT: 5000,
|
||||
WARNING_TIMEOUT: 10000,
|
||||
NOTICE_TIMEOUT: 20000
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@ export function isMobile() {
|
||||
}
|
||||
|
||||
let showErrorOptions = { autoClose: toastConstants.ERROR_TIMEOUT };
|
||||
let showWarningOptions = { autoClose: toastConstants.WARNING_TIMEOUT };
|
||||
let showSuccessOptions = { autoClose: toastConstants.SUCCESS_TIMEOUT };
|
||||
let showInfoOptions = { autoClose: toastConstants.INFO_TIMEOUT };
|
||||
let showNoticeOptions = { autoClose: false };
|
||||
@@ -74,6 +75,10 @@ export function showError(error) {
|
||||
}
|
||||
}
|
||||
|
||||
export function showWarning(message) {
|
||||
toast.warn(message, showWarningOptions);
|
||||
}
|
||||
|
||||
export function showSuccess(message) {
|
||||
toast.success(message, showSuccessOptions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user