PLT-7 adding loc db calls for oauth table
Этот коммит содержится в:
@@ -5,6 +5,7 @@ package store
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -52,7 +53,7 @@ func (as SqlOAuthStore) CreateIndexesIfNotExists() {
|
||||
as.CreateIndexIfNotExists("idx_oauthauthdata_client_id", "OAuthAuthData", "Code")
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) StoreChannel {
|
||||
func (as SqlOAuthStore) SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -86,7 +87,7 @@ func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) StoreChannel {
|
||||
func (as SqlOAuthStore) UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -127,7 +128,7 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) GetApp(id string) StoreChannel {
|
||||
func (as SqlOAuthStore) GetApp(T goi18n.TranslateFunc, id string) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -150,7 +151,7 @@ func (as SqlOAuthStore) GetApp(id string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) GetAppByUser(userId string) StoreChannel {
|
||||
func (as SqlOAuthStore) GetAppByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -172,7 +173,7 @@ func (as SqlOAuthStore) GetAppByUser(userId string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) StoreChannel {
|
||||
func (as SqlOAuthStore) SaveAccessData(T goi18n.TranslateFunc, accessData *model.AccessData) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -198,7 +199,7 @@ func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) StoreChanne
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) GetAccessData(token string) StoreChannel {
|
||||
func (as SqlOAuthStore) GetAccessData(T goi18n.TranslateFunc, token string) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -221,7 +222,7 @@ func (as SqlOAuthStore) GetAccessData(token string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) GetAccessDataByAuthCode(authCode string) StoreChannel {
|
||||
func (as SqlOAuthStore) GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode string) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -248,7 +249,7 @@ func (as SqlOAuthStore) GetAccessDataByAuthCode(authCode string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAccessData(token string) StoreChannel {
|
||||
func (as SqlOAuthStore) RemoveAccessData(T goi18n.TranslateFunc, token string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
@@ -265,7 +266,7 @@ func (as SqlOAuthStore) RemoveAccessData(token string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) StoreChannel {
|
||||
func (as SqlOAuthStore) SaveAuthData(T goi18n.TranslateFunc, authData *model.AuthData) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -292,7 +293,7 @@ func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) GetAuthData(code string) StoreChannel {
|
||||
func (as SqlOAuthStore) GetAuthData(T goi18n.TranslateFunc, code string) StoreChannel {
|
||||
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
@@ -315,7 +316,7 @@ func (as SqlOAuthStore) GetAuthData(code string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAuthData(code string) StoreChannel {
|
||||
func (as SqlOAuthStore) RemoveAuthData(T goi18n.TranslateFunc, code string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
@@ -333,7 +334,7 @@ func (as SqlOAuthStore) RemoveAuthData(code string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) StoreChannel {
|
||||
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
|
||||
@@ -5,6 +5,7 @@ package store
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func TestOAuthStoreSaveApp(t *testing.T) {
|
||||
a1.CallbackUrls = []string{"https://nowhere.com"}
|
||||
a1.Homepage = "https://nowhere.com"
|
||||
|
||||
if err := (<-store.OAuth().SaveApp(&a1)).Err; err != nil {
|
||||
if err := (<-store.OAuth().SaveApp(utils.T, &a1)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -30,13 +31,13 @@ func TestOAuthStoreGetApp(t *testing.T) {
|
||||
a1.Name = "TestApp" + model.NewId()
|
||||
a1.CallbackUrls = []string{"https://nowhere.com"}
|
||||
a1.Homepage = "https://nowhere.com"
|
||||
Must(store.OAuth().SaveApp(&a1))
|
||||
Must(store.OAuth().SaveApp(utils.T, &a1))
|
||||
|
||||
if err := (<-store.OAuth().GetApp(a1.Id)).Err; err != nil {
|
||||
if err := (<-store.OAuth().GetApp(utils.T, a1.Id)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := (<-store.OAuth().GetAppByUser(a1.CreatorId)).Err; err != nil {
|
||||
if err := (<-store.OAuth().GetAppByUser(utils.T, a1.CreatorId)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -49,13 +50,13 @@ func TestOAuthStoreUpdateApp(t *testing.T) {
|
||||
a1.Name = "TestApp" + model.NewId()
|
||||
a1.CallbackUrls = []string{"https://nowhere.com"}
|
||||
a1.Homepage = "https://nowhere.com"
|
||||
Must(store.OAuth().SaveApp(&a1))
|
||||
Must(store.OAuth().SaveApp(utils.T, &a1))
|
||||
|
||||
a1.CreateAt = 1
|
||||
a1.ClientSecret = "pwd"
|
||||
a1.CreatorId = "12345678901234567890123456"
|
||||
a1.Name = "NewName"
|
||||
if result := <-store.OAuth().UpdateApp(&a1); result.Err != nil {
|
||||
if result := <-store.OAuth().UpdateApp(utils.T, &a1); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
ua1 := (result.Data.([2]*model.OAuthApp)[0])
|
||||
@@ -82,7 +83,7 @@ func TestOAuthStoreSaveAccessData(t *testing.T) {
|
||||
a1.Token = model.NewId()
|
||||
a1.RefreshToken = model.NewId()
|
||||
|
||||
if err := (<-store.OAuth().SaveAccessData(&a1)).Err; err != nil {
|
||||
if err := (<-store.OAuth().SaveAccessData(utils.T, &a1)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -94,9 +95,9 @@ func TestOAuthStoreGetAccessData(t *testing.T) {
|
||||
a1.AuthCode = model.NewId()
|
||||
a1.Token = model.NewId()
|
||||
a1.RefreshToken = model.NewId()
|
||||
Must(store.OAuth().SaveAccessData(&a1))
|
||||
Must(store.OAuth().SaveAccessData(utils.T, &a1))
|
||||
|
||||
if result := <-store.OAuth().GetAccessData(a1.Token); result.Err != nil {
|
||||
if result := <-store.OAuth().GetAccessData(utils.T, a1.Token); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
ra1 := result.Data.(*model.AccessData)
|
||||
@@ -105,11 +106,11 @@ func TestOAuthStoreGetAccessData(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := (<-store.OAuth().GetAccessDataByAuthCode(a1.AuthCode)).Err; err != nil {
|
||||
if err := (<-store.OAuth().GetAccessDataByAuthCode(utils.T, a1.AuthCode)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := (<-store.OAuth().GetAccessDataByAuthCode("junk")).Err; err != nil {
|
||||
if err := (<-store.OAuth().GetAccessDataByAuthCode(utils.T, "junk")).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -121,13 +122,13 @@ func TestOAuthStoreRemoveAccessData(t *testing.T) {
|
||||
a1.AuthCode = model.NewId()
|
||||
a1.Token = model.NewId()
|
||||
a1.RefreshToken = model.NewId()
|
||||
Must(store.OAuth().SaveAccessData(&a1))
|
||||
Must(store.OAuth().SaveAccessData(utils.T, &a1))
|
||||
|
||||
if err := (<-store.OAuth().RemoveAccessData(a1.Token)).Err; err != nil {
|
||||
if err := (<-store.OAuth().RemoveAccessData(utils.T, a1.Token)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-store.OAuth().GetAccessDataByAuthCode(a1.AuthCode); result.Err != nil {
|
||||
if result := <-store.OAuth().GetAccessDataByAuthCode(utils.T, a1.AuthCode); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
if result.Data != nil {
|
||||
@@ -144,7 +145,7 @@ func TestOAuthStoreSaveAuthData(t *testing.T) {
|
||||
a1.UserId = model.NewId()
|
||||
a1.Code = model.NewId()
|
||||
|
||||
if err := (<-store.OAuth().SaveAuthData(&a1)).Err; err != nil {
|
||||
if err := (<-store.OAuth().SaveAuthData(utils.T, &a1)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -156,9 +157,9 @@ func TestOAuthStoreGetAuthData(t *testing.T) {
|
||||
a1.ClientId = model.NewId()
|
||||
a1.UserId = model.NewId()
|
||||
a1.Code = model.NewId()
|
||||
Must(store.OAuth().SaveAuthData(&a1))
|
||||
Must(store.OAuth().SaveAuthData(utils.T, &a1))
|
||||
|
||||
if err := (<-store.OAuth().GetAuthData(a1.Code)).Err; err != nil {
|
||||
if err := (<-store.OAuth().GetAuthData(utils.T, a1.Code)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -170,13 +171,13 @@ func TestOAuthStoreRemoveAuthData(t *testing.T) {
|
||||
a1.ClientId = model.NewId()
|
||||
a1.UserId = model.NewId()
|
||||
a1.Code = model.NewId()
|
||||
Must(store.OAuth().SaveAuthData(&a1))
|
||||
Must(store.OAuth().SaveAuthData(utils.T, &a1))
|
||||
|
||||
if err := (<-store.OAuth().RemoveAuthData(a1.Code)).Err; err != nil {
|
||||
if err := (<-store.OAuth().RemoveAuthData(utils.T, a1.Code)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := (<-store.OAuth().GetAuthData(a1.Code)).Err; err == nil {
|
||||
if err := (<-store.OAuth().GetAuthData(utils.T, a1.Code)).Err; err == nil {
|
||||
t.Fatal("should have errored - auth code removed")
|
||||
}
|
||||
}
|
||||
@@ -188,9 +189,9 @@ func TestOAuthStoreRemoveAuthDataByUser(t *testing.T) {
|
||||
a1.ClientId = model.NewId()
|
||||
a1.UserId = model.NewId()
|
||||
a1.Code = model.NewId()
|
||||
Must(store.OAuth().SaveAuthData(&a1))
|
||||
Must(store.OAuth().SaveAuthData(utils.T, &a1))
|
||||
|
||||
if err := (<-store.OAuth().PermanentDeleteAuthDataByUser(a1.UserId)).Err; err != nil {
|
||||
if err := (<-store.OAuth().PermanentDeleteAuthDataByUser(utils.T, a1.UserId)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,18 +147,18 @@ type AuditStore interface {
|
||||
}
|
||||
|
||||
type OAuthStore interface {
|
||||
SaveApp(app *model.OAuthApp) StoreChannel
|
||||
UpdateApp(app *model.OAuthApp) StoreChannel
|
||||
GetApp(id string) StoreChannel
|
||||
GetAppByUser(userId string) StoreChannel
|
||||
SaveAuthData(authData *model.AuthData) StoreChannel
|
||||
GetAuthData(code string) StoreChannel
|
||||
RemoveAuthData(code string) StoreChannel
|
||||
PermanentDeleteAuthDataByUser(userId string) StoreChannel
|
||||
SaveAccessData(accessData *model.AccessData) StoreChannel
|
||||
GetAccessData(token string) StoreChannel
|
||||
GetAccessDataByAuthCode(authCode string) StoreChannel
|
||||
RemoveAccessData(token string) StoreChannel
|
||||
SaveApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
|
||||
UpdateApp(T goi18n.TranslateFunc, app *model.OAuthApp) StoreChannel
|
||||
GetApp(T goi18n.TranslateFunc, id string) StoreChannel
|
||||
GetAppByUser(T goi18n.TranslateFunc, userId string) StoreChannel
|
||||
SaveAuthData(T goi18n.TranslateFunc, authData *model.AuthData) StoreChannel
|
||||
GetAuthData(T goi18n.TranslateFunc, code string) StoreChannel
|
||||
RemoveAuthData(T goi18n.TranslateFunc, code string) StoreChannel
|
||||
PermanentDeleteAuthDataByUser(T goi18n.TranslateFunc, userId string) StoreChannel
|
||||
SaveAccessData(T goi18n.TranslateFunc, accessData *model.AccessData) StoreChannel
|
||||
GetAccessData(T goi18n.TranslateFunc, token string) StoreChannel
|
||||
GetAccessDataByAuthCode(T goi18n.TranslateFunc, authCode string) StoreChannel
|
||||
RemoveAccessData(T goi18n.TranslateFunc, token string) StoreChannel
|
||||
}
|
||||
|
||||
type SystemStore interface {
|
||||
|
||||
Ссылка в новой задаче
Block a user