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

Attach discussions to other objects #1668

Open
gregelin opened this issue Aug 2, 2021 · 2 comments · Fixed by #1675
Open

Attach discussions to other objects #1668

gregelin opened this issue Aug 2, 2021 · 2 comments · Fixed by #1675

Comments

@gregelin
Copy link
Contributor

gregelin commented Aug 2, 2021

Is your feature request related to a problem? Please describe.

Enable discussions to be attached to other objects.

Describe the solution you'd like

Methods the attached_to object must implement:

get_absolute_url() => Expects that the Discussion exists on the page returned by this method. Invitations to the discussion bring the user here.

title (with "@Property" attribute) => Return the title of the discussion

is_discussion_deleted() => Is the attached_to object inactive and the discussion should be treated as deleted, maybe?
get_discussion_participants() => Returns a QuerySet of Users. Used to give those users notifications about new comments I think?

get_discussion_interleaved_events(since) => Returns other events to show interleaved between comments like github's pull requests show comments interleaved with other activity on the PR. "since" is a time, if passed, it should return events since that time.

get_project_context_dict() => Return stuff.... Need to look at how it is used to know what it can return. Probably should be a dict, so returning an empty dict " {} " would probably be fine.

is_discussion_public() => Optional! If implemented, returns something. Need to see how Discussion.is_public is used.

can_invite_guests(user) => Returns whether the user is permitted to invite guests.

get_notification_watchers() => Returns a QuerySet of Users who should get notifications about things related to the discussion.

get_discussion_autocompletes(discussion) => Returns information about available autocompletes for comments. Need to see how Discussion.get_autocompletes is used to know what to return.

on_discussion_comment(discussion) => Optional! This is called after a comment is left so the attached_to object can take further action.

on_discussion_comment_edited(comment) => Optional! If implemented, it is called after an existing comment is edited (i.e. revised) by its author.

task (with "@Property" attribute) => Returns the Task associated with the TaskAnswer but obviously does not pertain to other uses of discussions.

get_user_role(user) => Returns a string describing the user's role in a discussion. I think this might be for display purposes only. Can return None. Otherwise e.g. "guest", "member," etc.

@davidpofo
Copy link
Contributor

Because the Discussion Model has a GenericForeignKey( attached_to = GenericForeignKey('attached_to_content_type', 'attached_to_object_id')) it can be attached to any model with a GenericRelation like so:

class Comment(models.Model):
    ...
    likes = GenericRelation(Discussion)
# Creating a new like in the discussion
discussion.likes.create(attached_to_content_type=Discussion.LIKE, user=request.user)

In this example there is a constant in Discussion called LIKE. This issue then seems to either be enhancing the Discussion methods are present and applying GenericRelations to at least the User and Comment models. This is all to say the Discussion model is all setup to attach to other models.

@davidpofo
Copy link
Contributor

davidpofo commented Aug 5, 2021

Unless otherwise discussed below the methods are already ready to be added given the Generic Relationship Discussion can have with any other model (given its GenericForeignKey)

  • is_discussion_deleted() is now .is_discussion_inactive() (note there is no deleting of a discussion yet implemented.)
  • get_project_context_dict doesn't seem relevant for any other model besides task.
  • is_public() doesn't seems to do anything as assigning the attribute is_discussion_public to a model doesn't happen anywhere so it always returns the default which is False.
  • Added get_discussion_autocompletes changes to get the organization from the discussion(should be 1 to 1). If another models wants to implement it they can look at the get_discussion_autocompletes in TaskAnswer
  • on_discussion_comment assumes a task to get the org which is easy enough to replace (comment.discussion.organization) however it also needs a project for the task which you cannot get from the comment.
  • on_discussion_comment_edited is not implemented see TODO line 95 in discussion/views.py
  • get_user_role is implemented solely assuming a task in TaskAnswer

@davidpofo davidpofo linked a pull request Aug 5, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants