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. 86
      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 @@ @@ -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

46
src/containers/Logs/actions.js

@ -4,19 +4,43 @@ import { getUsersNotification } from '../Layout/topbar/TopbarNotification/action @@ -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);
}
};
}

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

@ -4,14 +4,15 @@ import { Menu, Icon, Tooltip } from 'antd'; @@ -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 { @@ -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 { @@ -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 (
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}>
@ -126,7 +153,7 @@ class Contexmenu extends Component { @@ -126,7 +153,7 @@ class Contexmenu extends Component {
<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'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати користувача' : null}>
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати користувача' : null}
@ -134,7 +161,7 @@ class Contexmenu extends Component { @@ -134,7 +161,7 @@ class Contexmenu extends Component {
</Item>
: null}
{getPermissionCheck('user', 'update', profile) ?
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && log.user_id && log.user_id.is_ban ?
<Item key='notban'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати користувача' : null}>
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати користувача' : null}
@ -142,6 +169,22 @@ class Contexmenu extends Component { @@ -142,6 +169,22 @@ class Contexmenu extends Component {
</Item>
: 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>
</div>
)
@ -155,11 +198,18 @@ Contexmenu.propTypes = { @@ -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)

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

@ -152,11 +152,11 @@ class Data extends Component { @@ -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) => (
// <div>
// {text}
// </div>
// ),
render: (text, record) => (
<div>
{text.replace('::ffff:', '')}
</div>
),
},
{
title: 'Подія',

9
src/containers/Logs/index.jsx

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

2
src/containers/Logs/reducer.js

@ -4,6 +4,7 @@ import moment from 'moment' @@ -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) { @@ -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':

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

@ -4,6 +4,7 @@ import { @@ -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 { @@ -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 (
<Col md={12} lg={12} xl={12}>
<Card>
<CardBody className="profile__card">
<div>
Статус: {profile.is_ban ? "Заблокований" : "Не заблокований"}
</div>
<Button color={profile.is_ban ? "success" : "danger"} onClick={() => {
this.props.updateUser(profile.id, {is_ban: !profile.is_ban});
if(!profile.is_ban){

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

@ -36,6 +36,14 @@ class SearchTask extends Component { @@ -36,6 +36,14 @@ class SearchTask extends Component {
<Search
placeholder="Пошук"
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 => {
let tmp_filter = _.cloneDeep(filter);

1
src/containers/Taxonomy/actions.js

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

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

@ -105,10 +105,9 @@ class Data extends Component { @@ -105,10 +105,9 @@ class Data extends Component {
columns.unshift({
title: 'Іконка',
dataIndex: 'icon',
width: 90,
key: 'icon',
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 { @@ -121,7 +121,7 @@ class DataUser extends Component {
dataIndex: 'avatar',
key: 'avatar',
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 { @@ -145,6 +145,16 @@ class DataUser extends Component {
sortOrder: sortedInfo.columnKey === 'email' && sortedInfo.order,
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: 'Підприємство',

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

@ -35,6 +35,14 @@ class SearchUser extends Component { @@ -35,6 +35,14 @@ class SearchUser extends Component {
<Search
placeholder="Пошук"
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 => {
let tmp_filter = _.cloneDeep(filter);

1
src/lib/error.js

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

Loading…
Cancel
Save