Skip to content

Fix clean metadata #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/configs/tableConfigs/usersTableConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { User } from "../../slices/userSlice";
Copy link
Member

Choose a reason for hiding this comment

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

Dead import

import { TableConfig } from "./aclsTableConfig";

/**
Expand Down
45 changes: 25 additions & 20 deletions src/slices/userInfoSlice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PayloadAction, SerializedError, createSlice } from '@reduxjs/toolkit'
import axios from 'axios';
import axios, { AxiosError } from 'axios';
import { addNotification } from './notificationSlice';
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';

Expand Down Expand Up @@ -73,26 +73,31 @@ const initialState: UserInfoState = {
},
};

export const fetchUserInfo = createAppAsyncThunk('UserInfo/fetchUserInfo', async (_, { dispatch }) => {
// Just make the async request here, and return the response.
// This will automatically dispatch a `pending` action first,
// and then `fulfilled` or `rejected` actions based on the promise.
const res = await axios.get("/info/me.json")
.then((response) => {
return response.data;
})
.catch((response) => {
console.error(response);
dispatch(addNotification({type: "error", key: "USER_NOT_SAVED"}));
});

// Redirect to login if not in ROLE_ADMIN_UI
if (!(res.roles.includes('ROLE_ADMIN') || res.roles.includes('ROLE_ADMIN_UI'))) {
window.location.href = "/login.html";
export const fetchUserInfo = createAppAsyncThunk(
Copy link
Member

Choose a reason for hiding this comment

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

All changes in this file seem unrelated to the issue you are trying to fix. If you still feel like they belong in the codebase, please explain why they belong in this PR or submit them as another PR and state your intentions there,

'UserInfo/fetchUserInfo',
async (_, { dispatch }) => {
try {
const response = await axios.get("/info/me.json");
const res = response.data;
if (!res || !(res.roles?.includes('ROLE_ADMIN') || res.roles?.includes('ROLE_ADMIN_UI'))) {
window.location.href = "/login.html";
}
return res;
} catch (err: unknown) {
const error = err as AxiosError;
// eslint-disable-next-line no-trailing-spaces
console.error(error);
const status = error?.response?.status;
if (status === 401 || status === 403) {
window.location.href = "/login.html";
// eslint-disable-next-line no-trailing-spaces
}
dispatch(addNotification({ type: "error", key: "USER_NOT_SAVED" }));
throw error;
}
}

return res;
});
// eslint-disable-next-line no-trailing-spaces
);

export const fetchOcVersion = createAppAsyncThunk('UserInfo/fetchOcVersion', async () => {
const res = await axios.get("/sysinfo/bundles/version?prefix=opencast");
Expand Down
1 change: 1 addition & 0 deletions src/slices/userSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const fetchUsers = createAppAsyncThunk('users/fetchUsers', async (_, { ge
// This will automatically dispatch a `pending` action first,
// and then `fulfilled` or `rejected` actions based on the promise.
const res = await axios.get("/admin-ng/users/users.json", { params: params });
console.log("this is the response", res);
Copy link
Member

Choose a reason for hiding this comment

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

Superfluous logging statement.

return res.data;
});

Expand Down
67 changes: 37 additions & 30 deletions src/utils/resourceUtils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { getFilters, getTextFilter } from "../selectors/tableFilterSelectors";
import {getFilters, getTextFilter} from "../selectors/tableFilterSelectors";
import {
getPageLimit,
getPageOffset,
getTableDirectionForResource,
getTableSortingForResource,
} from "../selectors/tableSelectors";
import { TransformedAcl } from "../slices/aclDetailsSlice";
import { Acl } from "../slices/aclSlice";
import { NewUser } from "../slices/userSlice";
import { Recording } from "../slices/recordingSlice";
import { UserInfoState } from "../slices/userInfoSlice";
import { hasAccess, isJson } from "./utils";
import { RootState } from "../store";
import { MetadataCatalog, MetadataField } from "../slices/eventSlice";
import { initialFormValuesNewGroup } from '../configs/modalConfig';
import { UpdateUser } from '../slices/userDetailsSlice';
import { ParseKeys, TFunction } from 'i18next';
import { TableState } from "../slices/tableSlice";
import {TransformedAcl} from "../slices/aclDetailsSlice";
import {Acl} from "../slices/aclSlice";
import {NewUser} from "../slices/userSlice";
import {Recording} from "../slices/recordingSlice";
import {UserInfoState} from "../slices/userInfoSlice";
import {hasAccess, isJson} from "./utils";
import {RootState} from "../store";
import {MetadataCatalog, MetadataField} from "../slices/eventSlice";
import {initialFormValuesNewGroup} from '../configs/modalConfig';
import {UpdateUser} from '../slices/userDetailsSlice';
import {ParseKeys, TFunction} from 'i18next';
import {TableState} from "../slices/tableSlice";

/**
* This file contains methods that are needed in more than one resource thunk
Expand Down Expand Up @@ -166,22 +166,28 @@ export const transformMetadataFields = (metadata: MetadataField[]) => {
};

// transform metadata catalog for update via post request
export const transformMetadataForUpdate = (catalog: MetadataCatalog, values: { [key: string]: MetadataCatalog["fields"][0]["value"] }) => {
export const transformMetadataForUpdate = (
catalog: MetadataCatalog,
values: { [key: string]: MetadataCatalog["fields"][0]["value"] }
) => {
let fields: MetadataCatalog["fields"] = [];
let updatedFields: MetadataCatalog["fields"] = [];

let updatedFields: { id: string; value: unknown }[] = [];
catalog.fields.forEach((field) => {
if (field.value !== values[field.id]) {
let updatedField = {
...field,
value: values[field.id],
};
updatedFields.push(updatedField);
fields.push(updatedField);
} else {
fields.push({ ...field });
const newValue = values[field.id];

// update UI state with full field (optional)
const fullField = {...field, value: newValue};
fields.push(fullField);

// only include minimal clean data for backend if value changed
if (field.value !== newValue) {
updatedFields.push({
id: field.id,
value: newValue,
});
}
});

let data = new URLSearchParams();
data.append(
"metadata",
Expand All @@ -194,8 +200,7 @@ export const transformMetadataForUpdate = (catalog: MetadataCatalog, values: { [
])
);
const headers = getHttpHeaders();

return { fields, data, headers };
return {fields, data, headers};
};

// Prepare metadata for post of new events or series
Expand Down Expand Up @@ -247,7 +252,9 @@ export const prepareMetadataFieldsForPost = (
};

// returns the name for a field value from the collection
export const getMetadataCollectionFieldName = (metadataField: { collection?: { [key: string]: unknown }[] }, field: { value: unknown }, t: TFunction) => {
export const getMetadataCollectionFieldName = (metadataField: { collection?: { [key: string]: unknown }[] }, field: {
value: unknown
}, t: TFunction) => {
try {
if (!!metadataField.collection) {
const collectionField = metadataField.collection.find(
Expand All @@ -270,8 +277,8 @@ export const getMetadataCollectionFieldName = (metadataField: { collection?: { [
// Prepare rules of access policies for post of new events or series
export const prepareAccessPolicyRulesForPost = (policies: TransformedAcl[]) => {
// access policies for post request
let access : {
acl : Acl
let access: {
acl: Acl
} = {
acl: {
ace: [],
Expand Down
Loading