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

Fix ignored errors when checking if organization, team member #3177

Merged
merged 2 commits into from
Dec 21, 2017

Conversation

ethantkoenig
Copy link
Member

@ethantkoenig ethantkoenig commented Dec 13, 2017

  • Add checks for previously-ignored errors in various org functions.
  • Get(..) -> Exist() micro-optimization
  • Remove unnecessary checks in repo.SettingsPost(..)

@lafriks lafriks added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Dec 13, 2017
@codecov-io
Copy link

codecov-io commented Dec 13, 2017

Codecov Report

Merging #3177 into master will decrease coverage by 0.05%.
The diff coverage is 23.95%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
routers/api/v1/repo/fork.go 0% <0%> (ø) ⬆️
routers/api/v1/api.go 75.24% <0%> (-1.11%) ⬇️
routers/api/v1/org/team.go 4.67% <0%> (-0.06%) ⬇️
routers/api/v1/org/member.go 0% <0%> (ø) ⬆️
modules/context/org.go 0.86% <0%> (-0.05%) ⬇️
models/user.go 39.76% <0%> (-0.44%) ⬇️
routers/repo/setting.go 4.72% <0%> (+0.15%) ⬆️
models/repo.go 43.38% <10%> (-0.02%) ⬇️
routers/api/v1/repo/repo.go 38.46% <16.12%> (-1.64%) ⬇️
routers/repo/repo.go 22.44% <20%> (-0.01%) ⬇️
... and 7 more

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 5294821...e75a2fd. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 13, 2017
@@ -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 {
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

true 👍

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 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))
Copy link
Member

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.

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

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))
Copy link
Member

Choose a reason for hiding this comment

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

As above.

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

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))
Copy link
Member

Choose a reason for hiding this comment

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

As above

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

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))
Copy link
Member

Choose a reason for hiding this comment

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

As above.

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

@lunny
Copy link
Member

lunny commented Dec 14, 2017

All Get -> Exist changes will not block this PR. If this PR didn't do that, I will send another PR to do that.

@ethantkoenig
Copy link
Member Author

@lafriks @lunny Friendly ping

@lafriks lafriks changed the title Fix ignored errors Fix ignored errors when checking if organization, team member Dec 18, 2017
@lafriks
Copy link
Member

lafriks commented Dec 18, 2017

Please use more descriptive titles but otherwise LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 18, 2017
models/org.go Outdated
return IsOrganizationOwner(org.ID, uid)
isOwner, err := IsOrganizationOwner(org.ID, uid)
if err != nil {
log.Error(4, "IsOwnedBy: %v", err)
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@lunny lunny added this to the 1.4.0 milestone Dec 19, 2017
@lunny
Copy link
Member

lunny commented Dec 19, 2017

@ethantkoenig a new issue to be considered that if the log will affect SSH console output.

@@ -234,13 +234,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
return
}

if ctx.Repo.Owner.IsOrganization() {
Copy link
Member Author

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
}
Copy link
Member

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?

Copy link
Member Author

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)

@lunny
Copy link
Member

lunny commented Dec 21, 2017

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 Dec 21, 2017
@lafriks lafriks merged commit 515cdaa into go-gitea:master Dec 21, 2017
@ethantkoenig ethantkoenig deleted the ignored_errors branch February 21, 2018 05:56
@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/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants