Browse Source

fix

old_master
Listat.an 5 years ago
parent
commit
4708d2d133
  1. 2
      __build.bat
  2. 46
      src/containers/Logs/actions.js
  3. 88
      src/containers/Logs/components/Contexmenu/index.jsx
  4. 10
      src/containers/Logs/components/Data/index.jsx
  5. 9
      src/containers/Logs/index.jsx
  6. 2
      src/containers/Logs/reducer.js
  7. 9
      src/containers/Profile/components/Actions/index.jsx
  8. 8
      src/containers/Task/components/Search/index.jsx
  9. 1
      src/containers/Taxonomy/actions.js
  10. 3
      src/containers/Taxonomy/components/Data/index.jsx
  11. 12
      src/containers/User/components/DataUser/index.jsx
  12. 8
      src/containers/User/components/Search/index.jsx
  13. 1
      src/lib/error.js

2
__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 yarn build

46
src/containers/Logs/actions.js

@ -4,19 +4,43 @@ import { getUsersNotification } from '../Layout/topbar/TopbarNotification/action
export function getLogs(filter) { export function getLogs(filter) {
return (dispatch) => { return async(dispatch) => {
dispatch({ type: 'SET_LOGS_IS_LOAD', status: false}); dispatch({ type: 'SET_LOGS_IS_LOAD', status: false});
return Promise.all([
restClient.find('logs', filter), try {
// restClient.get('task', 'count', filter), let data = await restClient.find('logs', filter);
]).then(([data, count, users]) => { let ban_ip = await restClient.get('ban', 'find');
dispatch({ type: 'GET_LOGS', data, filter, count: 0 }); dispatch({ type: 'GET_LOGS', data, filter, count: 0, ban_ip });
dispatch(getUsersNotification()); } catch (error) {
return null;
}).catch(err => {
dispatch({type: 'GET_LOGS', data: [], filter, count: 0}); 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);
}
}; };
} }

88
src/containers/Logs/components/Contexmenu/index.jsx

@ -4,14 +4,15 @@ import { Menu, Icon, Tooltip } from 'antd';
const Item = Menu.Item; const Item = Menu.Item;
const SubMenu = Menu.SubMenu; const SubMenu = Menu.SubMenu;
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { setLogSelectedIds } from '../../actions'; import { setLogSelectedIds, getLogs, banIp, deleteIp } from '../../actions';
import _ from 'lodash' import _ from 'lodash'
import { genTree, getPermissionCheck } from '../../../../lib/helper'; import { genTree, getPermissionCheck } from '../../../../lib/helper';
import moment from 'moment' import moment from 'moment'
import './style.scss' import './style.scss'
import Modal from '../../../../components/Modal' import Modal from '../../../../components/Modal'
import { Button, ButtonToolbar } from 'reactstrap'; import { Button, ButtonToolbar } from 'reactstrap';
setLogSelectedIds import { updateUser } from '../../../User/actions';
import { logoutUser } from '../../../Profile/actions';
class Contexmenu extends Component { class Contexmenu extends Component {
constructor(props) { constructor(props) {
@ -84,27 +85,44 @@ class Contexmenu extends Component {
} }
handleMenuClick = (e) => { handleMenuClick = (e) => {
let {item, profile, selectedUserIds, mode} = this.props; let {data, item} = this.props;
let user = {}; 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) { 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(); this.props.handleMenuClick();
break; break;
case 'notban':
case 'delete': if(log.user_id){
// this.props.deleteUser(selectedUserIds) this.props.updateUser(log.user_id.id, {is_ban: false});
this.setState({warningDelete: true}) this.props.getLogs({populate: 'user_id'});
}
this.props.handleMenuClick();
break; 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(); this.props.handleMenuClick();
break; break;
default: default:
this.props.handleMenuClick(); this.props.handleMenuClick();
break; break;
@ -112,13 +130,22 @@ class Contexmenu extends Component {
} }
render() { render() {
let {item, users, profile, selectedUserIds, mode} = this.props; let {item, users, profile, selectedUserIds, mode, data, ban_ip} = this.props;
if(!mode){ if(!mode){
mode = "vertical"; 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 ( return (
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}> <div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}>
@ -126,7 +153,7 @@ class Contexmenu extends Component {
<Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}> <Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}>
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 ? {getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && log.user_id && !log.user_id.is_ban ?
<Item key='isban'> <Item key='isban'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати користувача' : null}> <Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати користувача' : null}>
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати користувача' : null} <i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати користувача' : null}
@ -134,13 +161,29 @@ class Contexmenu extends Component {
</Item> </Item>
: null} : null}
{getPermissionCheck('user', 'update', profile) ? {getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && log.user_id && log.user_id.is_ban ?
<Item key='notban'> <Item key='notban'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати користувача' : null}> <Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати користувача' : null}>
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати користувача' : null} <i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати користувача' : null}
</Tooltip> </Tooltip>
</Item> </Item>
: null} : null}
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && find_index < 0 ?
<Item key='isban_ip'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати ip' : null}>
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати ip' : null}
</Tooltip>
</Item>
: null}
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && find_index > -1 ?
<Item key='notban_ip'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати ip' : null}>
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати ip' : null}
</Tooltip>
</Item>
: null}
</Menu> </Menu>
</div> </div>
@ -155,11 +198,18 @@ Contexmenu.propTypes = {
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
selectedUserIds: state.logs.log_selected_ids, selectedUserIds: state.logs.log_selected_ids,
data: state.logs.data,
ban_ip: state.logs.ban_ip,
profile: state.auth.profile, profile: state.auth.profile,
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
setLogSelectedIds setLogSelectedIds,
getLogs,
logoutUser,
updateUser,
banIp,
deleteIp,
} }
export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu) export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu)

10
src/containers/Logs/components/Data/index.jsx

@ -152,11 +152,11 @@ class Data extends Component {
key: 'ip', key: 'ip',
sortOrder: sortedInfo.columnKey === 'ip' && sortedInfo.order, sortOrder: sortedInfo.columnKey === 'ip' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.ip, b.ip), sorter: (a, b) => this.sortString(a.ip, b.ip),
// render: (text, record) => ( render: (text, record) => (
// <div> <div>
// {text} {text.replace('::ffff:', '')}
// </div> </div>
// ), ),
}, },
{ {
title: 'Подія', title: 'Подія',

9
src/containers/Logs/index.jsx

@ -10,6 +10,13 @@ class Logs extends Component {
} }
render() { render() {
const {profile} = this.props;
if(profile.role != 'admin'){
histoty.push('/');
return null;
}
return ( return (
<Container className="task"> <Container className="task">
<Row> <Row>
@ -28,7 +35,7 @@ class Logs extends Component {
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
profile: state.auth.profile
}) })
const mapDispatchToProps = { const mapDispatchToProps = {

2
src/containers/Logs/reducer.js

@ -4,6 +4,7 @@ import moment from 'moment'
const initialState = { const initialState = {
is_load: false, is_load: false,
data: [], data: [],
ban_ip: [],
log_selected_ids: [], log_selected_ids: [],
filter: {}, filter: {},
}; };
@ -14,6 +15,7 @@ export default function (state = initialState, action) {
case 'GET_LOGS': case 'GET_LOGS':
return {...state, return {...state,
data: action.data, data: action.data,
ban_ip: action.ban_ip,
is_load: true, is_load: true,
} }
case 'SET_LOGS_IS_LOAD': case 'SET_LOGS_IS_LOAD':

9
src/containers/Profile/components/Actions/index.jsx

@ -4,6 +4,7 @@ import {
} from 'reactstrap'; } from 'reactstrap';
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { updateUser, logoutUser } from '../../actions'; import { updateUser, logoutUser } from '../../actions';
import { getPermissionCheck } from '../../../../lib/helper';
class Actions extends Component { class Actions extends Component {
render() { render() {
@ -11,10 +12,18 @@ class Actions extends Component {
// if(!profile.id || profile.id == login_profile.id){ // if(!profile.id || profile.id == login_profile.id){
// return null; // return null;
// } // }
if(!getPermissionCheck('user', 'update', login_profile)){
return null;
}
return ( return (
<Col md={12} lg={12} xl={12}> <Col md={12} lg={12} xl={12}>
<Card> <Card>
<CardBody className="profile__card"> <CardBody className="profile__card">
<div>
Статус: {profile.is_ban ? "Заблокований" : "Не заблокований"}
</div>
<Button color={profile.is_ban ? "success" : "danger"} onClick={() => { <Button color={profile.is_ban ? "success" : "danger"} onClick={() => {
this.props.updateUser(profile.id, {is_ban: !profile.is_ban}); this.props.updateUser(profile.id, {is_ban: !profile.is_ban});
if(!profile.is_ban){ if(!profile.is_ban){

8
src/containers/Task/components/Search/index.jsx

@ -36,6 +36,14 @@ class SearchTask extends Component {
<Search <Search
placeholder="Пошук" placeholder="Пошук"
allowClear allowClear
onChange={(e) => {
let tmp_filter = _.cloneDeep(filter);
if(e.target.value == '' && tmp_filter.search){
delete tmp_filter.search;
this.props.getTasks(tmp_filter);
}
}}
onSearch={search => { onSearch={search => {
let tmp_filter = _.cloneDeep(filter); let tmp_filter = _.cloneDeep(filter);

1
src/containers/Taxonomy/actions.js

@ -22,6 +22,7 @@ export function deleteTaxonomy(id) {
dispatch({ type: 'DELETE_TAXONOMY', id }); dispatch({ type: 'DELETE_TAXONOMY', id });
return null; return null;
}).catch(err => { }).catch(err => {
console.log("TCL: deleteTaxonomy -> err", err)
return processError(err, dispatch); return processError(err, dispatch);
}); });
}; };

3
src/containers/Taxonomy/components/Data/index.jsx

@ -105,10 +105,9 @@ class Data extends Component {
columns.unshift({ columns.unshift({
title: 'Іконка', title: 'Іконка',
dataIndex: 'icon', dataIndex: 'icon',
width: 90,
key: 'icon', key: 'icon',
render: (text, record) => { render: (text, record) => {
return record.icon ? <img style={{maxHeight: 40, maxWidth: 40}} src={config.apiUrl + record.icon}/> : <img style={{maxHeight: 40, maxWidth: 40}} src={`${process.env.PUBLIC_URL}/img/group_icon.png`}/>; return record.icon ? <img style={{maxHeight: 30, maxWidth: 30}} src={config.apiUrl + record.icon}/> : <img style={{maxHeight: 30, maxWidth: 30}} src={`${process.env.PUBLIC_URL}/img/group_icon.png`}/>;
} }
}) })
} }

12
src/containers/User/components/DataUser/index.jsx

@ -121,7 +121,7 @@ class DataUser extends Component {
dataIndex: 'avatar', dataIndex: 'avatar',
key: 'avatar', key: 'avatar',
render: (text, record) => { render: (text, record) => {
return record.avatar ? <img style={{maxHeight: 30, maxWidth: 30}} src={config.apiUrl + record.avatar}/> : <img style={{maxHeight: 30, maxWidth: 30}} src={`${process.env.PUBLIC_URL}/img/default-avatar.jpg`}/>; return record.avatar ? <img style={{maxHeight: 30, width: 'auto'}} src={config.apiUrl + record.avatar}/> : <img style={{maxHeight: 30, width: 'auto'}} src={`${process.env.PUBLIC_URL}/img/default-avatar.jpg`}/>;
} }
}, },
{ {
@ -145,6 +145,16 @@ class DataUser extends Component {
sortOrder: sortedInfo.columnKey === 'email' && sortedInfo.order, sortOrder: sortedInfo.columnKey === 'email' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.email, b.email), sorter: (a, b) => this.sortString(a.email, b.email),
}, },
{
title: 'Статус',
dataIndex: 'is_ban',
key: 'is_ban',
sortOrder: sortedInfo.columnKey === 'is_ban' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.is_ban + '', b.is_ban+''),
render: (text, record) => {
return <div style={{whiteSpace: 'nowrap'}}>{text ? 'Заблоковано' : 'Не заблоковано'}</div>
}
},
{ {
title: 'Підприємство', title: 'Підприємство',

8
src/containers/User/components/Search/index.jsx

@ -35,6 +35,14 @@ class SearchUser extends Component {
<Search <Search
placeholder="Пошук" placeholder="Пошук"
allowClear allowClear
onChange={(e) => {
let tmp_filter = _.cloneDeep(filter);
if(e.target.value == '' && tmp_filter.search){
delete tmp_filter.search;
this.props.getUsers(tmp_filter);
}
}}
onSearch={search => { onSearch={search => {
let tmp_filter = _.cloneDeep(filter); let tmp_filter = _.cloneDeep(filter);

1
src/lib/error.js

@ -1,7 +1,6 @@
export default function processError(error, dispatch) { export default function processError(error, dispatch) {
if(error.status == 402){ if(error.status == 402){
dispatch({type: 'LOGOUT'});
dispatch({type: 'AUTH_IS_BAN', status: true}); dispatch({type: 'AUTH_IS_BAN', status: true});
return; return;
} }

Loading…
Cancel
Save