Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,8 @@ public function post_getFromDB()
public function post_addItem()
{
parent::post_addItem();

// Add right to current user - Hack to avoid login/logout
$_SESSION['glpiactiveentities'][$this->fields['id']] = $this->fields['id'];
$_SESSION['glpiactiveentities_string'] .= ",'" . $this->fields['id'] . "'";
// Root entity cannot be deleted, so if we added an entity this means GLPI is now multi-entity
$_SESSION['glpi_multientitiesmode'] = 1;
// We force the recursivity, so the new entity is visible in the current session
Session::changeActiveEntities(Session::getActiveEntity(), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check that the user is allowed to see recursive content?

I think the "add entity" action is only available for users that can see recursive content anyway but I guess it doesn't hurt to check twice here?

Not a mandatory change, just wondering out loud.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, we must only add the newly created entity to the active scope. The existing hack was probably incomplete, maybe only updating one or two more session variables is enough.

}

public function post_updateItem($history = true)
Expand Down
31 changes: 30 additions & 1 deletion tests/cypress/e2e/entity.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
let entity_id;

describe('Entity', () => {
beforeEach(() => {
cy.login();
});

it('Can configure assistance properties', () => {
const unique_id = (new Date()).getTime();
cy.createWithAPI("Entity", {
Expand All @@ -52,7 +56,6 @@ describe('Entity', () => {
});

it('Survey options change by type and rate', () => {
cy.login();
cy.visit(`/front/entity.form.php?id=1&forcetab=Entity$5`);
cy.findByLabelText('Configuring the satisfaction survey: Tickets').within(() => {
cy.getDropdownByLabelText('Configuring the satisfaction survey').selectDropdownValue('Internal survey');
Expand Down Expand Up @@ -103,4 +106,30 @@ describe('Entity', () => {
cy.findByLabelText('URL').should('be.visible');
});
});

it('Should be able to create a sub-subentity in a sub-entity context', () => {
const rand = Math.floor(Math.random() * 1000);
const subentity_name = `Subentity ${rand}`;

cy.visit(`/front/entity.form.php`);
cy.findByLabelText('Name').type(subentity_name);
cy.findByRole('button', {'name': "Add"}).click();

// We switch context to the newly created subentity
cy.openEntitySelector();
cy.get('.fancytree-expander[role=button]:visible').as('toggle_tree').click(); // From entities_selector tests.
cy.findByRole('gridcell', {'name': subentity_name}).findByRole('button').click();

cy.visit(`/front/entity.form.php`);
cy.intercept(`/front/entity.form.php`).as('formSent');

// We create the sub-subentity
cy.findByLabelText('Name').type(`Sub-${subentity_name}`);
cy.findByRole('button', {'name': "Add"}).click();

cy.wait('@formSent').then((interception) => {
expect(interception.response.statusCode).to.eq(302);
});
cy.findByRole('link', {name: 'User menu'}).children().children().should('contain.text', `${subentity_name} (tree structure)`);
});
});
Loading