Fix inSomeGroups for the superadmin, delete empty comments
This commit is contained in:
parent
118b853a91
commit
b0d4851651
@ -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<object> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
return await this.http.delete(`rest/motions/motion/${motion.id}/manage_comments/`, { section_id: section.id });
|
||||
}
|
||||
}
|
||||
|
@ -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<void> {
|
||||
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);
|
||||
},
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user