-
Notifications
You must be signed in to change notification settings - Fork 34
feat: Allow users to comment #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f13137
feat: Allow users to comment
orronai ccd024d
feat: Allow users comments
orronai 92f70f3
feat: Allow users to comment
orronai b0c7357
Solved a conflict with pull origin master
orronai fd1b484
feat: Allow users to comment
orronai d211981
feat: Allow users comments
orronai 4821b3c
feat: Allow users comments
orronai 51a82aa
feat: Allow users comments
orronai 35dce73
Fixed conflict issue
orronai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
from werkzeug.utils import redirect | ||
|
||
from lms.lmsdb.models import ( | ||
ALL_MODELS, Comment, CommentText, Exercise, RoleOptions, | ||
ALL_MODELS, Comment, CommentText, Exercise, Role, RoleOptions, | ||
SharedSolution, Solution, SolutionFile, User, database, | ||
) | ||
from lms.lmsweb import babel, routes, webapp | ||
|
@@ -208,8 +208,8 @@ def _create_comment( | |
|
||
return jsonify({ | ||
'success': 'true', 'text': comment_.comment.text, | ||
'author_name': user.fullname, 'is_auto': False, 'id': comment_.id, | ||
'line_number': line_number, | ||
'author_name': user.fullname, 'author_role': user.role.id, | ||
'is_auto': False, 'id': comment_.id, 'line_number': line_number, | ||
}) | ||
|
||
|
||
|
@@ -274,9 +274,20 @@ def comment(): | |
if act == 'fetch': | ||
return jsonify(Comment.by_file(file_id)) | ||
|
||
if ( | ||
not webapp.config.get('USERS_COMMENTS', False) | ||
and not current_user.role.is_manager | ||
): | ||
return fail(403, "You aren't allowed to access this page.") | ||
|
||
if act == 'delete': | ||
comment_id = int(request.args.get('commentId')) | ||
comment_ = Comment.get_or_none(Comment.id == comment_id) | ||
if ( | ||
comment_.commenter.id != current_user.id | ||
and not current_user.role.is_manager | ||
): | ||
return fail(403, "You aren't allowed to access this page.") | ||
if comment_ is not None: | ||
comment_.delete_instance() | ||
return jsonify({'success': 'true'}) | ||
|
@@ -501,9 +512,17 @@ def _common_comments(exercise_id=None, user_id=None): | |
Most common comments throughout all exercises. | ||
Filter by exercise id when specified. | ||
""" | ||
query = CommentText.filter(**{ | ||
CommentText.flake8_key.name: None, | ||
}).select(CommentText.id, CommentText.text).join(Comment) | ||
is_moderator_comments = ( | ||
(Comment.commenter.role == Role.get_staff_role().id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not possible - it throws an error that says is_staff, is_manager etc. are not attributes of Role. |
||
| (Comment.commenter.role == Role.get_admin_role().id), | ||
) | ||
query = ( | ||
CommentText.select(CommentText.id, CommentText.text) | ||
.join(Comment).join(User).join(Role).where( | ||
CommentText.flake8_key.is_null(True), | ||
is_moderator_comments, | ||
).switch(Comment) | ||
) | ||
|
||
if exercise_id is not None: | ||
query = ( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A user should be able to delete a comment only if its his comment , or he's an administrator