Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: huridocs/uwazi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.188.7
Choose a base ref
...
head repository: huridocs/uwazi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.188.8
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 20, 2024

  1. AT entity creation event listener fix (#7387)

    not using permissions commandContext anymore, the listener gets executed
    in the same context as the entity creation, we are only separating this
    into a event listener / use case to decouple v1 and v2 codes.
    
    for some reason some of the entity saves at this point ocury without the
    entities having _id even though they where already created and in this
    case the special permission commandId gets replaced on the entities
    leaving them "corrupted" with a wrong id.
    
    this pr fixes the issue because we do not need to use the
    commandContext, but the original issue causing this potentially remains
    and should be understood.
    daneryl authored Oct 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    81e4b93 View commit details
  2. Bump version

    daneryl committed Oct 20, 2024
    Copy the full SHA
    5fc84c8 View commit details
Original file line number Diff line number Diff line change
@@ -46,15 +46,8 @@ export class RequestEntityTranslation {

async execute(entityInputModel: EntityInputModel | unknown) {
this.inputValidator.ensure(entityInputModel);
const atConfig = await this.ATConfigDS.get();
const atTemplateConfig = atConfig.templates.find(
t => t.template === entityInputModel.template?.toString()
);

const languageFrom = entityInputModel.language;
const languagesTo = atConfig.languages.filter(
language => language !== entityInputModel.language
);
const entity = Entity.fromInputModel(entityInputModel);
const { atTemplateConfig, languagesTo, atConfig, languageFrom } = await this.getConfig(entity);

if (
!atTemplateConfig ||
@@ -64,7 +57,6 @@ export class RequestEntityTranslation {
return;
}

const entity = Entity.fromInputModel(entityInputModel);
let updatedEntities = (await this.entitiesDS.getByIds([entity.sharedId]).all()).filter(
e => e.language !== languageFrom
);
@@ -105,4 +97,15 @@ export class RequestEntityTranslation {
})
);
}

private async getConfig(entity: Entity) {
const atConfig = await this.ATConfigDS.get();
const atTemplateConfig = atConfig.templates.find(
t => t.template === entity.template?.toString()
);

const languageFrom = entity.language;
const languagesTo = atConfig.languages.filter(language => language !== entity.language);
return { atTemplateConfig, languagesTo, atConfig, languageFrom };
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DefaultTransactionManager } from 'api/common.v2/database/data_source_defaults';
import { EntityCreatedEvent } from 'api/entities/events/EntityCreatedEvent';
import { EventsBus } from 'api/eventsbus';
import { permissionsContext } from 'api/permissions/permissionsContext';
import { AutomaticTranslationFactory } from '../../AutomaticTranslationFactory';
import { DefaultTransactionManager } from 'api/common.v2/database/data_source_defaults';

export class ATEntityCreationListener {
private eventBus: EventsBus;
@@ -24,7 +23,6 @@ export class ATEntityCreationListener {
).get();

if (active) {
permissionsContext.setCommandContext();
const entityFrom = event.entities.find(e => e.language === event.targetLanguageKey) || {};

entityFrom._id = entityFrom._id?.toString();
Original file line number Diff line number Diff line change
@@ -3,12 +3,10 @@ import { EntityCreatedEvent } from 'api/entities/events/EntityCreatedEvent';
import { EventsBus } from 'api/eventsbus';
import { AutomaticTranslationFactory } from 'api/externalIntegrations.v2/automaticTranslation/AutomaticTranslationFactory';
import { RequestEntityTranslation } from 'api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation';
import { permissionsContext } from 'api/permissions/permissionsContext';
import { tenants } from 'api/tenants';
import { appContext } from 'api/utils/AppContext';
import { getFixturesFactory } from 'api/utils/fixturesFactory';
import { testingEnvironment } from 'api/utils/testingEnvironment';
import { UserSchema } from 'shared/types/userType';
import { ATEntityCreationListener } from '../ATEntityCreationListener';

const factory = getFixturesFactory();
@@ -32,17 +30,14 @@ describe('ATEntityCreationListener', () => {
let listener: ATEntityCreationListener;
const eventBus: EventsBus = new EventsBus();
let executeSpy: jest.Mock<any, any, any>;
let userInContext: UserSchema | undefined = {} as UserSchema;

beforeEach(async () => {
await testingEnvironment.setUp({
settings: [{ features: { automaticTranslation: { active: false } } }],
});
await testingEnvironment.setTenant('tenant');

executeSpy = jest.fn().mockImplementation(() => {
userInContext = permissionsContext.getUserInContext();
});
executeSpy = jest.fn().mockImplementation(() => {});

listener = new ATEntityCreationListener(eventBus, prepareATFactory(executeSpy));
listener.start();
@@ -88,10 +83,6 @@ describe('ATEntityCreationListener', () => {
it('should execute RequestEntityTranslation on receiving entity creation event', async () => {
expect(executeSpy).toHaveBeenCalledWith(entityEn);
});

it('should execute RequestEntityTranslation with commandUser as its context user', async () => {
expect(userInContext).toBe(permissionsContext.commandUser);
});
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.188.7",
"version": "1.188.8",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"