Skip to content

Commit

Permalink
Merge pull request #2740 from irontec/PROVIDER-1450-use-web-portals-f…
Browse files Browse the repository at this point in the history
…or-impersonation

Impersonation with webportal
  • Loading branch information
danigargar authored Sep 13, 2024
2 parents ab52992 + c3dcb05 commit d7cec06
Show file tree
Hide file tree
Showing 29 changed files with 468 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static function getPropertyMap(string $context = '', string $role = null)
'lastname' => 'lastname',
'email' => 'email'
];

if ($role === 'ROLE_BRAND_ADMIN') {
$response['company'] = 'company';
}
} else {
$response = parent::getPropertyMap(...func_get_args());
unset($response['internal']);
Expand Down
4 changes: 4 additions & 0 deletions library/Ivoz/Provider/Domain/Model/WebPortal/WebPortalDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getPropertyMap(string $context = '', string $role = null)
'baseName',
],
];

if ($role === 'ROLE_BRAND_ADMIN' || $role === 'ROLE_SUPER_ADMIN') {
$response['brand'] = 'brand';
}
} else {
$response = parent::getPropertyMap(...func_get_args());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CompaniesItem from '../../../fixtures/Provider/Companies/VirtualPbxs/getItem.json';
import newCompanies from '../../../fixtures/Provider/Companies/VirtualPbxs/post.json';
import editCompanies from '../../../fixtures/Provider/Companies/VirtualPbxs/put.json';
import webPortals from '../../../fixtures/Provider/WebPortals/getCollection.json';
import { MODE, testPbx } from '../utils/PbxsValidator';

export const postCompany = () => {
Expand Down Expand Up @@ -78,3 +79,23 @@ export const postWebPortal = () => {

cy.get('input[name="urlType"]').should('be.enabled');
};

export const checkImpersonationURL = () => {
cy.contains('Virtual PBXs').click();

const impersonationURLs = webPortals.body.map((wp) => wp.url);

cy.get('div.actions-cell a[target="_impersonate-client"]').as(
'impersonation-links'
);

cy.get('a[target="_impersonate-client"]')
.eq(0)
.should('have.attr', 'href')
.should('match', new RegExp(`${impersonationURLs[2]}.*`));

cy.get('@impersonation-links')
.eq(1)
.should('have.attr', 'href')
.should('match', new RegExp(`${impersonationURLs[0]}.*`));
};
86 changes: 54 additions & 32 deletions web/portal/brand/cypress/fixtures/apiSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,29 +417,35 @@
"type": "string"
},
{
"name": "email[neq]",
"name": "email[start]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "email[start]",
"name": "email[partial]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "email[partial]",
"name": "email[end]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "email[end]",
"name": "email[neq]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "exists[company]",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "exists[lastname]",
"in": "query",
Expand Down Expand Up @@ -477,34 +483,34 @@
"type": "string"
},
{
"name": "lastname[neq]",
"name": "lastname[end]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "lastname[start]",
"name": "lastname[exists]",
"in": "query",
"required": false,
"type": "string"
"type": "boolean"
},
{
"name": "lastname[partial]",
"name": "lastname[neq]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "lastname[end]",
"name": "lastname[start]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "lastname[exists]",
"name": "lastname[partial]",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "name",
Expand All @@ -524,12 +530,6 @@
"required": false,
"type": "string"
},
{
"name": "name[partial]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "name[end]",
"in": "query",
Expand All @@ -548,6 +548,12 @@
"required": false,
"type": "string"
},
{
"name": "name[partial]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "restricted",
"in": "query",
Expand Down Expand Up @@ -34692,6 +34698,12 @@
}
},
"parameters": [
{
"name": "brand",
"in": "query",
"required": false,
"type": "integer"
},
{
"name": "company",
"in": "query",
Expand Down Expand Up @@ -34764,12 +34776,6 @@
"required": false,
"type": "string"
},
{
"name": "logo.baseName[neq]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "logo.baseName[start]",
"in": "query",
Expand All @@ -34794,6 +34800,12 @@
"required": false,
"type": "boolean"
},
{
"name": "logo.baseName[neq]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "logo.fileSize",
"in": "query",
Expand Down Expand Up @@ -34855,31 +34867,31 @@
"type": "string"
},
{
"name": "logo.mimeType[start]",
"name": "logo.mimeType[end]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "logo.mimeType[partial]",
"name": "logo.mimeType[exists]",
"in": "query",
"required": false,
"type": "string"
"type": "boolean"
},
{
"name": "logo.mimeType[end]",
"name": "logo.mimeType[neq]",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "logo.mimeType[exists]",
"name": "logo.mimeType[start]",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "logo.mimeType[neq]",
"name": "logo.mimeType[partial]",
"in": "query",
"required": false,
"type": "string"
Expand Down Expand Up @@ -35410,7 +35422,8 @@
"active",
"restricted",
"username",
"email"
"email",
"company"
],
"properties": {
"id": {
Expand Down Expand Up @@ -35451,6 +35464,10 @@
"description": "",
"example": "",
"type": "string"
},
"company": {
"description": "",
"type": "integer"
}
}
},
Expand Down Expand Up @@ -46089,7 +46106,8 @@
"type": "object",
"required": [
"url",
"urlType"
"urlType",
"brand"
],
"properties": {
"id": {
Expand Down Expand Up @@ -46123,6 +46141,10 @@
"logo": {
"$ref": "#/definitions/WebPortal_Logo"
},
"brand": {
"description": "",
"type": "integer"
},
"company": {
"description": "",
"type": "integer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,50 @@ import {
import _ from '@irontec/ivoz-ui/services/translations/translate';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import { Tooltip } from '@mui/material';
import { WebPortalPropertiesList } from 'entities/WebPortal/WebPortalProperties';
import { useStoreState } from 'store';

const Impersonate: ActionFunctionComponent = (props: ActionItemProps) => {
const { row, entityService, variant = 'icon' } = props;
const token = useStoreState((state) => state.auth.token);
const customData = useStoreState((state) => state.list.customData);

if (!row) {
return null;
}

if (customData === undefined) {
return (
<>
{variant === 'text' && (
<MoreMenuItem disabled={true}>{_('Impersonate')}</MoreMenuItem>
)}
{variant === 'icon' && (
<StyledTableRowCustomCta disabled={true}>
<AdminPanelSettingsIcon />
</StyledTableRowCustomCta>
)}
</>
);
}

const companyUrl = customData.find(
(data: WebPortalPropertiesList) => data.company === row.companyId
)?.url;

const brandUrl = customData.find(
(data: WebPortalPropertiesList) => data.company === null
)?.url;

const impersonationUrl = companyUrl ? companyUrl : brandUrl;
const url = impersonationUrl ?? '';

const { username } = row;
const queryString = `username=${username}&token=${token}`;

return (
<StyledTableRowChildEntityLink
to={`/client/?${queryString}`}
to={`${url}/client/?${queryString}`}
parentEntity={entityService.getEntity()}
parentRow={row}
target='_impersonate-client'
Expand Down
7 changes: 2 additions & 5 deletions web/portal/brand/src/entities/Administrator/Administrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AdministratorProperties,
AdministratorPropertyList,
} from './AdministratorProperties';
import List from './List';

type marshallerType = typeof defaultMarshaller;
const marshaller: marshallerType = (row, properties, whitelist) => {
Expand Down Expand Up @@ -163,16 +164,12 @@ const Administrator: EntityInterface = {
},
ChildDecorator,
customActions: Actions,
List: List,
selectOptions: async () => {
const module = await import('./SelectOptions');

return module.default;
},
foreignKeyResolver: async () => {
const module = await import('./ForeignKeyResolver');

return module.default;
},
foreignKeyGetter: async () => {
const module = await import('./ForeignKeyGetter');

Expand Down
23 changes: 0 additions & 23 deletions web/portal/brand/src/entities/Administrator/ForeignKeyResolver.tsx

This file was deleted.

Loading

0 comments on commit d7cec06

Please sign in to comment.