-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Branch protection: Possibility to not use whitelist but allow anyone with write access #9055
Merged
techknowlogick
merged 28 commits into
go-gitea:master
from
davidsvantesson:branch-protection-anyone
Dec 4, 2019
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
22be3e9
Possibility to not use whitelist but allow anyone with write access
davidsvantesson 11a5954
fix existing test
davidsvantesson 5bcf80e
rename migration function
davidsvantesson b488f1d
Try to give a better name for migration step
davidsvantesson 21f8590
Merge branch 'master' into branch-protection-anyone
davidsvantesson 2461d52
Merge remote-tracking branch 'upstream/master' into branch-protection…
davidsvantesson d1ecef6
Merge branch 'master' into branch-protection-anyone
davidsvantesson d48fcb4
Merge branch 'master' into branch-protection-anyone
davidsvantesson 459c59c
Merge branch 'master' into branch-protection-anyone
davidsvantesson 283be88
Merge branch 'master' into branch-protection-anyone
davidsvantesson 9d3da22
Clear settings if higher level setting is not set
davidsvantesson 148e1d6
Move official reviews to db instead of counting approvals each time
davidsvantesson 8afcf90
migration
davidsvantesson c296126
Merge branch 'master' into branch-protection-anyone
davidsvantesson 5ee7ae2
fix
davidsvantesson b63974e
fix migration
davidsvantesson 6b04006
fix migration
davidsvantesson e6908f5
Remove NOT NULL from EnableWhitelist as migration isn't possible
davidsvantesson 2cad7bb
Fix migration, reviews are connected to issues.
davidsvantesson 8af34e3
Fix SQL query issues in GetReviewersByPullID.
davidsvantesson 2187c6f
Merge branch 'master' into branch-protection-anyone
davidsvantesson b1537d4
Simplify function GetReviewersByIssueID
davidsvantesson 8198531
Handle reviewers that has been deleted
davidsvantesson 5aa2e18
Ensure reviews for test is in a well defined order
davidsvantesson 6ca746a
Only clear and set official reviews when it is an approve or reject.
davidsvantesson f81f209
Merge branch 'master' into branch-protection-anyone
techknowlogick 52760dd
Merge branch 'master' into branch-protection-anyone
davidsvantesson 93ede5a
Merge branch 'master' into branch-protection-anyone
techknowlogick 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 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.
This line I don't understand. If you have
review.id
in the row, all lines are already unique (unless there were multiple users with the same id which should never happen). AMAX(updated_unix)
will be the same asupdated_unix
without the Group By. 🤔What is it that you are trying to accomplish? Bring up the latest review? The query from the migration should achieve that.
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 function shall return the latest review of each reviewer (not necessary official reviewers). I see that I actually don't use the change in this function, probably rewrote something. I think later on the information on which reviews are "official" should be shown on the pull request page.
The
max(review.updated_unix) as review_updated_unix
is used to sort the list and ensure the group by gets the latest review. However it might have been enough to get themax(id)
instead, I don't see how reviews from same reviewer could change order.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 kind of query will not work. If you have two different
review.type
(e.g. comment + approval) from the same user, you'll get two rows because Group By will see them as different values. To get the latest record you need to do a select in select like the one used in the migration:Of course the example above requires some adaptation to get the JOIN and the columns you're expecting.
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.
It is actually solved further down in the function (I don't say it is a good solution 😄)
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.
Your query might work... although it doesn't work to just remove some of the group by fields for pgsql and mysql (due to some only_full_group_by setting).
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.
So I didn't want to touch this function more than needed (and actually I can revert the changes I done). But the only thing I added was the
Official
field to the results, and hence added in SQL where necessary. The multiple rows is handled by the code later already.I think maybe this function tries to do too much in SQL which makes it a bit complex.
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.
To exemplify this, let me give you one example. Suppose you have this in the
review
table:If you do:
This is what you will get:
As you see, the two reviews from user
#1
were consolidated in one row, as the fieldsuser_id
andreview_type
are the same for all records; user#3
is not a problem, but the two reviews from user#2
show up as different rows.That's why the only way to get this SQL right is with a sub-query:
Will give you:
So, these are the records that you're looking for:
returns:
which is what you want. With this method you can perform joins too:
There's probably a nice way to write all of this with a couple of xorm directives (e.g. I think you can write the subquery in builder and use it in the
In()
operator, but I'm not sure), so I think it will be just quicker to do it withsess.SQL()
like you did in migrations.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.
Very long informative response 😄.
I just wanted to point out that the existing code actually works, although not very efficient or elegant. I will see if I can rewrite the SQL query in a better way.
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, sorry! I didn't realize that the code wasn't yours. It's my tendency of checking the right column more thoroughly than the left one. 😋
If you just don't feel like doing that change just let me know, because that's the only thing I was waiting for to give my 👍.
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 rewrote the code and think it is easier to understand now although there will be a few more sql queries, but normally there will not be that many reviews for a PR.