Skip to content

Commit

Permalink
Merge branch 'main' into BC-5863-remove-tiptap
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-darsow authored Nov 27, 2023
2 parents 0923549 + a2cc466 commit 21368e1
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
ToolApiFactory,
ToolApiInterface,
} from "@/serverApi/v3";
import { $axios } from "@/utils/api";
import { SchoolExternalToolMetadata } from "@/store/external-tool";
import { SchoolExternalToolMapper } from "@/store/external-tool/mapper";
import { $axios } from "@/utils/api";
import { AxiosResponse } from "axios";

export const useSchoolExternalToolApi = () => {
Expand All @@ -19,18 +19,10 @@ export const useSchoolExternalToolApi = () => {
schoolExternalToolId
);

if (
response.data.contextExternalToolCountPerContext.course ||
response.data.contextExternalToolCountPerContext.boardElement
) {
const mapped: SchoolExternalToolMetadata =
SchoolExternalToolMapper.mapSchoolExternalToolMetadata(response.data);
const mapped: SchoolExternalToolMetadata =
SchoolExternalToolMapper.mapSchoolExternalToolMetadata(response.data);

return mapped;
}
throw new Error(
"SchoolExternalToolMetadataResponse is missing required fields"
);
return mapped;
};

return {
Expand Down
9 changes: 4 additions & 5 deletions src/components/organisms/administration/AuthSystems.unit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import AuthSystems from "./AuthSystems";
import { schoolsModule, envConfigModule, authModule } from "@/store";
import { mockSchool } from "@@/tests/test-utils/mockObjects";
import { authModule, envConfigModule, schoolsModule } from "@/store";
import { mockSchool, mockUser } from "@@/tests/test-utils/mockObjects";
import setupStores from "@@/tests/test-utils/setupStores";
import { mockUser } from "@@/tests/test-utils/mockObjects";
import EnvConfigModule from "@/store/env-config";
import SchoolsModule from "@/store/schools";
import AuthModule from "@/store/auth";
Expand Down Expand Up @@ -223,7 +222,7 @@ describe("AuthSystems", () => {
// { _id: "1234", type: "sample system" }, // deletable: true, editable: false
expect(
tableCell.wrappers[2].find(searchStrings.deleteSystemButton).exists()
).toStrictEqual(true);
).toStrictEqual(false);
expect(
tableCell.wrappers[2].find(searchStrings.editSystemButton).exists()
).toStrictEqual(false);
Expand Down Expand Up @@ -338,7 +337,7 @@ describe("AuthSystems", () => {
expect(wrapper.vm.$data.confirmDeleteDialog.isOpen).toStrictEqual(false);
deleteButton.trigger("click");
expect(wrapper.vm.$data.confirmDeleteDialog.isOpen).toStrictEqual(true);
expect(wrapper.vm.$data.confirmDeleteDialog.systemId).toStrictEqual("1");
expect(wrapper.vm.$data.confirmDeleteDialog.systemId).toStrictEqual("3");
});
});
describe("display system buttons", () => {
Expand Down
11 changes: 4 additions & 7 deletions src/components/organisms/administration/AuthSystems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<v-icon>{{ iconMdiPencilOutline }}</v-icon>
</v-btn>
<v-btn
v-if="isRemovable(system) && hasSystemCreatePermission"
v-if="isEditable(system) && hasSystemCreatePermission"
class="delete-system-btn"
icon
:aria-label="ariaLabels(system).delete"
Expand Down Expand Up @@ -142,10 +142,10 @@
<script>
import { authModule, envConfigModule, schoolsModule } from "@/store";
import {
mdiCheckCircle,
mdiContentCopy,
mdiPencilOutline,
mdiTrashCanOutline,
mdiContentCopy,
mdiCheckCircle,
} from "@mdi/js";
import vCustomDialog from "@/components/organisms/vCustomDialog";
Expand Down Expand Up @@ -201,10 +201,7 @@ export default {
};
},
isEditable(system) {
return system.type === "ldap" && system.ldapConfig.provider === "general";
},
isRemovable(system) {
return system.type !== "ldap" || system.ldapConfig.provider === "general";
return system.ldapConfig?.provider === "general";
},
openConfirmDeleteDialog(systemId) {
this.confirmDeleteDialog = {
Expand Down
127 changes: 104 additions & 23 deletions src/serverApi/v3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,25 @@ export interface ContextExternalToolConfigurationTemplateResponse {
*/
version: number;
}
/**
*
* @export
* @interface ContextExternalToolCountPerContextResponse
*/
export interface ContextExternalToolCountPerContextResponse {
/**
*
* @type {number}
* @memberof ContextExternalToolCountPerContextResponse
*/
course: number;
/**
*
* @type {number}
* @memberof ContextExternalToolCountPerContextResponse
*/
boardElement: number;
}
/**
*
* @export
Expand Down Expand Up @@ -1633,10 +1652,10 @@ export interface ExternalToolMetadataResponse {
schoolExternalToolCount: number;
/**
*
* @type {SchoolExternalToolMetadataResponseContextExternalToolCountPerContext}
* @type {ContextExternalToolCountPerContextResponse}
* @memberof ExternalToolMetadataResponse
*/
contextExternalToolCountPerContext: SchoolExternalToolMetadataResponseContextExternalToolCountPerContext;
contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse;
}
/**
*
Expand Down Expand Up @@ -3923,29 +3942,10 @@ export interface SchoolExternalToolConfigurationTemplateResponse {
export interface SchoolExternalToolMetadataResponse {
/**
*
* @type {SchoolExternalToolMetadataResponseContextExternalToolCountPerContext}
* @type {ContextExternalToolCountPerContextResponse}
* @memberof SchoolExternalToolMetadataResponse
*/
contextExternalToolCountPerContext: SchoolExternalToolMetadataResponseContextExternalToolCountPerContext;
}
/**
*
* @export
* @interface SchoolExternalToolMetadataResponseContextExternalToolCountPerContext
*/
export interface SchoolExternalToolMetadataResponseContextExternalToolCountPerContext {
/**
*
* @type {number}
* @memberof SchoolExternalToolMetadataResponseContextExternalToolCountPerContext
*/
course?: number;
/**
*
* @type {number}
* @memberof SchoolExternalToolMetadataResponseContextExternalToolCountPerContext
*/
boardElement?: number;
contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse;
}
/**
*
Expand Down Expand Up @@ -12585,6 +12585,44 @@ export class SubmissionApi extends BaseAPI implements SubmissionApiInterface {
*/
export const SystemsApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @summary Deletes a system.
* @param {string} systemId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
systemControllerDeleteSystem: async (systemId: string, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'systemId' is not null or undefined
assertParamExists('systemControllerDeleteSystem', 'systemId', systemId)
const localVarPath = `/systems/{systemId}`
.replace(`{${"systemId"}}`, encodeURIComponent(String(systemId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication bearer required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)



setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* This endpoint is used to show users the possible login systems that exist. No sensible data should be returned!
* @summary Finds all publicly available systems.
Expand Down Expand Up @@ -12669,6 +12707,17 @@ export const SystemsApiAxiosParamCreator = function (configuration?: Configurati
export const SystemsApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = SystemsApiAxiosParamCreator(configuration)
return {
/**
*
* @summary Deletes a system.
* @param {string} systemId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async systemControllerDeleteSystem(systemId: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.systemControllerDeleteSystem(systemId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* This endpoint is used to show users the possible login systems that exist. No sensible data should be returned!
* @summary Finds all publicly available systems.
Expand Down Expand Up @@ -12702,6 +12751,16 @@ export const SystemsApiFp = function(configuration?: Configuration) {
export const SystemsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = SystemsApiFp(configuration)
return {
/**
*
* @summary Deletes a system.
* @param {string} systemId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
systemControllerDeleteSystem(systemId: string, options?: any): AxiosPromise<void> {
return localVarFp.systemControllerDeleteSystem(systemId, options).then((request) => request(axios, basePath));
},
/**
* This endpoint is used to show users the possible login systems that exist. No sensible data should be returned!
* @summary Finds all publicly available systems.
Expand Down Expand Up @@ -12732,6 +12791,16 @@ export const SystemsApiFactory = function (configuration?: Configuration, basePa
* @interface SystemsApi
*/
export interface SystemsApiInterface {
/**
*
* @summary Deletes a system.
* @param {string} systemId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SystemsApiInterface
*/
systemControllerDeleteSystem(systemId: string, options?: any): AxiosPromise<void>;

/**
* This endpoint is used to show users the possible login systems that exist. No sensible data should be returned!
* @summary Finds all publicly available systems.
Expand Down Expand Up @@ -12762,6 +12831,18 @@ export interface SystemsApiInterface {
* @extends {BaseAPI}
*/
export class SystemsApi extends BaseAPI implements SystemsApiInterface {
/**
*
* @summary Deletes a system.
* @param {string} systemId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof SystemsApi
*/
public systemControllerDeleteSystem(systemId: string, options?: any) {
return SystemsApiFp(this.configuration).systemControllerDeleteSystem(systemId, options).then((request) => request(this.axios, this.basePath));
}

/**
* This endpoint is used to show users the possible login systems that exist. No sensible data should be returned!
* @summary Finds all publicly available systems.
Expand Down
6 changes: 3 additions & 3 deletions src/store/external-tool/mapper/school-external-tool.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SchoolExternalTool,
SchoolExternalToolSave,
} from "../school-external-tool";
import { SchoolExternalToolMetadata } from "../school-external-tool-metadata";
import { SchoolExternalToolConfigurationTemplate } from "../tool-configuration-template";
import { ToolParameter } from "../tool-parameter";
import { ToolParameterEntry } from "../tool-parameter-entry";
Expand All @@ -19,7 +20,6 @@ import {
ToolConfigurationStatusMapping,
} from "./common-tool.mapper";
import { ExternalToolMapper } from "./external-tool.mapper";
import { SchoolExternalToolMetadata } from "../school-external-tool-metadata";

export class SchoolExternalToolMapper {
static mapToSchoolExternalToolConfigurationTemplate(
Expand Down Expand Up @@ -121,8 +121,8 @@ export class SchoolExternalToolMapper {
response: SchoolExternalToolMetadataResponse
): SchoolExternalToolMetadata {
const mapped: SchoolExternalToolMetadata = {
course: response.contextExternalToolCountPerContext.course!,
boardElement: response.contextExternalToolCountPerContext.boardElement!,
course: response.contextExternalToolCountPerContext.course,
boardElement: response.contextExternalToolCountPerContext.boardElement,
};

return mapped;
Expand Down
20 changes: 13 additions & 7 deletions src/store/schools.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
SystemsApiFactory,
SystemsApiInterface,
UserImportApiFactory,
UserImportApiInterface,
ValidationError,
} from "@/serverApi/v3";
import { authModule } from "@/store";
import { authModule, envConfigModule } from "@/store";
import { $axios } from "@/utils/api";
import { AxiosError } from "axios";
import { Action, Module, Mutation, VuexModule } from "vuex-module-decorators";
Expand Down Expand Up @@ -50,10 +51,6 @@ function transformSchoolClientToServer(school: School): SchoolPayload {
return { ...school, features: featureArray };
}

function isGracePeriodError(error: AxiosError<ValidationError>): boolean {
return !!error.response?.data.message.startsWith("grace_period_expired");
}

@Module({
name: "schoolsModule",
namespaced: true,
Expand Down Expand Up @@ -197,6 +194,7 @@ export default class SchoolsModule extends VuexModule {
return this.systems.some(
(system) =>
system.type === "tsp-school" ||
system.type === "oauth" ||
(system.type === "ldap" &&
(system.ldapConfig.provider === "iserv-idm" ||
system.ldapConfig.provider === "univention" ||
Expand Down Expand Up @@ -312,7 +310,11 @@ export default class SchoolsModule extends VuexModule {
async deleteSystem(systemId: string): Promise<void> {
this.setLoading(true);
try {
await $axios.delete(`v1/systems/${systemId}`);
if (envConfigModule.getEnv.FEATURE_NEST_SYSTEMS_API_ENABLED) {
await this.systemsApi.systemControllerDeleteSystem(systemId);
} else {
await $axios.delete(`v1/systems/${systemId}`);
}

const updatedSystemsList = this.systems.filter(
(system) => system._id !== systemId
Expand Down Expand Up @@ -392,4 +394,8 @@ export default class SchoolsModule extends VuexModule {
private get importUserApi(): UserImportApiInterface {
return UserImportApiFactory(undefined, "/v3", $axios);
}

private get systemsApi(): SystemsApiInterface {
return SystemsApiFactory(undefined, "/v3", $axios);
}
}
Loading

0 comments on commit 21368e1

Please sign in to comment.