GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Commit 1d3a9683 authored by Christopher Mark Fullarton's avatar Christopher Mark Fullarton
Browse files

Fixes auth error when logging in as user with questions without content in the db

parent 42288f75
......@@ -25,9 +25,9 @@ export function GetAssetUrlByDigest(digest: string): Promise<Document & AssetMod
export async function MatchAssetCachedQuiz(quiz: IQuiz): Promise<IQuiz> {
quiz.questionList = await Promise.all<IQuestionBase>((
quiz.questionList as Array<IQuestionBase>
).map(async question => {
)?.map(async question => {
question.answerOptionList = await Promise.all(question.answerOptionList.map(async answer => {
question.answerOptionList = await Promise.all(question.answerOptionList?.map(async answer => {
const answerMatched = answer.answerText.matchAll(new RegExp(assetsPathUrlRegex, 'gi'));
let answerTextMatcher = answerMatched.next();
while (!answerTextMatcher.done) {
......
......@@ -17,29 +17,18 @@ export async function roleAuthorizationChecker(action: Action, searchRoles: User
return false;
}
if (action.request.headers.authorization.startsWith('Basic ')) {
const encBasicAuth = (action.request.headers.authorization || '').replace('Basic ', '');
const decBasicAuth = Buffer.from(encBasicAuth, 'base64').toString().split(':');
if (!decBasicAuth || decBasicAuth.length !== 2) {
return false;
}
username = decBasicAuth[0];
password = decBasicAuth[1];
} else if (action.request.headers.authorization.startsWith('Bearer ')) {
const token = action.request.headers.authorization.replace('Bearer ', '');
const decodedToken = AuthService.decodeToken(token);
if (typeof decodedToken !== 'object' || !(decodedToken as any).name) {
return false;
}
action.request.headers.authorization = (decodedToken as any).privateKey;
return (searchRoles as unknown as Array<string>).some(role => (decodedToken as any).userAuthorizations.includes(UserRole[role]));
if (action.request.headers.authorization.startsWith('Bearer ')) {
action.request.headers.authorization = action.request.headers.authorization.replace('Bearer ', '');
}
return false;
const decodedToken = AuthService.decodeToken(action.request.headers.authorization);
if (typeof decodedToken !== 'object' || !(decodedToken as any).name) {
return false;
}
action.request.headers.authorization = (decodedToken as any).privateKey;
return (searchRoles as unknown as Array<string>).some(role => (decodedToken as any).userAuthorizations.includes(UserRole[role]));
}
const authenticated = await AuthService.authenticate({
......
......@@ -351,7 +351,11 @@ export class LibRouter extends AbstractRouter {
token = await AuthService.generateToken(user);
await UserDAO.updateUser(user.id, { token });
const quizzes = await QuizDAO.getQuizzesByPrivateKey(user.privateKey) || [];
const parsedQuizzes = await Promise.all(quizzes.map(quiz => MatchAssetCachedQuiz(quiz.toJSON({getters: true}))));
const parsedQuizzes = await Promise.all(
quizzes
.filter(quiz => quiz.questionList?.length)
.map(quiz => MatchAssetCachedQuiz(quiz.toJSON({getters: true})))
);
return {
status: StatusProtocol.Success,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment