-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 ignored errors when checking if organization, team member #3177
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3177 +/- ##
=========================================
- Coverage 34.95% 34.9% -0.06%
=========================================
Files 277 277
Lines 40014 40108 +94
=========================================
+ Hits 13987 13998 +11
- Misses 23988 24061 +73
- Partials 2039 2049 +10
Continue to review full report at Codecov.
|
@@ -401,8 +414,9 @@ func ChangeOrgUserStatus(orgID, uid int64, public bool) error { | |||
|
|||
// AddOrgUser adds new user to given organization. | |||
func AddOrgUser(orgID, uid int64) error { |
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 function should be removed since we have dropped the UI to add user to org.
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.
But user is still added to org when adding it to team
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.
That should be in a transaction but not this function
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.
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.
I will address this in a separate PR
models/org.go
Outdated
func IsOrganizationOwner(orgID, uid int64) bool { | ||
has, _ := x. | ||
func IsOrganizationOwner(orgID, uid int64) (bool, error) { | ||
return x. | ||
Where("is_owner=?", true). | ||
And("uid=?", uid). | ||
And("org_id=?", orgID). | ||
Get(new(OrgUser)) |
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.
Get
-> Exist
will has better performance.
Exist(new(OrgUser))
-> Table("org_user").Exist()
will has better performance and less memory usage.
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.
done
models/org.go
Outdated
func IsOrganizationMember(orgID, uid int64) bool { | ||
has, _ := x. | ||
func IsOrganizationMember(orgID, uid int64) (bool, error) { | ||
return x. | ||
Where("uid=?", uid). | ||
And("org_id=?", orgID). | ||
Get(new(OrgUser)) |
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.
As above.
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.
done
models/org.go
Outdated
func IsPublicMembership(orgID, uid int64) bool { | ||
has, _ := x. | ||
func IsPublicMembership(orgID, uid int64) (bool, error) { | ||
return x. | ||
Where("uid=?", uid). | ||
And("org_id=?", orgID). | ||
And("is_public=?", true). | ||
Get(new(OrgUser)) |
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.
As above
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.
done
models/org_team.go
Outdated
func isTeamMember(e Engine, orgID, teamID, userID int64) bool { | ||
has, _ := e. | ||
func isTeamMember(e Engine, orgID, teamID, userID int64) (bool, error) { | ||
return e. | ||
Where("org_id=?", orgID). | ||
And("team_id=?", teamID). | ||
And("uid=?", userID). | ||
Get(new(TeamUser)) |
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.
As above.
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.
done
All Get -> Exist changes will not block this PR. If this PR didn't do that, I will send another PR to do that. |
f10cbf9
to
f540076
Compare
Please use more descriptive titles but otherwise LGTM |
models/org.go
Outdated
return IsOrganizationOwner(org.ID, uid) | ||
isOwner, err := IsOrganizationOwner(org.ID, uid) | ||
if err != nil { | ||
log.Error(4, "IsOwnedBy: %v", err) |
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 I don't know if the log will affect the SSH output? Maybe change the function's signature to IsOwnedBy(uid int64) (bool, error)
or maybe just ignore them.
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 had thought this function was used in templates (and thus did not want to change the signature), but it looks like it isn't. Will update signature.
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.
Also, I don't see how this specific call to log.Error
is different than any call to log.Error
currently in the codebase, and therefore I don't see why this particular log.Error
raises concerns about SSH output that other log.Error
calls do not.
@ethantkoenig a new issue to be considered that if the log will affect SSH console output. |
f540076
to
6b1948e
Compare
@@ -234,13 +234,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { | |||
return | |||
} | |||
|
|||
if ctx.Repo.Owner.IsOrganization() { |
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.
These can be removed, because we have already checked ctx.Repo.IsOwner()
.
ctx.Status(404) | ||
return | ||
} |
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 not use only one return on line 149?
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.
Because you may fall through to the redirect (lines 151-153)
LGTM |
Get(..)
->Exist()
micro-optimizationrepo.SettingsPost(..)