Unverified Commit c32b9a57 authored by Juorder Gonzalez's avatar Juorder Gonzalez Committed by GitHub

Merge pull request #295 from ZBoxApp/fix-admin-disabled

fix revoke admins, now its working, new request for search admins for…
parents f28b9eec 3c1882f5
...@@ -37,38 +37,27 @@ export default class DomainAdminList extends React.Component { ...@@ -37,38 +37,27 @@ export default class DomainAdminList extends React.Component {
}; };
} }
getAdmins(getAllFromAPI) { getAdmins() {
const domain = this.props.domain; const { domain } = this.props;
const getStuffFromAPI = getAllFromAPI || false;
if (!getStuffFromAPI) { if (domain) {
return domain.getAdmins((err, data) => { return Client.getAdminByDomainName(domain.name, 'givenName, displayName, sn, cn').then(({ account: admins }) => {
const admins = data.account || []; this.setState({ admins });
if (this.isStoreEnabled) { }).catch();
DomainStore.setAdmins(domain, admins);
}
this.setState({admins});
});
} }
return Client.getDomain(domain.name, (data) => { return Client.getDomain(domain.name, (data) => {
return data.getAdmins((err, res) => { Client.getAdminByDomainName(data.name).then(({ account: admins }) => {
const admins = res.account || []; this.setState({ admins });
if (this.isStoreEnabled) { }).catch();
DomainStore.setAdmins(domain, admins);
}
return this.setState({admins});
});
}, (err) => { }, (err) => {
return err; return err;
}); });
} }
handleRemoveAdmin(e, admin) { handleRemoveAdmin(e, admin) {
const plans = Object.keys(window.manager_config.plans).filter((plan) => {
return window.manager_config.plans[plan].forRights;
});
e.preventDefault(); e.preventDefault();
const response = { const response = {
title: 'Se ha borrado con éxito', title: 'Se ha borrado con éxito',
type: 'success' type: 'success'
...@@ -86,28 +75,22 @@ export default class DomainAdminList extends React.Component { ...@@ -86,28 +75,22 @@ export default class DomainAdminList extends React.Component {
}, },
(isDeleted) => { (isDeleted) => {
if (isDeleted) { if (isDeleted) {
this.props.domain.removeAdmin( const { id } = admin;
admin.name, const { admins } = this.state;
plans,
(error) => { Client.revokeAdmin(id).then(() => {
if (error) { // let's remove the admin for state to avoid search it into api
response.title = 'Ha ocurrido un error.'; const nextAdmins = admins.filter((admin) => admin.id !== id);
response.type = 'error'; this.setState({ admins: nextAdmins });
response.confirmButtonText = 'Intentar de nuevo'; return sweetAlert(response);
response.confirmButtonColor = '#DD6B55'; }).catch(() => {
response.title = 'Ha ocurrido un error.';
return sweetAlert(response); response.type = 'error';
} response.confirmButtonText = 'Intentar de nuevo';
response.confirmButtonColor = '#DD6B55';
if (this.isStoreEnabled) {
DomainStore.removeAdmin(admin.id); return sweetAlert(response);
} else { });
DomainStore.emitAdminsChange();
}
return sweetAlert(response);
}
);
} }
} }
); );
...@@ -116,10 +99,10 @@ export default class DomainAdminList extends React.Component { ...@@ -116,10 +99,10 @@ export default class DomainAdminList extends React.Component {
onAdminsChange() { onAdminsChange() {
const admins = this.isStoreEnabled ? DomainStore.getAdmins(this.props.domain) : null; const admins = this.isStoreEnabled ? DomainStore.getAdmins(this.props.domain) : null;
if (!admins) { if (!admins) {
return this.getAdmins(true); return this.getAdmins();
} }
return this.setState({admins}); return this.setState({ admins });
} }
componentDidMount() { componentDidMount() {
...@@ -129,9 +112,11 @@ export default class DomainAdminList extends React.Component { ...@@ -129,9 +112,11 @@ export default class DomainAdminList extends React.Component {
this.getAdmins(); this.getAdmins();
} }
} }
componentWillUnmount() { componentWillUnmount() {
DomainStore.removeAdminsChangeListener(this.onAdminsChange); DomainStore.removeAdminsChangeListener(this.onAdminsChange);
} }
render() { render() {
let btnAddNewAdmin = null; let btnAddNewAdmin = null;
if (!this.state.admins) { if (!this.state.admins) {
......
...@@ -307,6 +307,51 @@ export function getDomain(id, success, error) { ...@@ -307,6 +307,51 @@ export function getDomain(id, success, error) {
); );
} }
export function getAdminByDomainName(domain, attributes) {
const searchObject = {
query: '(|(zimbraIsDelegatedAdminAccount=TRUE)(zimbraIsAdminAccount=TRUE))',
types: 'accounts',
maxResults: 0,
attrs: 'zimbraIsDelegatedAdminAccount,zimbraIsAdminAccount',
domain
};
if (attributes && typeof attributes === 'string') {
let _attributes = searchObject.attrs.split(',');
const customAttributes = attributes.split(',').map((attribute) => attribute.trim());
_attributes = [..._attributes, ...customAttributes];
searchObject.attrs = _attributes.join(',');
}
return new Promise((resolve, reject) => {
initZimbra().then(
(zimbra) => {
zimbra.directorySearch(searchObject, (err, data) => {
if (err) {
const e = handleError('getAdminByDomainName', err);
return reject(e);
}
return resolve(data);
});
},
(err) => {
const e = handleError('getAdminByDomainName', err);
return reject(e);
}
);
});
}
export function revokeAdmin(zimbraId) {
return new Promise((resolve, reject) => {
modifyAccount(zimbraId, {
zimbraIsDelegatedAdminAccount: 'FALSE',
zimbraIsAdminAccount: 'FALSE'
}, resolve, reject);
});
}
export function createDomain(domain, success, error) { export function createDomain(domain, success, error) {
initZimbra().then( initZimbra().then(
(zimbra) => { (zimbra) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment