From b0d4851651b43695280e33fef1daedad12c5bef5 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Wed, 6 Mar 2019 08:01:46 +0100 Subject: [PATCH] Fix inSomeGroups for the superadmin, delete empty comments --- ...tion-comment-section-repository.service.ts | 36 ++++++++++++++----- .../motion-comments.component.ts | 8 ++--- openslides/utils/auth.py | 12 ++----- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/client/src/app/core/repositories/motions/motion-comment-section-repository.service.ts b/client/src/app/core/repositories/motions/motion-comment-section-repository.service.ts index 060b7b21c..87f89c661 100644 --- a/client/src/app/core/repositories/motions/motion-comment-section-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-comment-section-repository.service.ts @@ -12,6 +12,7 @@ import { HttpService } from 'app/core/core-services/http.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewGroup } from 'app/site/users/models/view-group'; import { TranslateService } from '@ngx-translate/core'; +import { ViewMotion } from 'app/site/motions/models/view-motion'; /** * Repository Services for Categories @@ -106,17 +107,36 @@ export class MotionCommentSectionRepositoryService extends BaseRepository< } /** - * Saves a comment made at a MotionCommentSection + * Saves a comment made at a MotionCommentSection. Does an update, if + * there is a comment text. Deletes the comment, if the text is empty. * - * @param motionId ID of the Motion - * @param sectionId ID of the Section where the comment was made + * @param motion the motion + * @param section the section where the comment was made * @param sectionComment the comment text - * @returns the promise to create the object + * @returns the promise from the HTTP request */ - public async saveComment(motionId: number, sectionId: number, sectionComment: String): Promise { - return this.http.post(`rest/motions/motion/${motionId}/manage_comments/`, { - section_id: sectionId, - comment: sectionComment + public async saveComment(motion: ViewMotion, section: ViewMotionCommentSection, comment: string): Promise { + if (comment) { + return await this.updateComment(motion, section, comment); + } else { + return await this.deleteComment(motion, section); + } + } + + /** + * Updates the comment. Saves it on the server. + */ + private async updateComment(motion: ViewMotion, section: ViewMotionCommentSection, comment: string): Promise { + return await this.http.post(`rest/motions/motion/${motion.id}/manage_comments/`, { + section_id: section.id, + comment: comment }); } + + /** + * Deletes a comment from the server + */ + private async deleteComment(motion: ViewMotion, section: ViewMotionCommentSection): Promise { + return await this.http.delete(`rest/motions/motion/${motion.id}/manage_comments/`, { section_id: section.id }); + } } diff --git a/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts b/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts index 14b821d25..9c0570404 100644 --- a/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts +++ b/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts @@ -130,15 +130,13 @@ export class MotionCommentsComponent extends BaseViewComponent { } /** - * Saves the comment. Makes a request to the server. + * Saves the comment. * * @param section The section for the comment to save */ - public async saveComment(section: ViewMotionCommentSection): Promise { + public saveComment(section: ViewMotionCommentSection): void { const commentText = this.commentForms[section.id].get('comment').value; - const sectionId = section.id; - const motionId = this.motion.id; - await this.commentRepo.saveComment(motionId, sectionId, commentText).then( + this.commentRepo.saveComment(this.motion, section, commentText).then( () => { this.cancelEditing(section); }, diff --git a/openslides/utils/auth.py b/openslides/utils/auth.py index d617eddc3..678ccb5f4 100644 --- a/openslides/utils/auth.py +++ b/openslides/utils/auth.py @@ -97,14 +97,10 @@ def in_some_groups(user_id: int, groups: List[int]) -> bool: """ Checks that user is in at least one given group. Groups can be given as a list of ids or group instances. If the user is in the admin group (pk = 2) the result - is always true. + is always true, even if no groups are given. user_id 0 means anonymous user. """ - - if len(groups) == 0: - return False # early end here, if no groups are given. - # Convert user to right type # TODO: Remove this and make use, that user has always the right type user_id = user_to_user_id(user_id) @@ -115,14 +111,10 @@ async def async_in_some_groups(user_id: int, groups: List[int]) -> bool: """ Checks that user is in at least one given group. Groups can be given as a list of ids. If the user is in the admin group (pk = 2) the result - is always true. + is always true, even if no groups are given. user_id 0 means anonymous user. """ - - if not len(groups): - return False # early end here, if no groups are given. - if not user_id and not await async_anonymous_is_enabled(): in_some_groups = False elif not user_id: