mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
NotesService: Implement getAuthorUsers
This reimplements logic to get all Users that ever edited a note
and fixes the empty `editedBy` property of `toNoteMetadataDto`
introduced in 81cc092e
.
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
6abcb686ca
commit
5846ca75a9
3 changed files with 51 additions and 2 deletions
|
@ -41,6 +41,7 @@ export class NotesService {
|
|||
private readonly logger: ConsoleLoggerService,
|
||||
@InjectRepository(Note) private noteRepository: Repository<Note>,
|
||||
@InjectRepository(Tag) private tagRepository: Repository<Tag>,
|
||||
@InjectRepository(User) private userRepository: Repository<User>,
|
||||
@Inject(UsersService) private usersService: UsersService,
|
||||
@Inject(GroupsService) private groupsService: GroupsService,
|
||||
@Inject(forwardRef(() => RevisionsService))
|
||||
|
@ -188,6 +189,22 @@ export class NotesService {
|
|||
return note;
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Get all users that ever appeared as an author for the given note
|
||||
* @param note The note to search authors for
|
||||
*/
|
||||
async getAuthorUsers(note: Note): Promise<User[]> {
|
||||
return await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.innerJoin('user.authors', 'author')
|
||||
.innerJoin('author.authorships', 'authorship')
|
||||
.innerJoin('authorship.revisions', 'revision')
|
||||
.innerJoin('revision.note', 'note')
|
||||
.where('note.id = :id', { id: note.id })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided note id or alias is not forbidden
|
||||
* @param noteIdOrAlias - the alias or id in question
|
||||
|
@ -358,7 +375,7 @@ export class NotesService {
|
|||
title: note.title ?? '',
|
||||
createTime: (await this.getFirstRevision(note)).createdAt,
|
||||
description: note.description ?? '',
|
||||
editedBy: [], // TODO temporary placeholder,
|
||||
editedBy: (await this.getAuthorUsers(note)).map((user) => user.userName),
|
||||
permissions: this.toNotePermissionsDto(note),
|
||||
tags: this.toTagList(note),
|
||||
updateTime: (await this.getLatestRevision(note)).createdAt,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue