-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix implementation of repo Home func #2601
Conversation
routers/repo/view.go
Outdated
unit, ok := models.Units[tp] | ||
if ok { | ||
unit, ok := models.Units[ctx.Repo.Repository.Units[0].Type] | ||
if ok && unit.URI != models.UnitCode.URI { |
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.
Seems it will never be models.UnitCode.URI
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 shouldn't, but to be sure we don't have dead loop.
Codecov Report
@@ Coverage Diff @@
## master #2601 +/- ##
==========================================
- Coverage 27.3% 27.29% -0.01%
==========================================
Files 86 86
Lines 17139 17144 +5
==========================================
Hits 4680 4680
- Misses 11781 11786 +5
Partials 678 678
Continue to review full report at Codecov.
|
I see 1 problem here... If the first unit in slice is external issue/wiki, we will be redirected to it. This is actual problem my colleague found few days ago. |
I don't see the point in changing this. |
@daviian But you shouldn't care about sorting in this function... You can sort it as u wish, but I know only about having 1 slice of available units, nothing else. |
Fixed problem with redirecting to external issue/wiki if there is another option. |
As I said: Doesn't ensure that leftmost tab is opened. |
@daviian You are right. This fix is not about that. Logic for that can be added in another PR. |
routers/repo/view.go
Outdated
unit, ok := models.Units[tp] | ||
if ok { | ||
unit, ok := models.Units[firstAvailable] | ||
if ok && unit.URI != models.UnitCode.URI { |
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 is the unit.URI != models.UnitCode.URI
condition necessary? From what I can tell, there is no way firstAvailable
can be models.UnitTypeCode
at this point
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 avoid redirecting to the same page (causing an infinite loop). Safer method would be to check requested uri vs computed uri....
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.
@Morlinest but that can't happen as only unit with same url is code and if it will be allowed it will render and return and won't get to this point
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.
@lafriks It shouldn't, now, but... There can also be new unit with same uri like Issue
and ExternalTracker
or Wiki
and ExternalWiki
. You know what's in code, that function doesn't. I don't think making safe functions is wrong.
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.
Actually I've just finished even more secure implementation. It can be used for each unit handler.
38559e9
to
02ff842
Compare
@ethantkoenig @lunny @ethantkoenig Removed uri check... |
LGTM |
I've changed implementation to use /cc @ethantkoenig @lafriks @daviian Edit: Add type safety to map version means adding 5 lines of code. |
routers/repo/view.go
Outdated
if tp == models.UnitTypeCode { | ||
renderCode(ctx) | ||
return | ||
var firstUnit struct { |
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.
Using double pointers and internal structs seems unnecessarily complicated. Can we please just do something like the following:
if ctx.Repo.Repository.UnitEnabled(models.UnitTypeCode) {
renderCode(ctx)
return
}
redirectUnitType = ctx.Repo.Repository.Units[0].Type
for _, unit := range ctx.Repo.Repository.Units {
// LessThan is a helper method to add to unit type, we can
// implement it so that it favors non-external units
if unit.Type.LessThan(redirectUnitType) {
redirectUnitType = unit.Type
}
}
redirectUnit := models.Units[redirectUnitType]
ctx.Redirect(fmt.Sprintf("%s/%s%s", setting.AppSubURL,
ctx.Repo.Repository.FullName(),
redirectUnit.URI))
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.
OK,I'll use map version instead. The reason for not using only 1 variable is to avoid redirecting to external tracker or wiki if there is another (internal) tab available.
Edit: Read your solution again, it would be better. I've made it too complicated
a3b7917
to
2dc9a49
Compare
@ethantkoenig @daviian Done |
@Morlinest Please add my changed fixture file from #2603 for testing. |
2dc9a49
to
bd98c34
Compare
@daviian Done |
LGTM |
No description provided.