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

improve protected branch to add whitelist support #2451

Merged
merged 9 commits into from
Sep 14, 2017

Conversation

lunny
Copy link
Member

@lunny lunny commented Sep 2, 2017

This PR will add a protected branch edit page to enable or disable protected branch. It also add support to whitelist users or whitelist teams so that special users could push to the branch.

-1
-2

@lunny lunny added the backport/done All backports for this PR have been created label Sep 2, 2017
@lunny lunny added this to the 1.2.0 milestone Sep 2, 2017
@lunny lunny added type/enhancement An improvement of existing functionality and removed backport/done All backports for this PR have been created labels Sep 2, 2017
@lunny lunny modified the milestones: 1.3.0, 1.2.0 Sep 2, 2017
if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
return fmt.Errorf("DROP COLUMN can_push: %v", err)
}
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need also migration support for PostgreSQL and MSSQL

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have done that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't see, my mistake :)

if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
return fmt.Errorf("DROP COLUMN can_push: %v", err)
}
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't see, my mistake :)

} else {
if protectBranch != nil {
if err := ctx.Repo.Repository.DeleteProtectedBranch(protectBranch.ID); err != nil {
ctx.Handle(500, "UpdateProtectBranch", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong error message

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -922,6 +922,16 @@ settings.protected_branch=Branch Protection
settings.protected_branch_can_push=Allow push?
settings.protected_branch_can_push_yes=You can push
settings.protected_branch_can_push_no=You can not push
settings.branch_protection = Branch Protection for <b>%s</b>
settings.protect_this_branch = Protect this branch
settings.protect_this_branch_desc = Disable force pushes and prevent from deletion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest Disable force pushes and prevent deletion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

settings.branch_protection = Branch Protection for <b>%s</b>
settings.protect_this_branch = Protect this branch
settings.protect_this_branch_desc = Disable force pushes and prevent from deletion.
settings.update_protect_branch_success = Change branch protect options successfully.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest Branch protect options changed successfully.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

settings.protect_whitelist_committers_desc = Add people or teams to whitelist of direct push to this branch. Users in whitelist will bypass require pull request check.
settings.protect_whitelist_users = Users who can push to this branch
settings.protect_whitelist_search_users = Search users
settings.protect_whitelist_teams = Teams for which members of them can push to this branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest Teams whose members can push to this branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

settings.protect_this_branch_desc = Disable force pushes and prevent from deletion.
settings.update_protect_branch_success = Change branch protect options successfully.
settings.protect_whitelist_committers = Whitelist who can push to this branch
settings.protect_whitelist_committers_desc = Add people or teams to whitelist of direct push to this branch. Users in whitelist will bypass require pull request check.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest Add users or teams to this branch's whitelist. Whitelisted users bypass the typical push restrictions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank space

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@lafriks
Copy link
Member

lafriks commented Sep 4, 2017

LGTM

@tboerger tboerger added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Sep 4, 2017
if protectBranch.ID == 0 {
if _, err = x.Insert(protectBranch); err != nil {
return fmt.Errorf("Insert: %v", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return nil

@bkcsoft
Copy link
Member

bkcsoft commented Sep 4, 2017

@lunny From the screenshot, do we really need to differentiate between Users and Teams? Can't they be in the same list? (Gitea knows the difference internally anyhow)

@lunny
Copy link
Member Author

lunny commented Sep 4, 2017

@bkcsoft For a non-organization repository, we only have users. For an organization repository, we will have users and teams. I think both are needed.

@bkcsoft
Copy link
Member

bkcsoft commented Sep 4, 2017

@lunny Right, the list it returns would be different, but I still don't understand why it needs to be 2 lists?

@lunny
Copy link
Member Author

lunny commented Sep 4, 2017

Two lists is easy to implement. 😄 We can optimist it later. We still need pull request control, status check and approval control.

@lafriks
Copy link
Member

lafriks commented Sep 4, 2017

I also would like to see there single list instead of two but I agree that it can be implemented later

@lunny lunny force-pushed the lunny/improve_proteced_branch branch 2 times, most recently from 7cea815 to 1666907 Compare September 6, 2017 10:52
} else if has {
return nil
}
func (p Int64Slice) Len() int { return len(p) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to move these helpers for int64 slices to a util file? They don't have anything to do with branches.

models/org.go Outdated
@@ -577,6 +577,11 @@ func (org *User) getUserTeamIDs(e Engine, userID int64) ([]int64, error) {
Find(&teamIDs)
}

// TeamsHaveAccessToRepo returns all teamsthat have given access level to the repository.
func (org *User) TeamsHaveAccessToRepo(repoID int64, mode AccessMode) ([]*Team, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest renaming to TeamsWithAccessToRepo(and similarly GetTeamsWithAccessToRepo)

models/repo.go Outdated
}

// getUsersWithAccesMode returns users that have at least given access mode to the repository.
func (repo *Repository) getUsersWithAccesMode(e Engine, mode AccessMode) (_ []*User, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misspelled Access

@lunny lunny force-pushed the lunny/improve_proteced_branch branch 2 times, most recently from 0ad42cc to bcadda5 Compare September 12, 2017 11:36
@lunny lunny mentioned this pull request Sep 12, 2017
20 tasks
@lunny
Copy link
Member Author

lunny commented Sep 12, 2017

will be part of #32

@lunny
Copy link
Member Author

lunny commented Sep 12, 2017

@ethantkoenig all done.

@LanaYuan
Copy link

my gitea version 1.2 the protect branch tool didn't work, but when i use version 1.1.3, it works well

@lunny
Copy link
Member Author

lunny commented Sep 14, 2017

@LanaYuan could you try on https://try.gitea.io

@lunny lunny force-pushed the lunny/improve_proteced_branch branch from bcadda5 to f71a25a Compare September 14, 2017 07:28
@appleboy
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 14, 2017
@codecov-io
Copy link

Codecov Report

Merging #2451 into master will decrease coverage by 0.08%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2451      +/-   ##
==========================================
- Coverage   27.83%   27.75%   -0.09%     
==========================================
  Files          83       83              
  Lines       16835    16886      +51     
==========================================
  Hits         4686     4686              
- Misses      11474    11525      +51     
  Partials      675      675
Impacted Files Coverage Δ
models/repo.go 13.53% <0%> (-0.2%) ⬇️
modules/base/tool.go 73.99% <0%> (-1.41%) ⬇️
models/org_team.go 52.74% <0%> (-1.43%) ⬇️
models/org.go 69.36% <0%> (-0.3%) ⬇️
models/branches.go 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be3319b...f71a25a. Read the comment docs.

@lunny lunny merged commit 1739e84 into go-gitea:master Sep 14, 2017
@lunny lunny deleted the lunny/improve_proteced_branch branch September 14, 2017 08:16
@daviian daviian mentioned this pull request Sep 21, 2017
7 tasks
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants