Skip to content

[WIP] Enforce usertype via GetIndividualUserByName #2118

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
wants to merge 5 commits into from

Conversation

sapk
Copy link
Member

@sapk sapk commented Jul 6, 2017

and switch to GetOrgByName when we want org.

As it modify the comportement of GetUserByName this need more testing (so WIP).
Maybe we will need a generic GetUserOrOrgByName method for some cases.

Follow #2117

@sapk sapk force-pushed the enforce-usertype branch from 8f42926 to b96df94 Compare July 6, 2017 22:58
Use GetOrgByName in place of GetUserByName
@sapk sapk force-pushed the enforce-usertype branch from b96df94 to e7ba9e8 Compare July 6, 2017 22:59
@sapk sapk changed the title [WIP] Enforce usertype for GetUserByName Enforce usertype for GetUserByName Jul 6, 2017
@sapk
Copy link
Member Author

sapk commented Jul 6, 2017

PR rebased after following PR. Tests are passing so should be good ^^

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 6, 2017
@lunny lunny added this to the 1.2.0 milestone Jul 7, 2017
@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Jul 7, 2017
@lunny
Copy link
Member

lunny commented Jul 7, 2017

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 Jul 7, 2017
Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

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

This won't work. In RepoAssignment() (and probably a lot of other places as well), we use GetUserByName(..) for both individuals and organizations.

@ethantkoenig
Copy link
Member

Also, if we're going to change the behavior of GetUserByName(..) to only look for individual users, we should rename it to GetIndividualUserByName(..). Otherwise it will be confusing that GetUserByName(..) only looks for individual users but GetUserByID(..) looks for any user (individual or org).

@sapk
Copy link
Member Author

sapk commented Jul 7, 2017

@ethantkoenig I will create GetIndividualUserByName and used it as base to remove duplicate code. I will update code where GetIndividualUserByName need to be used in place of GetUserByName (that will stay generic).

@sapk sapk changed the title Enforce usertype for GetUserByName [WIP] Enforce usertype via GetIndividualUserByName Jul 7, 2017
@sapk
Copy link
Member Author

sapk commented Jul 7, 2017

I have two questions for this implementation. Does I add a new ErrIndividualUserNotExist or keep using ErrUserNotExist ? In the last case, if we consider User as a complete generic then ErrOrgNotExist could be also removed ?

@sapk
Copy link
Member Author

sapk commented Jul 7, 2017

I am going for adding a field usertype to generic ErrUserNotExist and remove ErrOrgNotExist.

@sapk sapk force-pushed the enforce-usertype branch from 300b5b6 to 1f12214 Compare July 7, 2017 12:53
@sapk sapk force-pushed the enforce-usertype branch from 1f12214 to 7e93f6d Compare July 7, 2017 12:55
@@ -413,7 +413,7 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR
sr := source.Cfg.(*LDAPConfig).SearchEntry(login, password, source.Type == LoginDLDAP)
if sr == nil {
// User not in LDAP, do nothing
return nil, ErrUserNotExist{0, login, 0}
return nil, ErrUserNotExist{0, login, 0, -1}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why -1? I think it is better user type individual as you can't login with organization. Same in most other places.

Copy link
Member Author

Choose a reason for hiding this comment

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

A default value ^^ correspoding to any value.
I will review each case for determining.
I was planning on keep -1 when we don't check the type of the user but for external sources this could be set to IndividualUser as it is supposed.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't introduce (more) magic numbers, if you want -1 to be "I don't care" then const UserTypeIDoNotCare -1 🙂

@lunny lunny added the pr/wip This PR is not ready for review label Jul 12, 2017
@lunny lunny modified the milestones: 1.3.0, 1.2.0 Jul 12, 2017
@lunny lunny modified the milestones: 1.3.0, 1.x.x Oct 16, 2017
@techknowlogick
Copy link
Member

Closing as outdated. @sapk please re-open if needed.

@lunny lunny removed this from the 1.x.x milestone Oct 29, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. pr/wip This PR is not ready for review 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.

7 participants