-
Notifications
You must be signed in to change notification settings - Fork 932
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
Adds optional use of notes records #5511
base: master
Are you sure you want to change the base?
Adds optional use of notes records #5511
Conversation
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.
Why does this need to use [:user_id]
etc rather than the more typical .user_id
form?
57b066d
to
a6d2722
Compare
I replaced using |
app/models/note.rb
Outdated
def description | ||
comments.first.body | ||
if user_ip.nil? && user_id.nil? | ||
comments.first.body | ||
else | ||
RichText.new("text", self[:description]) | ||
end | ||
end |
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.
I assume that self[:description]
is going to be the true note description, the text note was created with. comments.first.body
is not necessarily that text because comments.first
is not necessarily the first api 0.6 comment. comments
only contain api 0.6 comments by active users and doesn't contain api 0.6 comments of deleted users.
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.
We could make it consistent by using all_comments
instead but that obviously changes the behaviour from what we have now, but then that's going to be the case anyway when this transition is completed?
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.
Weren't you insisting on not showing the true description until LWG agrees?
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.
I don't think I've said that as such.
What I have said is that we need a proper documented policy about how to handle deleted users and what we should and shouldn't show. I don't think I specifically asked for that to come from LWG though obviously that may be needed to answer questions about what we can and can't do.
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.
Have we reached a decision on this? We planned to copy the body of the first note's comment (i.e. one with event set to "opened") to note's description (data migration-script), but can easily switch to another logic?
Btw, before data-migration PR we planned 2 more steps (updating creating and updating searching).
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.
Copying is not the problem, the problem is you won't be able to the description if the user who created it is deleted. You'll have to remember that whenever you access note.description
.
There was a draft policy by DWG about deleted users that was supposed to be sent to LWG but wasn't. It says that DWG recommends note comments of deleted users to be visible. If that's impossible, "a comment is not shown because ..." is to be displayed instead. Descriptions are not mentioned but the same should apply to them.
The default solution if no decision was made was to replace description with "deleted" when the note is displayed:
Since you already started using note.description
, one of the following things should happen:
- you remove deleted descriptions here in the model
- you remove them on use
- we actually do a proper documented policy (in other words it's easier to remove deleted descriptions for now)
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.
Thanks! Started displaying "deleted" if note's author is deleted.
app/models/note.rb
Outdated
def author_id | ||
comments.first.author_id | ||
if user_ip.nil? && user_id.nil? | ||
comments.first.author_id | ||
else | ||
user_id | ||
end | ||
end |
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.
If user_id is a true id of the user who created the note, it won't necessarily match author.id
, see my comment for description
. Attempts to fix that for author
were made in the past but were rejected by the maintainers, see for example #3607.
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.
The latest push should fix this. Thanks!
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.
Now you are revealing the true author as soon as migration happens, but not before.
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.
Thanks! Started using all_comments
instead of comments
.
a6d2722
to
04bc2d4
Compare
04bc2d4
to
aee9a10
Compare
app/models/note.rb
Outdated
def description | ||
comments.first.body | ||
if !author.nil? && author.status == "deleted" | ||
RichText.new("text", I18n.t("notes.show.description_when_author_is_deleted")) | ||
elsif user_ip.nil? && user_id.nil? | ||
comments.first.body | ||
else | ||
RichText.new("text", self[:description]) | ||
end | ||
end | ||
|
||
# Return the note's author object, derived from the first comment | ||
# Return the note's author object, unless record is unavailable and | ||
# it will be derived from the first comment | ||
def author | ||
comments.first.author | ||
end | ||
|
||
# Return the note's author ID, derived from the first comment | ||
def author_id | ||
comments.first.author_id | ||
end | ||
|
||
# Return the note's author IP address, derived from the first comment | ||
def author_ip | ||
comments.first.author_ip | ||
if user_ip.nil? && user_id.nil? | ||
all_comments.first.author | ||
else | ||
self[:author] | ||
end | ||
end |
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.
If author
returns the true author, description
should also return the true description. There's note_author
helper which hides the author when necessary. Similarly you can make a helper that hides the description, and you won't need I18n.t("notes.show.description_when_author_is_deleted")
inside the model. And you'll use the helper in these places: 2c19c21.
In #3607 I also removed the deleted author from rss.
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.
This opens 2 problems with notes with deleted author:
- When we click on such note, it will show "deleted" as a description, but first next comment will be lost (i.e. we need to update app/views/notes/show.html.erb not to drop first comment if author is deleted) and
- When we hover over such note, it will show first "note.comments" comment instead of "deleted".
Should we fix these in this PR or in next?
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.
I've just pushed the latest changes without solving above.
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.
Added 2 commits solving above two problems.
180ffe4
to
e3f82ea
Compare
e3f82ea
to
4fc089e
Compare
Adds author association and optional use of note's records. If data-migration is done, real author is returned, otherwise if data-migration is not done, first note's comment author is returned. Added method author_deleted for encapsulating checking if note's author is deleted.
Added new helper routine note_description for retrieving note's description. Helper routine returns "deleted" if author is deleted, first comment's body if data-migration is not done or note's description record if data-migration is done.
Replaced using note's description method with note_description helper routine.
Removed author_id, author_ip and description methods from Note model because they are not used anymore.
Removed writing note's author to note's RSS if note's author is deleted.
Adds displaying first (visible) comment as a comment in case of deleted note's author. After adding displaying "deleted" as note description, first comment is not anymore dropped when displaying note's comments.
Adds description field to generated note's XML and JSON files with note's description.
Adds initializing note's tooltips from description retrieved from JSON file.
4fc089e
to
14a78ae
Compare
Description
PR adds use of
description
,user_id
,user_ip
fromnotes
table if data-migration is done, otherwise usebody
,author_id
,author_ip
from note's first comment. Decision procedure "data-migration is done" is defined with "is user_ip or user_id not nil?".This PR is 4th from set of PRs described here.
How has this been tested?
Automated unit tests and manual testing.