diff --git a/__build.bat b/__build.bat
index c56b1e1..b5bd0ef 100644
--- a/__build.bat
+++ b/__build.bat
@@ -1,3 +1,3 @@
-SET REACT_APP_API_URL=https://api-devtasks.ubg.ua:1339
+SET REACT_APP_API_URL=https://api-devtasks.ubg.ua
yarn build
\ No newline at end of file
diff --git a/src/containers/Logs/actions.js b/src/containers/Logs/actions.js
index 24f6dec..7ec2609 100644
--- a/src/containers/Logs/actions.js
+++ b/src/containers/Logs/actions.js
@@ -4,19 +4,43 @@ import { getUsersNotification } from '../Layout/topbar/TopbarNotification/action
export function getLogs(filter) {
- return (dispatch) => {
+ return async(dispatch) => {
dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
- return Promise.all([
- restClient.find('logs', filter),
- // restClient.get('task', 'count', filter),
- ]).then(([data, count, users]) => {
- dispatch({ type: 'GET_LOGS', data, filter, count: 0 });
- dispatch(getUsersNotification());
- return null;
- }).catch(err => {
+
+ try {
+ let data = await restClient.find('logs', filter);
+ let ban_ip = await restClient.get('ban', 'find');
+ dispatch({ type: 'GET_LOGS', data, filter, count: 0, ban_ip });
+ } catch (error) {
dispatch({type: 'GET_LOGS', data: [], filter, count: 0});
- return processError(err, dispatch);
- });
+ return processError(error, dispatch);
+ }
+ };
+}
+
+export function banIp(data) {
+ return async(dispatch) => {
+ dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
+ try {
+ let ban_ip = await restClient.post('ban', 'create', data);
+ return;
+ } catch (error) {
+ dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
+ return processError(error, dispatch);
+ }
+ };
+}
+
+export function deleteIp(data) {
+ return async(dispatch) => {
+ dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
+ try {
+ let ban_ip = await restClient.post('ban', 'destroy', data);
+ return;
+ } catch (error) {
+ dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
+ return processError(error, dispatch);
+ }
};
}
diff --git a/src/containers/Logs/components/Contexmenu/index.jsx b/src/containers/Logs/components/Contexmenu/index.jsx
index e09ffa9..389beb3 100644
--- a/src/containers/Logs/components/Contexmenu/index.jsx
+++ b/src/containers/Logs/components/Contexmenu/index.jsx
@@ -4,14 +4,15 @@ import { Menu, Icon, Tooltip } from 'antd';
const Item = Menu.Item;
const SubMenu = Menu.SubMenu;
import { connect } from 'react-redux'
-import { setLogSelectedIds } from '../../actions';
+import { setLogSelectedIds, getLogs, banIp, deleteIp } from '../../actions';
import _ from 'lodash'
import { genTree, getPermissionCheck } from '../../../../lib/helper';
import moment from 'moment'
import './style.scss'
import Modal from '../../../../components/Modal'
import { Button, ButtonToolbar } from 'reactstrap';
-setLogSelectedIds
+import { updateUser } from '../../../User/actions';
+import { logoutUser } from '../../../Profile/actions';
class Contexmenu extends Component {
constructor(props) {
@@ -84,27 +85,44 @@ class Contexmenu extends Component {
}
handleMenuClick = (e) => {
- let {item, profile, selectedUserIds, mode} = this.props;
- let user = {};
+ let {data, item} = this.props;
+ console.log("TCL: Contexmenu -> handleMenuClick -> item", item)
-
+ let log = {};
+
+ data.some(log_item => {
+ if(log_item.id == item){
+ log = _.cloneDeep(log_item);
+ }
+ });
switch (e.key) {
- case 'update':
-
+ case 'isban':
+ if(log.user_id){
+ this.props.updateUser(log.user_id.id, {is_ban: true});
+ this.props.logoutUser(log.user_id.id);
+ this.props.getLogs({populate: 'user_id'});
+ }
this.props.handleMenuClick();
break;
-
- case 'delete':
- // this.props.deleteUser(selectedUserIds)
- this.setState({warningDelete: true})
+ case 'notban':
+ if(log.user_id){
+ this.props.updateUser(log.user_id.id, {is_ban: false});
+ this.props.getLogs({populate: 'user_id'});
+ }
+ this.props.handleMenuClick();
break;
- case 'new':
-
+ case 'isban_ip':
+ this.props.banIp({ip: log.ip});
+ this.props.getLogs({populate: 'user_id'});
+ this.props.handleMenuClick();
+ break;
+ case 'notban_ip':
+ this.props.deleteIp({ip: log.ip});
+ this.props.getLogs({populate: 'user_id'});
this.props.handleMenuClick();
break;
-
default:
this.props.handleMenuClick();
break;
@@ -112,13 +130,22 @@ class Contexmenu extends Component {
}
render() {
- let {item, users, profile, selectedUserIds, mode} = this.props;
-
+ let {item, users, profile, selectedUserIds, mode, data, ban_ip} = this.props;
if(!mode){
mode = "vertical";
}
+ let log = {};
+
+ data.some(log_item => {
+ if(log_item.id == item){
+ log = _.cloneDeep(log_item);
+ }
+ });
+
+ let find_index = _.findIndex(ban_ip, ['ip', log.ip])
+ console.log("TCL: Contexmenu -> render -> find_index", find_index)
return (
@@ -126,7 +153,7 @@ class Contexmenu extends Component {
@@ -155,11 +198,18 @@ Contexmenu.propTypes = {
const mapStateToProps = (state, ownProps) => ({
selectedUserIds: state.logs.log_selected_ids,
+ data: state.logs.data,
+ ban_ip: state.logs.ban_ip,
profile: state.auth.profile,
})
const mapDispatchToProps = {
- setLogSelectedIds
+ setLogSelectedIds,
+ getLogs,
+ logoutUser,
+ updateUser,
+ banIp,
+ deleteIp,
}
export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu)
\ No newline at end of file
diff --git a/src/containers/Logs/components/Data/index.jsx b/src/containers/Logs/components/Data/index.jsx
index 873a31d..d2b3251 100644
--- a/src/containers/Logs/components/Data/index.jsx
+++ b/src/containers/Logs/components/Data/index.jsx
@@ -152,11 +152,11 @@ class Data extends Component {
key: 'ip',
sortOrder: sortedInfo.columnKey === 'ip' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.ip, b.ip),
- // render: (text, record) => (
- //
- // {text}
- //
- // ),
+ render: (text, record) => (
+
+ {text.replace('::ffff:', '')}
+
+ ),
},
{
title: 'Подія',
diff --git a/src/containers/Logs/index.jsx b/src/containers/Logs/index.jsx
index 322a274..adf14eb 100644
--- a/src/containers/Logs/index.jsx
+++ b/src/containers/Logs/index.jsx
@@ -10,6 +10,13 @@ class Logs extends Component {
}
render() {
+ const {profile} = this.props;
+
+ if(profile.role != 'admin'){
+ histoty.push('/');
+ return null;
+ }
+
return (
@@ -28,7 +35,7 @@ class Logs extends Component {
const mapStateToProps = (state, ownProps) => ({
-
+ profile: state.auth.profile
})
const mapDispatchToProps = {
diff --git a/src/containers/Logs/reducer.js b/src/containers/Logs/reducer.js
index 6adcb3e..7512aef 100644
--- a/src/containers/Logs/reducer.js
+++ b/src/containers/Logs/reducer.js
@@ -4,6 +4,7 @@ import moment from 'moment'
const initialState = {
is_load: false,
data: [],
+ ban_ip: [],
log_selected_ids: [],
filter: {},
};
@@ -14,6 +15,7 @@ export default function (state = initialState, action) {
case 'GET_LOGS':
return {...state,
data: action.data,
+ ban_ip: action.ban_ip,
is_load: true,
}
case 'SET_LOGS_IS_LOAD':
diff --git a/src/containers/Profile/components/Actions/index.jsx b/src/containers/Profile/components/Actions/index.jsx
index 5e1d210..3cbe531 100644
--- a/src/containers/Profile/components/Actions/index.jsx
+++ b/src/containers/Profile/components/Actions/index.jsx
@@ -4,6 +4,7 @@ import {
} from 'reactstrap';
import { connect } from 'react-redux'
import { updateUser, logoutUser } from '../../actions';
+import { getPermissionCheck } from '../../../../lib/helper';
class Actions extends Component {
render() {
@@ -11,10 +12,18 @@ class Actions extends Component {
// if(!profile.id || profile.id == login_profile.id){
// return null;
// }
+
+ if(!getPermissionCheck('user', 'update', login_profile)){
+ return null;
+ }
+
return (
+
+ Статус: {profile.is_ban ? "Заблокований" : "Не заблокований"}
+