Skip to content
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

Da/discussion updates #1675

Merged
merged 4 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions discussion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def post_comment(self, user, text, post_method, is_draft=False):
def is_public(self):
return getattr(self.attached_to_obj, 'is_discussion_public', lambda : False)

def is_discussion_inactive(self):

if self.attached_to_obj is not None:
return True if self.attached_to_obj.title == "<Deleted Discussion>" else False

def can_comment(self, user):
return user is not None and self.is_participant(user)

Expand Down Expand Up @@ -246,6 +251,18 @@ def get_autocompletes(self, user):
self._get_autocompletes = self.attached_to_obj.get_discussion_autocompletes(self)
return self._get_autocompletes

@property
def get_task(self):
"""
Retrieves the task for the given discussion's attached object. For example Projects have root_task while TaskAnswer discussion would have a task.
"""
if hasattr(self.attached_to_obj, 'root_task'):
return self.attached_to_obj.root_task
elif hasattr(self.attached_to_obj, 'task'):
return self.attached_to_obj.task
else:
return False#TODO: not sure what to do if the model isn't related to a Task

class Comment(models.Model):
discussion = models.ForeignKey(Discussion, related_name="comments", on_delete=models.CASCADE, help_text="The Discussion that this comment is attached to.")
replies_to = models.ForeignKey('self', blank=True, null=True, related_name="replies", on_delete=models.CASCADE, help_text="If this is a reply to a Comment, the Comment that this is in reply to.")
Expand Down
3 changes: 2 additions & 1 deletion discussion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def edit_discussion_comment(request):

# save
comment.save()

# TODO: fully implement this add it as an attribute to Discussion model perhaps? Otherwise to find out if the text of the
# Current comment is the same as the previous text you would do something like: comment.extra['history'][-1]['previous-text'] != comment.text
# Kick the attached object.
if hasattr(comment.discussion.attached_to, 'on_discussion_comment_edited'):
comment.discussion.attached_to.on_discussion_comment_edited(comment)
Expand Down
6 changes: 3 additions & 3 deletions guidedmodules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,12 +2008,12 @@ def get_notification_watchers(self):
# required to attach a Discussion to it
def get_discussion_autocompletes(self, discussion):
# Get a list of all users who can be @-mentioned. It includes the discussion
# participants (i.e. people working on the same project and disussion guests)
# participants (i.e. people working on the same project and discussion guests)
# plus anyone in the same organization.
organization = self.task.project.organization
organization = discussion.organization
mentionable_users = set(discussion.get_all_participants()) \
| set(
User.objects.filter(projectmembership__project__organization=self.task.project.organization).distinct())
User.objects.filter(projectmembership__project__organization=organization).distinct())
User.preload_profiles(mentionable_users)
return {
# @-mention participants in the discussion and other
Expand Down
4 changes: 2 additions & 2 deletions guidedmodules/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,14 +2021,14 @@ def start_a_discussion(request):

# Get the TaskAnswer for this task. It may not exist yet.
tq, isnew = TaskAnswer.objects.get_or_create(**tq_filter)

# Filter for discussion and return the first entry (if it doesn't exist it returns None)
discussion = Discussion.get_for(task.project.organization, tq)
if not discussion:
# Validate user can create discussion.
if not task.has_read_priv(request.user):
return JsonResponse({ "status": "error", "message": "You do not have permission!" })

# Get the Discussion.
# Create a Discussion.
discussion = Discussion.get_for(task.project.organization, tq, create=True)

return JsonResponse(discussion.render_context_dict(request.user))
Expand Down