Skip to content

Commit

Permalink
Merge branch 'main' into BC-6871-board-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac authored Jun 13, 2024
2 parents 79c3ac1 + 40f283a commit e5f7ae7
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Collaborative Text Editor Controller (API)', () => {
const basePath = Configuration.get('ETHERPAD__PAD_URI') as string;
const expectedPath = `${basePath}/${editorId}`;

const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD_COOKIE_EXPIRES_SECONDS')) * 1000;
const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD__COOKIE_EXPIRES_SECONDS')) * 1000;
// Remove the last 8 characters from the string to prevent conflict between time of test and code execution
const sessionCookieExpiryDate = new Date(Date.now() + cookieExpiresMilliseconds).toUTCString().slice(0, -8);

Expand Down Expand Up @@ -202,7 +202,7 @@ describe('Collaborative Text Editor Controller (API)', () => {
const basePath = Configuration.get('ETHERPAD__PAD_URI') as string;
const expectedPath = `${basePath}/${editorId}`;

const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD_COOKIE_EXPIRES_SECONDS')) * 1000;
const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD__COOKIE_EXPIRES_SECONDS')) * 1000;
// Remove the last 8 characters from the string to prevent conflict between time of test and code execution
const sessionCookieExpiryDate = new Date(Date.now() + cookieExpiresMilliseconds).toUTCString().slice(0, -8);

Expand Down Expand Up @@ -273,7 +273,7 @@ describe('Collaborative Text Editor Controller (API)', () => {
const basePath = Configuration.get('ETHERPAD__PAD_URI') as string;
const expectedPath = `${basePath}/${editorId}`;

const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD_COOKIE_EXPIRES_SECONDS')) * 1000;
const cookieExpiresMilliseconds = Number(Configuration.get('ETHERPAD__COOKIE_EXPIRES_SECONDS')) * 1000;
// Remove the last 8 characters from the string to prevent conflict between time of test and code execution
const sessionCookieExpiryDate = new Date(Date.now() + cookieExpiresMilliseconds).toUTCString().slice(0, -8);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface CollaborativeTextEditorConfig {
ETHERPAD_COOKIE_EXPIRES_SECONDS: number;
ETHERPAD_COOKIE_RELEASE_THRESHOLD: number;
ETHERPAD__COOKIE_EXPIRES_SECONDS: number;
ETHERPAD__COOKIE_RELEASE_THRESHOLD: number;
ETHERPAD__PAD_URI: string;
}
4 changes: 2 additions & 2 deletions apps/server/src/modules/collaborative-text-editor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { EtherpadClientConfig } from '@src/infra/etherpad-client';

export const etherpadClientConfig: EtherpadClientConfig = {
apiKey: Configuration.has('ETHERPAD_API_KEY') ? (Configuration.get('ETHERPAD_API_KEY') as string) : undefined,
basePath: Configuration.has('ETHERPAD_URI') ? (Configuration.get('ETHERPAD_URI') as string) : undefined,
apiKey: Configuration.has('ETHERPAD__API_KEY') ? (Configuration.get('ETHERPAD__API_KEY') as string) : undefined,
basePath: Configuration.has('ETHERPAD__URI') ? (Configuration.get('ETHERPAD__URI') as string) : undefined,
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CollaborativeTextEditorService {
params: GetCollaborativeTextEditorForParentParams
): Promise<CollaborativeTextEditor> {
const sessionExpiryDate = this.buildSessionExpiryDate();
const durationThreshold = Number(this.configService.get('ETHERPAD_COOKIE_RELEASE_THRESHOLD'));
const durationThreshold = Number(this.configService.get('ETHERPAD__COOKIE_RELEASE_THRESHOLD'));
const { parentId } = params;

const groupId = await this.collaborativeTextEditorAdapter.getOrCreateGroupId(parentId);
Expand Down Expand Up @@ -62,7 +62,7 @@ export class CollaborativeTextEditorService {
}

private buildSessionExpiryDate(): Date {
const cookieExpiresMilliseconds = Number(this.configService.get('ETHERPAD_COOKIE_EXPIRES_SECONDS')) * 1000;
const cookieExpiresMilliseconds = Number(this.configService.get('ETHERPAD__COOKIE_EXPIRES_SECONDS')) * 1000;
const sessionCookieExpiryDate = new Date(Date.now() + cookieExpiresMilliseconds);

return sessionCookieExpiryDate;
Expand Down
18 changes: 9 additions & 9 deletions apps/server/src/modules/server/admin-api.server.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Configuration } from '@hpi-schul-cloud/commons';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { DynamicModule, Module } from '@nestjs/common';
import { DeletionApiModule } from '@modules/deletion/deletion-api.module';
import { FileEntity } from '@modules/files/entity';
import { LegacySchoolAdminApiModule } from '@modules/legacy-school/legacy-school-admin.api-module';
import { UserAdminApiModule } from '@modules/user/user-admin-api.module';
import { DynamicModule, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { CqrsModule } from '@nestjs/cqrs';
import { ALL_ENTITIES } from '@shared/domain/entity';
import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config';
import { LoggerModule } from '@src/core/logger';
import { MongoDatabaseModuleOptions, MongoMemoryDatabaseModule } from '@src/infra/database';
import { RabbitMQWrapperModule, RabbitMQWrapperTestModule } from '@src/infra/rabbitmq';
import { CqrsModule } from '@nestjs/cqrs';
import { DeletionApiModule } from '@modules/deletion/deletion-api.module';
import { LegacySchoolAdminApiModule } from '@modules/legacy-school/legacy-school-admin.api-module';
import { UserAdminApiModule } from '@modules/user/user-admin-api.module';
import { EtherpadClientModule } from '@src/infra/etherpad-client';
import { Configuration } from '@hpi-schul-cloud/commons';
import { RabbitMQWrapperModule, RabbitMQWrapperTestModule } from '@src/infra/rabbitmq';
import { serverConfig } from './server.config';
import { defaultMikroOrmOptions } from './server.module';

Expand All @@ -22,8 +22,8 @@ const serverModules = [
LegacySchoolAdminApiModule,
UserAdminApiModule,
EtherpadClientModule.register({
apiKey: Configuration.has('ETHERPAD_API_KEY') ? (Configuration.get('ETHERPAD_API_KEY') as string) : undefined,
basePath: Configuration.has('ETHERPAD_URI') ? (Configuration.get('ETHERPAD_URI') as string) : undefined,
apiKey: Configuration.has('ETHERPAD__API_KEY') ? (Configuration.get('ETHERPAD__API_KEY') as string) : undefined,
basePath: Configuration.has('ETHERPAD__URI') ? (Configuration.get('ETHERPAD__URI') as string) : undefined,
}),
];

Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/server/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ const config: ServerConfig = {
FEATURE_NEXBOARD_COPY_ENABLED: Configuration.get('FEATURE_NEXBOARD_COPY_ENABLED') as boolean,
FEATURE_ETHERPAD_ENABLED: Configuration.get('FEATURE_ETHERPAD_ENABLED') as boolean,
ETHERPAD__PAD_URI: Configuration.get('ETHERPAD__PAD_URI') as string,
ETHERPAD_COOKIE_EXPIRES_SECONDS: Configuration.get('ETHERPAD_COOKIE_EXPIRES_SECONDS') as number,
ETHERPAD_COOKIE_RELEASE_THRESHOLD: Configuration.get('ETHERPAD_COOKIE_RELEASE_THRESHOLD') as number,
ETHERPAD__COOKIE_EXPIRES_SECONDS: Configuration.get('ETHERPAD__COOKIE_EXPIRES_SECONDS') as number,
ETHERPAD__COOKIE_RELEASE_THRESHOLD: Configuration.get('ETHERPAD__COOKIE_RELEASE_THRESHOLD') as number,
I18N__AVAILABLE_LANGUAGES: (Configuration.get('I18N__AVAILABLE_LANGUAGES') as string).split(',') as LanguageType[],
I18N__DEFAULT_LANGUAGE: Configuration.get('I18N__DEFAULT_LANGUAGE') as unknown as LanguageType,
I18N__FALLBACK_LANGUAGE: Configuration.get('I18N__FALLBACK_LANGUAGE') as unknown as LanguageType,
Expand Down
60 changes: 22 additions & 38 deletions config/default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -783,57 +783,41 @@
"default": true,
"description": "Etherpad feature enabled"
},
"ETHERPAD_API_KEY": {
"default": "",
"type": "string",
"description": "The etherpad api key for sending requests."
},
"ETHERPAD_API_PATH": {
"type": "string",
"default": "/api/1",
"description": "The etherpad api path."
},
"ETHERPAD_URI": {
"type": "string",
"default": "https://dbildungscloud.de/etherpad/api/1",
"description": "The etherpad api version uri."
},
"ETHERPAD_OLD_PAD_URI": {
"type": "string",
"default": "https://etherpad.dbildungscloud.de/p",
"description": "The etherpad api version uri."
},
"ETHERPAD": {
"type": "object",
"description": "Etherpad settings",
"required": ["PAD_URI"],
"properties": {
"URI": {
"type": "string",
"description": "The etherpad api version uri."
},
"PAD_URI": {
"type": "string",
"format": "uri",
"pattern": ".*(?<!/)$",
"description": "The etherpad pad uri"
},
"OLD_PAD_URI": {
"type": "string",
"description": "The etherpad api version uri."
},
"API_KEY": {
"type": "string",
"description": "The etherpad api key for sending requests."
},
"COOKIE_EXPIRES_SECONDS": {
"type": "integer",
"default": 7200,
"description": "Number of seconds after an etherpad cookie expires."
},
"COOKIE_RELEASE_THRESHOLD": {
"type": "integer",
"default": 7200,
"description": "If Session Valid time is smaller than this, a new session is created on request."
}
},
"default": {
"PAD_URI": "https://dbildungscloud.de/etherpad/p"
}
},
"ETHERPAD_OLD_PAD_DOMAIN": {
"type": "string",
"default": "etherpad.dbildungscloud.de",
"description": "The old etherpad domain."
},
"ETHERPAD_COOKIE_EXPIRES_SECONDS": {
"type": "integer",
"default": 28800,
"description": "Number of seconds after an etherpad cookie expires."
},
"ETHERPAD_COOKIE_RELEASE_THRESHOLD": {
"type": "integer",
"default": 7200,
"description": "If Session Valid time is smaller than this, a new session is created on request."
},
"NEXTCLOUD_BASE_URL": {
"type": "string",
"default": "http://nextcloud.localhost:9090",
Expand Down
4 changes: 2 additions & 2 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
"API_URL": "http://localhost:8888/v1/",
"TOKEN_ENDPOINT": "http://localhost:8888/realms/SANIS/protocol/openid-connect/token"
},
"ETHERPAD_URI": "http://localhost:9001/api/1/",
"ETHERPAD": {
"PAD_URI": "http://localhost:9001/p"
"PAD_URI": "http://localhost:9001/p",
"URI": "http://localhost:9001/api/1.2.14"
},
"PROVISIONING_SCHULCONNEX_LIZENZ_INFO_URL": "http://localhost:8888/v1/lizenzinfo",
"BOARD_COLLABORATION_URI": "ws://localhost:4450"
Expand Down
6 changes: 3 additions & 3 deletions config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@
"IS_ENABLED_BY_DEFAULT": true,
"IS_VISIBLE": true
},
"ETHERPAD_URI": "http://localhost:9001/api/1/",
"ETHERPAD_API_KEY": "381d67e6347d235ac9446",
"ETHERPAD": {
"PAD_URI": "http://localhost:9001/p"
"URI": "http://localhost:9001/api/1/",
"PAD_URI": "http://localhost:9001/p",
"API_KEY": "381d67e6347d235ac9446"
}
}
14 changes: 7 additions & 7 deletions src/services/etherpad/hooks/Pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const restrictOldPadsToCourse = async (context) => {
if (typeof context.data.oldPadId === 'undefined') {
return context;
}
const oldPadURI = Configuration.get('ETHERPAD_OLD_PAD_URI') || 'https://etherpad.schul-cloud.org/p';
const oldPadURI = Configuration.get('ETHERPAD__OLD_PAD_URI') || 'https://etherpad.schul-cloud.org/p';
try {
const lessonsService = context.app.service('/lessons');
const foundLessons = await lessonsService.find({
Expand Down Expand Up @@ -58,12 +58,12 @@ const before = {
find: [disallow()],
get: [disallow()],
create: [
globalHooks.hasPermission(['TOOL_CREATE', 'TOOL_CREATE_ETHERPAD']),
injectCourseId,
globalHooks.restrictToUsersOwnCourses,
getGroupData,
restrictOldPadsToCourse,
],
globalHooks.hasPermission(['TOOL_CREATE', 'TOOL_CREATE_ETHERPAD']),
injectCourseId,
globalHooks.restrictToUsersOwnCourses,
getGroupData,
restrictOldPadsToCourse,
],
update: [disallow()],
patch: [disallow()],
remove: [disallow()],
Expand Down
14 changes: 7 additions & 7 deletions src/services/etherpad/utils/EtherpadClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const logger = require('../../../logger');
*/
class EtherpadClient {
constructor() {
if (Configuration.has('ETHERPAD_URI')) {
this.uri = () => Configuration.get('ETHERPAD_URI');
if (Configuration.has('ETHERPAD__URI')) {
this.uri = () => Configuration.get('ETHERPAD__URI');
logger.info('Etherpad uri is set to=', this.uri());
} else {
this.uri = null;
logger.info('Etherpad uri is not defined');
}
if (Configuration.has('ETHERPAD_COOKIE_EXPIRES_SECONDS')) {
this.cookieExpiresSeconds = Configuration.get('ETHERPAD_COOKIE_EXPIRES_SECONDS');
if (Configuration.has('ETHERPAD__COOKIE_EXPIRES_SECONDS')) {
this.cookieExpiresSeconds = Configuration.get('ETHERPAD__COOKIE_EXPIRES_SECONDS');
} else {
this.cookieExpiresSeconds = 28800;
}
if (Configuration.has('ETHERPAD_COOKIE_RELEASE_THRESHOLD')) {
this.cookieReleaseThreshold = Configuration.get('ETHERPAD_COOKIE_RELEASE_THRESHOLD');
if (Configuration.has('ETHERPAD__COOKIE_RELEASE_THRESHOLD')) {
this.cookieReleaseThreshold = Configuration.get('ETHERPAD__COOKIE_RELEASE_THRESHOLD');
} else {
this.cookieReleaseThreshold = 7200;
}
Expand All @@ -45,7 +45,7 @@ class EtherpadClient {
method = 'POST',
endpoint,
formDef = {
apikey: Configuration.get('ETHERPAD_API_KEY'),
apikey: Configuration.get('ETHERPAD__API_KEY'),
},
body,
},
Expand Down
6 changes: 1 addition & 5 deletions test/services/etherpad/MockServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const { Configuration } = require('@hpi-schul-cloud/commons');
const logger = require('../../../src/logger');

// /api/1/
module.exports = function MockServer(
url = 'http://localhost:58373',
path = Configuration.get('ETHERPAD_API_PATH'),
resolver
) {
module.exports = function MockServer(url = 'http://localhost:58373', path = '/api', resolver) {
const app = express();
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
Expand Down
8 changes: 4 additions & 4 deletions test/services/etherpad/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ describe('Etherpad services', () => {
logger.warning('freeport:', err);
}

const API_PATH_CONFIG = Configuration.get('ETHERPAD_API_PATH');
const API_PATH_CONFIG = `/api`;
const mockUrl = `http://localhost:${port}${API_PATH_CONFIG}`;
Configuration.set('ETHERPAD_URI', mockUrl);
Configuration.set('ETHERPAD_API_KEY', 'someapikey');
Configuration.set('ETHERPAD__URI', mockUrl);
Configuration.set('ETHERPAD__API_KEY', 'someapikey');

app = await appPromise();
server = await app.listen(0);
nestServices = await setupNestServices(app);

const mock = await MockServer(mockUrl, Configuration.get('ETHERPAD_API_PATH'));
const mock = await MockServer(mockUrl, API_PATH_CONFIG);
mockServer = mock.server;
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/services/etherpad/permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ describe('Etherpad Permission Check: Teacher', () => {
logger.warning('freeport:', err);
}

const ethPath = Configuration.get('ETHERPAD_API_PATH');
const ethPath = '/api';
const mockUrl = `http://localhost:${port}${ethPath}`;
Configuration.set('ETHERPAD_URI', mockUrl);
Configuration.set('ETHERPAD_API_KEY', 'someapikey');
Configuration.set('ETHERPAD__URI', mockUrl);
Configuration.set('ETHERPAD__API_KEY', 'someapikey');

app = await appPromise();
server = await app.listen(0);
nestServices = await setupNestServices(app);

const mock = MockServer(mockUrl, Configuration.get('ETHERPAD_API_PATH'), done);
const mock = MockServer(mockUrl, ethPath, done);
mockServer = mock.server;
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/services/etherpad/permissionsStudents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ describe('Etherpad Permission Check: Students', () => {
logger.warning('freeport:', err);
}

const ethPath = Configuration.get('ETHERPAD_API_PATH');
const ethPath = '/api';
const mockUrl = `http://localhost:${port}${ethPath}`;
Configuration.set('ETHERPAD_URI', mockUrl);
Configuration.set('ETHERPAD_API_KEY', 'someapikey');
Configuration.set('ETHERPAD__URI', mockUrl);
Configuration.set('ETHERPAD__API_KEY', 'someapikey');

app = await appPromise();
server = await app.listen(0);
nestServices = await setupNestServices(app);

const mock = MockServer(mockUrl, Configuration.get('ETHERPAD_API_PATH'), done);
const mock = MockServer(mockUrl, ethPath, done);
mockServer = mock.server;
});
});
Expand Down

0 comments on commit e5f7ae7

Please sign in to comment.