Skip to content

Commit

Permalink
Merge branch 'main' into BC-5119-Prevent-creating-new-neXboards-server
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk authored Nov 24, 2023
2 parents 3088581 + 25eead8 commit c0b4c46
Show file tree
Hide file tree
Showing 20 changed files with 603 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ansible/roles/h5p-library-management/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
galaxy_info:
role_name: h5p-library-management
author: Schul-Cloud Verbund
description: h5p library role for the management of libraries
company: Schul-Cloud Verbund
license: license (AGPLv3)
min_ansible_version: 2.8
galaxy_tags: []
dependencies: []
6 changes: 6 additions & 0 deletions ansible/roles/h5p-library-management/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: H5pLibraryManagement CronJob
when: WITH_H5P_LIBRARY_MANAGEMENT is defined and WITH_H5P_LIBRARY_MANAGEMENT|bool == true
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: api-h5p-library-management-cronjob.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: batch/v1
kind: CronJob
metadata:
namespace: {{ NAMESPACE }}
labels:
app: api-library-management-cronjob
name: api-library-management-cronjob
spec:
schedule: "{{ SERVER_H5P_LIBRARY_MANAGEMENT_CRONJOB|default("0 3 * * 3,6", true) }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
activeDeadlineSeconds: {{ SERVER_H5P_LIBRARY_MANAGEMENT_CRONJOB_TIMEOUT|default("39600", true) }}
template:
spec:
containers:
- name: api-h5p-library-management-cronjob
image: {{ SCHULCLOUD_SERVER_IMAGE }}:{{ SCHULCLOUD_SERVER_IMAGE_TAG }}
envFrom:
- configMapRef:
name: api-configmap
- secretRef:
name: api-secret
command: ['/bin/sh', '-c']
args: ['npm run nest:start:h5p:library-management']
resources:
limits:
cpu: {{ API_H5P_LIBRARY_MANAGEMENT_CPU_LIMITS|default("2000m", true) }}
memory: {{ API_H5P_LIBRARY_MANAGEMENT_MEMORY_LIMITS|default("2Gi", true) }}
requests:
cpu: {{ API_H5P_LIBRARY_MANAGEMENT_CPU_REQUESTS|default("100m", true) }}
memory: {{ API_H5P_LIBRARY_MANAGEMENT_MEMORY_REQUESTS|default("150Mi", true) }}
restartPolicy: OnFailure
31 changes: 31 additions & 0 deletions apps/server/src/apps/h5p-library-management.app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* istanbul ignore file */
/* eslint-disable no-console */
import { NestFactory } from '@nestjs/core';
import { install as sourceMapInstall } from 'source-map-support';
import { LegacyLogger } from '@src/core/logger';
import { H5PLibraryManagementModule, H5PLibraryManagementService } from '@modules/h5p-library-management';

async function bootstrap() {
sourceMapInstall();

const nestApp = await NestFactory.createApplicationContext(H5PLibraryManagementModule);

// WinstonLogger
nestApp.useLogger(await nestApp.resolve(LegacyLogger));

await nestApp.init();

console.log('#########################################');
console.log(`##### Start H5P Library Management ######`);
console.log('#########################################');

// to execute it on this place for the ORM the allowGlobalContext: true must be set, but to executed in this way is a hack
await nestApp.get(H5PLibraryManagementService).run();
// TODO: properly close app (there is some issue with the logger)
console.log('#########################################');
console.log(`##### Close H5P Library Management ######`);
console.log('#########################################');
await nestApp.close();
process.exit(0);
}
void bootstrap();
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { FileFieldsInterceptor } from '@nestjs/platform-express';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { Request, Response } from 'express';

import { H5PEditorUc } from '../uc/h5p.uc';

import {
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/modules/h5p-editor/h5p-editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const imports = [
password: DB_PASSWORD,
user: DB_USERNAME,
// Needs ALL_ENTITIES for authorization
allowGlobalContext: true,
entities: [...ALL_ENTITIES, H5PContent, H5pEditorTempFile, InstalledLibrary],
}),
ConfigModule.forRoot(createConfigModuleOptions(config)),
Expand All @@ -65,5 +66,6 @@ const providers = [
imports,
controllers,
providers,
exports: [ContentStorage, LibraryStorage],
})
export class H5PEditorModule {}
4 changes: 3 additions & 1 deletion apps/server/src/modules/h5p-editor/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './h5p-editor.module';
export { H5PEditorModule } from './h5p-editor.module';
export { ContentStorage, LibraryStorage } from './service';
export { s3ConfigContent, s3ConfigLibraries } from './h5p-editor.config';
4 changes: 2 additions & 2 deletions apps/server/src/modules/h5p-editor/uc/h5p.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ export class H5PEditorUc {
private changeUserType(currentUser: ICurrentUser): LumiIUser {
const user: LumiIUser = {
canCreateRestricted: false,
canInstallRecommended: true,
canUpdateAndInstallLibraries: true,
canInstallRecommended: false,
canUpdateAndInstallLibraries: false,
email: '',
id: currentUser.userId,
name: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { RabbitMQWrapperModule } from '@infra/rabbitmq';
import { S3ClientModule } from '@infra/s3-client';
import { createConfigModuleOptions } from '@src/config';
import { CoreModule } from '@src/core';
import { Logger } from '@src/core/logger';
import { H5PEditorModule, s3ConfigContent, s3ConfigLibraries } from '@modules/h5p-editor';
import { H5PLibraryManagementService, h5PLibraryManagementConfig } from './service';

const imports = [
ConfigModule.forRoot(createConfigModuleOptions(h5PLibraryManagementConfig)),
CoreModule,
H5PEditorModule,
RabbitMQWrapperModule,
S3ClientModule.register([s3ConfigContent, s3ConfigLibraries]),
];

const controllers = [];

const providers = [Logger, H5PLibraryManagementService];

@Module({
imports,
controllers,
providers,
exports: [],
})
export class H5PLibraryManagementModule {}
2 changes: 2 additions & 0 deletions apps/server/src/modules/h5p-library-management/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { H5PLibraryManagementModule } from './h5p-library-management.module';
export { H5PLibraryManagementService } from './service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { h5PLibraryManagementConfig } from './h5p-library-management.config';

describe('H5PLibraryManagementConfig', () => {
describe('h5PLibraryManagementConfig', () => {
describe('when h5PLibraryManagementConfig is called', () => {
it('should get Object s3ConfigLibraries', () => {
const config = h5PLibraryManagementConfig();
expect(config).toBeDefined();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Configuration } from '@hpi-schul-cloud/commons';

export interface IH5PLibraryManagementConfig {
H5P_EDITOR__LIBRARY_LIST_PATH: string;
}

export const config: IH5PLibraryManagementConfig = {
H5P_EDITOR__LIBRARY_LIST_PATH: Configuration.get('H5P_EDITOR__LIBRARY_LIST_PATH') as string,
};

export const h5PLibraryManagementConfig = () => config;
Loading

0 comments on commit c0b4c46

Please sign in to comment.