Skip to content

Commit

Permalink
Merge branch 'release/2.17.1'
Browse files Browse the repository at this point in the history
* release/2.17.1:
  bump version
  verify visualization by TYPE
  fix create sync rule for event charts and reports
  feat: add constantsModel. Update factory and MetadataEntities
  Update translations
  Update tests
  Get userAccesses and userGroupAccesses from sharing endpoint instead of directly from metaData because displayName is not in the response
  Update pull_request_template.md
  • Loading branch information
MiquelAdell committed May 6, 2024
2 parents 73f0a65 + e35cc50 commit d28c1ac
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

-

### :art: Screenshots
### :video_camera: Screenshots/Screen capture

### :fire: Is there anything the reviewer should know to test it?

Expand Down
4 changes: 2 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-06-12T22:53:44.873Z\n"
"PO-Revision-Date: 2023-06-12T22:53:44.873Z\n"
"POT-Creation-Date: 2024-04-16T06:03:13.568Z\n"
"PO-Revision-Date: 2024-04-16T06:03:13.568Z\n"

msgid ""
"THIS NEW RELEASE INCLUDES SHARING SETTINGS PER INSTANCES. FOR THIS VERSION "
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "metadata-synchronization",
"description": "Advanced metadata & data synchronization utility",
"version": "2.17.0",
"version": "2.17.1",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand Down
30 changes: 29 additions & 1 deletion src/data/metadata/MetadataD2ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,33 @@ export class MetadataD2ApiRepository implements MetadataRepository {
const response = await Promise.all(promises);
const results = _.deepMerge({}, ...response);
if (results.system) delete results.system;
return results;

const metadata = await this.validateEventVisualizationsByIds(results);
return metadata;
}

private async validateEventVisualizationsByIds(metadata: any) {
if (!metadata.eventCharts || !metadata.eventReports) return metadata;

const chartsMetadata = _(metadata.eventCharts)
.map(eventChart => {
return this.isEventReport(eventChart.type) ? undefined : eventChart;
})
.compact()
.value();

const eventReportsMetadata = _(metadata.eventReports)
.map(eventReport => {
return this.isEventReport(eventReport.type) ? eventReport : undefined;
})
.compact()
.value();

return { ...metadata, eventReports: eventReportsMetadata, eventCharts: chartsMetadata };
}

private isEventReport(visualizationType: D2VisualizationType): boolean {
return visualizationType === "PIVOT_TABLE" || visualizationType === "LINE_LIST";
}

private getApiModel(type: keyof MetadataEntities): Model<any, any> {
Expand Down Expand Up @@ -660,3 +686,5 @@ function getFilterAsString(filter: FilterBase): string[] {
)
);
}

type D2VisualizationType = "LINE_LIST" | "PIVOT_TABLE";
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ describe("Sync local instance mapped", () => {
id: "Db5532sXKXT",
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKXT",
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
externalAccess: false,
},
}));

const addAggregatedToDb = async (schema: Schema<AnyRegistry>, request: Request) => {
schema.db.dataValueSets.insert(JSON.parse(request.requestBody));

Expand Down
30 changes: 30 additions & 0 deletions src/data/metadata/__tests__/integration/sync-aggregated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,36 @@ describe("Sync aggregated", () => {
id: "Db5532sXKX1",
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKXT",
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
externalAccess: false,
},
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKX1",
externalAccess: false,
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
},
}));

const addAggregatedToDb = async (schema: Schema<AnyRegistry>, request: Request) => {
schema.db.dataValueSets.insert(JSON.parse(request.requestBody));

Expand Down
30 changes: 30 additions & 0 deletions src/data/metadata/__tests__/integration/sync-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,36 @@ describe("Sync events", () => {
id: "Db5532sXKX1",
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKXT",
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
externalAccess: false,
},
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKX1",
externalAccess: false,
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
},
}));

// local.get("/trackedEntityInstances", async () => ({
// trackedEntityInstances: [],
// }));
Expand Down
30 changes: 30 additions & 0 deletions src/data/metadata/__tests__/integration/sync-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ describe("Sync metadata", () => {
id: "Db5532sXKX1",
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKXT",
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
externalAccess: false,
},
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKX1",
externalAccess: false,
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
},
}));

const addMetadataToDb = async (schema: Schema<AnyRegistry>, request: Request) => {
schema.db.metadata.insert(JSON.parse(request.requestBody));

Expand Down
8 changes: 6 additions & 2 deletions src/data/storage/StorageDataStoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ export class StorageDataStoreClient extends StorageClient {
const metadata = await this.getMetadataByKey(key);
if (!metadata) return undefined;

const { object } = await this.api.sharing.get({ type: "dataStore", id: metadata.id }).getData();

if (!object) return undefined;

return {
user: { name: "", ...metadata.user },
userAccesses: metadata.userAccesses,
userGroupAccesses: metadata.userGroupAccesses,
userAccesses: object.userAccesses || [],
userGroupAccesses: object.userGroupAccesses || [],
publicAccess: metadata.publicAccess,
externalAccess: metadata.externalAccess,
};
Expand Down
30 changes: 30 additions & 0 deletions src/data/transformations/__tests__/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ export async function sync({
id: "Db5532sXKX1",
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKXT",
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
externalAccess: false,
},
}));

local.get("/sharing", async () => ({
meta: {
allowPublicAccess: true,
allowExternalAccess: false,
},
object: {
id: "Db5532sXKX1",
externalAccess: false,
publicAccess: "rw------",
user: { id: "H4atNsEuKxP" },
userGroupAccesses: [],
userAccesses: [],
},
}));

const addMetadataToDb = async (schema: Schema<AnyRegistry>, request: Request) => {
schema.db.metadata.insert(JSON.parse(request.requestBody));

Expand Down
1 change: 1 addition & 0 deletions src/domain/metadata/entities/MetadataEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5065,6 +5065,7 @@ export type MetadataEntities = {
categoryOptionCombos: CategoryOptionCombo[];
categoryOptionGroups: CategoryOptionGroup[];
categoryOptionGroupSets: CategoryOptionGroupSet[];
constants: Constant[];
charts: Chart[];
dashboards: Dashboard[];
dataApprovalLevels: DataApprovalLevel[];
Expand Down
1 change: 1 addition & 0 deletions src/models/dhis/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const metadataModels = [
metadataClasses.CategoryOptionComboModel,
metadataClasses.CategoryOptionGroupModel,
metadataClasses.CategoryOptionGroupSetModel,
metadataClasses.ConstantsModel,
metadataClasses.DashboardModel,
metadataClasses.DataElementModel,
metadataClasses.DataElementGroupModel,
Expand Down
5 changes: 5 additions & 0 deletions src/models/dhis/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ export class DataEntryFormModel extends D2Model {
protected static collectionName = "dataEntryForms" as const;
}

export class ConstantsModel extends D2Model {
protected static metadataType = "constants";
protected static collectionName = "constants" as const;
}

export class DataSetModel extends D2Model {
protected static metadataType = "dataSet";
protected static collectionName = "dataSets" as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ export const SummaryStepContent = (props: SummaryStepContentProps) => {
</LiEntry>

{_.keys(metadata).map(metadataType => {
//@ts-ignore
const modelByMetadataType = api.models[metadataType];
if (!modelByMetadataType) {
console.warn(`Metadata type "${metadataType}" not supported in d2-api`);
return null;
}
const itemsByType = metadata[metadataType as keyof MetadataEntities] || [];

const items = itemsByType.filter(({ id }) => !syncRule.excludedIds.includes(id));
Expand All @@ -225,8 +231,7 @@ export const SummaryStepContent = (props: SummaryStepContentProps) => {
items.length > 0 && (
<LiEntry
key={metadataType}
//@ts-ignore
label={`${api.models[metadataType].schema.displayName} [${items.length}]`}
label={`${modelByMetadataType.schema.displayName} [${items.length}]`}
>
<ul>
{items.map(({ id, name }) => (
Expand Down

0 comments on commit d28c1ac

Please sign in to comment.