-
Notifications
You must be signed in to change notification settings - Fork 82
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
[Issue #441] Add maintainer notes to patches #586
base: main
Are you sure you want to change the base?
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.
No issues with the idea or API design on this one. Just a couple of minor nits and a slight tweak to the model (that will have knock-on effects for the API also).
Thought on this more over the weekend. Out of curiosity, how many maintainer notes would one expect and do we need them to be surfaced to the top above comments? Put another way, would we expect there to be a single uber-important note on a patch, or many notes like a conversation? I'm thinking that a note is really no different from a comment. Rather than adding a whole new model, we could simply extend the |
I don't imagine patches having many notes at once (although it's possible in the current implementation). I think the idea for it is to provide important context for a patch before the reader dives into the patch so it makes sense to give them more importance than comments, they are similar to a commit message, but can be private and edited without the need to submit a new patch. If they were to be in the middle of a comment thread they wouldn't have the same emphasis on their message. Like you mentioned, notes also have a different way to interact with them, to maintain the privacy they are added through the Web UI / REST API For these reasons notes, in their current state, are different enough from comments to have their own model. I think that if we went with private comments the use case for the feature would be a bit different, but very valid as well |
3c68f5d
to
0dedae2
Compare
That's right, FWIW, the intention is small number of important notes / one note which can be edited. |
patchwork/api/note.py
Outdated
@@ -0,0 +1,143 @@ | |||
# Patchwork - automated patch tracking system | |||
# Copyright (C) 2018 Red Hat |
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.
Probably want a different copyright here.
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.
Fixed
models.DateTimeField(default=django.utils.timezone.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.
This shouldn't be here. I'm going to guess you missed setting abstract
in the TimestampMixin.Meta
class?
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 this setting
patchwork/models.py
Outdated
updated_at = models.DateTimeField(default=tz_utils.now) | ||
|
||
def update_timestamp(self): | ||
self.updated_at = tz_utils.now().isoformat() |
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.
You need to add the following to ensure this doesn't translate to a real table:
class Meta:
abstract = True
patchwork/models.py
Outdated
@@ -33,6 +33,14 @@ def validate_regex_compiles(regex_string): | |||
raise ValidationError('Invalid regular expression entered!') | |||
|
|||
|
|||
class TimestampMixin(models.Model): | |||
created_at = models.DateTimeField(default=tz_utils.now) | |||
updated_at = models.DateTimeField(default=tz_utils.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.
I think you want auto_now_add
and auto_now
for created_at
and updated_at
, respectively. You should be able to drop update_timestamp
and the call to same then.
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.DateField
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.
Nice catch. Changed to use these options
) | ||
submitter = models.ForeignKey(User, on_delete=models.CASCADE) | ||
content = models.TextField(null=False, blank=True) | ||
maintainer_only = models.BooleanField(default=True) |
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.
Are these not always maintainer-only? Why would we ever want to make them public?
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.
Not necessarily, it may be used to transmit additional context for reviewers that may not be adequate to have in the commit message, in this context it would make sense to have public notes.
<h2>Notes</h2> | ||
{% endif %} | ||
<a name="{{ item.id }}"></a> | ||
<div class="submission-message"> |
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.
Can we use a different class and set the background to a different colour so it stands out? These are presumably rather important.
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.
patchwork/tests/api/test_notes.py
Outdated
@@ -0,0 +1,231 @@ | |||
# Patchwork - automated patch tracking system | |||
# Copyright (C) 2018 Red Hat |
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.
Wrong license header?
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.
Fixed
patchwork/views/patch.py
Outdated
@@ -122,6 +122,14 @@ def patch_detail(request, project_id, msgid): | |||
'submitter', 'date', 'id', 'content', 'patch', 'addressed' | |||
) | |||
|
|||
if ( | |||
request.user.is_authenticated | |||
and patch.project not in request.user.profile.maintainer_projects.all() |
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.
and patch.project not in request.user.profile.maintainer_projects.all() | |
and patch.project in request.user.profile.maintainer_projects.all() |
Assuming I'm reading this correctly, surely the project should be in the user's list of projects they maintain?
Assuming this does need updating, I think we need a test for the UI also.
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.
Oh I think I was logged in the wrong account when testing it on my end, you are correct, it should be in the user list of projects. I fexed the issue, made the notes show for admin users and added tests for the UI
may not have. These can also be public so that any user can read them. | ||
api: | ||
- | | ||
The Application version has been updated to v3.2. |
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.
You don't need this: we'll announce the version bump separately when we cut a release.
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.
Removed
@hero24 I'll investigate / fix the mentioned points over the next week |
Signed-off-by: andrepapoti <[email protected]>
Signed-off-by: andrepapoti <[email protected]>
Added NoteList api. It allows the user to fetch all notes from a specific test or create a new one Added NoteDetail api. It allows the user to fetch, update and delete notes Signed-off-by: andrepapoti <[email protected]>
Patch serializer returns a fields containing it's notes. Some notes may be filtered out depending on the request's user and on the note maintainer_only attribute Signed-off-by: andrepapoti <[email protected]>
Bump latest API version to 1.4 Update patchwork.j2 with new note endpoints Add note endpoints to django urls Signed-off-by: andrepapoti <[email protected]>
Signed-off-by: andrepapoti <[email protected]>
Signed-off-by: andrepapoti <[email protected]>
The submission template now includes a section to display notes, these can be filtered out depending if the request user is a maintainer for the patch's project and on the note maintainer_only attribute Signed-off-by: andrepapoti <[email protected]>
Signed-off-by: andrepapoti <[email protected]>
create_note_form = CreateNoteForm() | ||
|
||
if is_maintainer and action == 'edit-note': | ||
print(edit_cancel) |
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.
Leftover
if is_maintainer and action == 'add-note': | ||
create_note_form = CreateNoteForm() | ||
|
||
if is_maintainer and action == 'edit-note': |
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.
You have to make sure the other actions are not evaluated after the first match, without the elif when trying to add a note as superuser but not maintainer we get a 403 error.
if is_maintainer and action == 'edit-note': | |
elif is_maintainer and action == 'edit-note': |
form_name = forms.CharField(initial=name, widget=forms.HiddenInput) | ||
content = forms.CharField(label='Content', widget=forms.Textarea) | ||
maintainer_only = forms.BooleanField( | ||
label='Maintainers Only', initial=True, widget=forms.CheckboxInput |
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 must set required=False for checkboxes to enable public notes creation
label='Maintainers Only', initial=True, widget=forms.CheckboxInput | |
label='Maintainers Only', initial=True, widget=forms.CheckboxInput, required=False |
instance.submitter.id, response_data['submitter']['id'] | ||
) | ||
|
||
def test_create_note(self): |
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.
Add create public note for tests
Description
Add support for maintainers to add notes to patches.
Notes can be either public or private enabling non maintainers users of a certain patches to see them or not.
The API for this feature allows to create, read, update, and delete notes. Reading can be either a detailed view of a note or a list of notes for a specified patch.
The patch serializer was update to include the notes related to it
Related