Web: Client: refactoring accessRights code, added new translations, refactoring api requests

This commit is contained in:
Nikita Gopienko 2019-11-01 15:09:16 +03:00
parent 997d87251d
commit dc3ccbe7b7
6 changed files with 84 additions and 39 deletions

View File

@ -121,20 +121,26 @@ class PureAccessRights extends Component {
} }
componentDidMount() { componentDidMount() {
const { getListAdmins, getListUsers, getUserById, ownerId } = this.props; const {
getListAdmins,
getListUsers,
getUserById,
ownerId,
productId
} = this.props;
getUserById(ownerId).catch(error => { getUserById(ownerId).catch(error => {
toastr.error("accessRights getUserById", error); toastr.error(error);
//console.log("accessRights getUserById", error); //console.log("accessRights getUserById", error);
}); });
getListUsers().catch(error => { getListUsers().catch(error => {
toastr.error("accessRights getListAdmins", error); toastr.error(error);
//console.log("accessRights getListAdmins", error); //console.log("accessRights getListAdmins", error);
}); });
getListAdmins().catch(error => { getListAdmins(productId).catch(error => {
toastr.error("accessRights getListAdmins", error); toastr.error(error);
//console.log("accessRights getListAdmins", error); //console.log("accessRights getListAdmins", error);
}); });
} }
@ -176,6 +182,12 @@ class PureAccessRights extends Component {
const { showSelector, advancedOptions } = this.state; const { showSelector, advancedOptions } = this.state;
const OwnerOpportunities = t("AccessRightsOwnerOpportunities").split("|"); const OwnerOpportunities = t("AccessRightsOwnerOpportunities").split("|");
const countItems = [
{ key: 25, label: t("CountPerPage", { count: 25 }) },
{ key: 50, label: t("CountPerPage", { count: 50 }) },
{ key: 100, label: t("CountPerPage", { count: 100 }) }
];
return ( return (
<MainContainer> <MainContainer>
<HeaderContainer> <HeaderContainer>
@ -196,9 +208,12 @@ class PureAccessRights extends Component {
<Text.Body className="avatar_text" fontSize={16} isBold={true}> <Text.Body className="avatar_text" fontSize={16} isBold={true}>
{owner.displayName} {owner.displayName}
</Text.Body> </Text.Body>
<Text.Body className="avatar_text" fontSize={12}> {owner.groups &&
{owner.department} owner.groups.map(group => (
</Text.Body> <Link fontSize={12} key={group.id} href={owner.profileUrl}>
{group.name}
</Link>
))}
</div> </div>
</AvatarContainer> </AvatarContainer>
<ProjectsBody> <ProjectsBody>
@ -233,7 +248,6 @@ class PureAccessRights extends Component {
isOpen={showSelector} isOpen={showSelector}
placeholder="placeholder" placeholder="placeholder"
options={advancedOptions} options={advancedOptions}
//options={this.AdvancedSelectorFunction(users)}
onSearchChanged={this.onSearchUsers} onSearchChanged={this.onSearchUsers}
//groups={groups} //groups={groups}
isMultiSelect={true} isMultiSelect={true}
@ -252,8 +266,8 @@ class PureAccessRights extends Component {
<Avatar <Avatar
size="small" size="small"
role="admin" role="admin"
userName={user.userName} userName={user.displayName}
source={user.avatar} source={user.avatarSmall}
/> />
); );
const nameColor = const nameColor =
@ -270,13 +284,13 @@ class PureAccessRights extends Component {
<Link <Link
containerWidth="120px" containerWidth="120px"
type="page" type="page"
title={user.userName} title={user.displayName}
isBold={true} isBold={true}
fontSize={15} fontSize={15}
color={nameColor} color={nameColor}
href={user.profileUrl} href={user.profileUrl}
> >
{user.userName} {user.displayName}
</Link> </Link>
<div style={{ maxWidth: 120 }} /> <div style={{ maxWidth: 120 }} />
@ -303,15 +317,20 @@ class PureAccessRights extends Component {
{admins.length > 25 ? ( {admins.length > 25 ? (
<div className="wrapper"> <div className="wrapper">
<Paging <Paging
previousLabel="Previous" previousLabel={t("PreviousPage")}
nextLabel="Next" nextLabel={t("NextPage")}
openDirection="top"
displayItems={false}
countItems={countItems}
selectedPageItem={{ label: "1 of 1" }} selectedPageItem={{ label: "1 of 1" }}
selectedCountItem={{ label: "25 per page" }} selectedCountItem={{ label: "25 per page" }}
previousAction={() => console.log("Prev")} previousAction={() => console.log("previousAction")}
nextAction={() => console.log("Next")} nextAction={() => console.log("nextAction")}
openDirection="bottom"
onSelectPage={a => console.log(a)} onSelectPage={a => console.log(a)}
onSelectCount={a => console.log(a)} onSelectCount={a => console.log(a)}
//pageItems={pageItems}
//disablePrevious={!filter.hasPrev()}
//disableNext={!filter.hasNext()}
/> />
</div> </div>
) : null} ) : null}
@ -377,12 +396,22 @@ const AccessRights = props => {
); );
}; };
const filterOwner = (users, ownerId) => const filterUsers = (users, ownerId) =>
filter(users, function(f) { filter(users, function(f) {
return f.id !== ownerId; return f.id !== ownerId;
}); });
const filterAdminUsers = users => { const filterAdminUsers = users => {
return users.filter(user => user.listAdminModules === undefined); const newArray = [];
users.map(user => {
if (user.listAdminModules !== undefined) {
if (!user.listAdminModules.includes("people")) {
newArray.push(user);
}
} else {
newArray.push(user);
}
});
return newArray.filter(user => !user.isVisitor);
}; };
const AdvancedSelectorFunction = users => const AdvancedSelectorFunction = users =>
@ -396,12 +425,12 @@ const AdvancedSelectorFunction = users =>
function mapStateToProps(state) { function mapStateToProps(state) {
const { ownerId } = state.auth.settings; const { ownerId } = state.auth.settings;
const { admins, users } = state.settings; const { admins, users } = state.settings;
const arrayUsers = filterOwner(users, ownerId); const arrayUsers = filterUsers(users, ownerId);
const filterArrayUsers = filterAdminUsers(arrayUsers); const filterArrayUsers = filterAdminUsers(arrayUsers);
return { return {
users: filterArrayUsers, users: filterArrayUsers,
admins: filterOwner(admins, ownerId), admins: filterUsers(admins, ownerId),
productId: state.auth.modules[0].id, productId: state.auth.modules[0].id,
owner: state.settings.owner, owner: state.settings.owner,
ownerId, ownerId,
@ -414,7 +443,8 @@ AccessRights.defaultProps = {
admins: [], admins: [],
productId: "", productId: "",
ownerId: "", ownerId: "",
owner: {} owner: {},
advancedOptions: []
}; };
AccessRights.propTypes = { AccessRights.propTypes = {
@ -422,7 +452,8 @@ AccessRights.propTypes = {
admins: PropTypes.arrayOf(PropTypes.object), admins: PropTypes.arrayOf(PropTypes.object),
productId: PropTypes.string, productId: PropTypes.string,
ownerId: PropTypes.string, ownerId: PropTypes.string,
owner: PropTypes.object owner: PropTypes.object,
advancedOptions: PropTypes.arrayOf(PropTypes.object)
}; };
export default connect( export default connect(

View File

@ -23,6 +23,8 @@
"SuccessfullySaveSettingsMessage": "Settings have been successfully updated", "SuccessfullySaveSettingsMessage": "Settings have been successfully updated",
"NotFoundLanguage": "In case you cannot find your language in the list of the available ones, feel free to write to us at <1>{{supportEmail}}</1> to take part in the translation and get up to 1 year free of charge.", "NotFoundLanguage": "In case you cannot find your language in the list of the available ones, feel free to write to us at <1>{{supportEmail}}</1> to take part in the translation and get up to 1 year free of charge.",
"Settings": "Settings", "Settings": "Settings",
"PreviousPage": "Previous",
"NextPage": "Next",
@ -59,5 +61,6 @@
"Settings_integration": "Integration", "Settings_integration": "Integration",
"Settings_third-party-services": "Third-Party Services", "Settings_third-party-services": "Third-Party Services",
"Settings_smtp-settings": "SMTP Settings", "Settings_smtp-settings": "SMTP Settings",
"Settings_statistics": "Statistics" "Settings_statistics": "Statistics",
"CountPerPage": "{{count}} per page"
} }

View File

@ -22,6 +22,8 @@
"SuccessfullySaveSettingsMessage": "Настройки успешно обновлены", "SuccessfullySaveSettingsMessage": "Настройки успешно обновлены",
"NotFoundLanguage": "Если Вы не можете найти свой язык в списке доступных, Вы всегда можете написать нам по адресу <1>{{supportEmail}}</1>, чтобы принять участие в переводе и получить до 1 года бесплатного использования.", "NotFoundLanguage": "Если Вы не можете найти свой язык в списке доступных, Вы всегда можете написать нам по адресу <1>{{supportEmail}}</1>, чтобы принять участие в переводе и получить до 1 года бесплатного использования.",
"Settings": "Настройки", "Settings": "Настройки",
"PreviousPage": "Предыдущая",
"NextPage": "Следующая",
@ -58,5 +60,6 @@
"Settings_integration": "Интеграция", "Settings_integration": "Интеграция",
"Settings_third-party-services": "Сторонние сервисы", "Settings_third-party-services": "Сторонние сервисы",
"Settings_smtp-settings": "Настройки SMTP", "Settings_smtp-settings": "Настройки SMTP",
"Settings_statistics": "Статистика" "Settings_statistics": "Статистика",
"CountPerPage": "{{count}} на странице"
} }

View File

@ -83,6 +83,10 @@
], ],
"PeopleResource": [ "PeopleResource": [
"Settings" "Settings"
],
"UserControlsCommonResource": [
"NextPage",
"PreviousPage"
] ]
} }
}, },

View File

@ -149,15 +149,17 @@ export function getPortalTimezones() {
}); });
} }
export function getUserList(role) { export function getUserList() {
let params = "";
if(role === "admin") {
params = "/filter?isAdministrator=true";
}
return request({ return request({
method: "get", method: "get",
url: `/people${params}` url: `/people`
});
}
export function getProductAdminsList(productId) {
return request({
method: "get",
url: `/settings/security/administrator/${productId}`
}); });
} }

View File

@ -31,18 +31,20 @@ export function getListUsers() {
}; };
} }
export function getListAdmins() { export function getListAdmins(productId) {
return dispatch => { return dispatch => {
return api.getUserList("admin").then(admins => dispatch(setAdmins(admins))); return api
.getProductAdminsList(productId)
.then(admins => dispatch(setAdmins(admins)));
}; };
} }
export function changeAdmins(userId, productId, isAdmin) { export function changeAdmins(userId, productId, isAdmin) {
return dispatch => { return dispatch => {
return api return api.changeProductAdmin(userId, productId, isAdmin).then(() => {
.changeProductAdmin(userId, productId, isAdmin) dispatch(getListUsers());
.then(() => dispatch(getListUsers())) dispatch(getListAdmins(productId));
.then(() => dispatch(getListAdmins())); });
}; };
} }