Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343)

* Chore: Add user service method SetUsingOrg

* Chore: Add user service method GetSignedInUserWithCacheCtx

* Use method GetSignedInUserWithCacheCtx from user service

* Fix lint after rebase

* Fix lint

* Fix lint error

* roll back some changes

* Roll back changes in api and middleware

* Add xorm tags to SignedInUser ID fields
This commit is contained in:
idafurjes
2022-08-11 13:28:55 +02:00
committed by GitHub
parent ca72cd570e
commit a14621fff6
191 changed files with 1108 additions and 1049 deletions
+9 -9
View File
@@ -27,7 +27,7 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
query: &models.GetOrgUsersQuery{
OrgId: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {ac.ScopeUsersAll}}},
},
},
@@ -38,7 +38,7 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
query: &models.GetOrgUsersQuery{
OrgId: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {""}}},
},
},
@@ -49,7 +49,7 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
query: &models.GetOrgUsersQuery{
OrgId: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {
"users:id:1",
"users:id:5",
@@ -76,7 +76,7 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
if !hasWildcardScope(tt.query.User, ac.ActionOrgUsersRead) {
for _, u := range tt.query.Result {
assert.Contains(t, tt.query.User.Permissions[tt.query.User.OrgId][ac.ActionOrgUsersRead], fmt.Sprintf("users:id:%d", u.UserId))
assert.Contains(t, tt.query.User.Permissions[tt.query.User.OrgID][ac.ActionOrgUsersRead], fmt.Sprintf("users:id:%d", u.UserId))
}
}
})
@@ -96,7 +96,7 @@ func TestSQLStore_SearchOrgUsers(t *testing.T) {
query: &models.SearchOrgUsersQuery{
OrgID: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {ac.ScopeUsersAll}}},
},
},
@@ -107,7 +107,7 @@ func TestSQLStore_SearchOrgUsers(t *testing.T) {
query: &models.SearchOrgUsersQuery{
OrgID: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {""}}},
},
},
@@ -118,7 +118,7 @@ func TestSQLStore_SearchOrgUsers(t *testing.T) {
query: &models.SearchOrgUsersQuery{
OrgID: 1,
User: &user.SignedInUser{
OrgId: 1,
OrgID: 1,
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {
"users:id:1",
"users:id:5",
@@ -141,7 +141,7 @@ func TestSQLStore_SearchOrgUsers(t *testing.T) {
if !hasWildcardScope(tt.query.User, ac.ActionOrgUsersRead) {
for _, u := range tt.query.Result.OrgUsers {
assert.Contains(t, tt.query.User.Permissions[tt.query.User.OrgId][ac.ActionOrgUsersRead], fmt.Sprintf("users:id:%d", u.UserId))
assert.Contains(t, tt.query.User.Permissions[tt.query.User.OrgID][ac.ActionOrgUsersRead], fmt.Sprintf("users:id:%d", u.UserId))
}
}
})
@@ -272,7 +272,7 @@ func seedOrgUsers(t *testing.T, store *SQLStore, numUsers int) {
}
func hasWildcardScope(user *user.SignedInUser, action string) bool {
for _, scope := range user.Permissions[user.OrgId][action] {
for _, scope := range user.Permissions[user.OrgID][action] {
if strings.HasSuffix(scope, ":*") {
return true
}