-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
WIP: add support for private repos to open issues or wiki #5833
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,25 +23,49 @@ func (p *Permission) IsAdmin() bool { | |
|
||
// HasAccess returns true if the current user has at least read access to any unit of this repository | ||
func (p *Permission) HasAccess() bool { | ||
for _, u := range p.Units { | ||
if u.AllowAnonymous { | ||
return true | ||
} | ||
} | ||
|
||
if p.UnitsMode == nil { | ||
return p.AccessMode >= AccessModeRead | ||
} | ||
return len(p.UnitsMode) > 0 | ||
} | ||
|
||
// UnitAccessMode returns current user accessmode to the specify unit of the repository | ||
// UnitAccessMode returns the unit's minial accessmode to be accessed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am guessing minial is supposed to minimal ? |
||
func (p *Permission) UnitAccessMode(unitType UnitType) AccessMode { | ||
if p.UnitsMode == nil { | ||
for _, u := range p.Units { | ||
if u.Type == unitType { | ||
return p.AccessMode | ||
var found bool | ||
for _, u := range p.Units { | ||
if u.Type == unitType { | ||
if u.AllowAnonymous { | ||
return AccessModeRead | ||
} | ||
found = true | ||
} | ||
} | ||
|
||
if p.UnitsMode == nil { | ||
if found { | ||
return p.AccessMode | ||
} | ||
return AccessModeNone | ||
} | ||
return p.UnitsMode[unitType] | ||
} | ||
|
||
// CanAnonymousAccess returns true if anonymous access is enabled | ||
func (p *Permission) CanAnonymousAccess(unitType UnitType) bool { | ||
for _, u := range p.Units { | ||
if u.Type == unitType { | ||
return u.AllowAnonymous | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// CanAccess returns true if user has mode access to the unit of the repository | ||
func (p *Permission) CanAccess(mode AccessMode, unitType UnitType) bool { | ||
return p.UnitAccessMode(unitType) >= mode | ||
|
@@ -96,22 +120,19 @@ func GetUserRepoPermission(repo *Repository, user *User) (Permission, error) { | |
} | ||
|
||
func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permission, err error) { | ||
// anonymous user visit private repo. | ||
// TODO: anonymous user visit public unit of private repo??? | ||
if user == nil && repo.IsPrivate { | ||
perm.AccessMode = AccessModeNone | ||
return | ||
} | ||
|
||
// always load repo unit so that we can read unit's allow_anonymous | ||
if err = repo.getUnits(e); err != nil { | ||
return | ||
} | ||
|
||
perm.Units = repo.Units | ||
|
||
// anonymous visit public repo | ||
// for anonymous user | ||
if user == nil { | ||
perm.AccessMode = AccessModeRead | ||
if repo.IsPrivate { | ||
perm.AccessMode = AccessModeNone | ||
} else { | ||
perm.AccessMode = AccessModeRead | ||
} | ||
return | ||
} | ||
|
||
|
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.