1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-05 13:35:25 +02:00

Continued MySQL/PostgreSQL store provider refactoring

Refactored, renamed, removed storage related code.

Basic smoke test passed for PostgreSQL whilst fully working on MySQL variants as per usual.
This commit is contained in:
HarveyKandola 2018-09-27 15:14:48 +01:00
parent b455e5eaf5
commit 97beb3f4d3
81 changed files with 1454 additions and 1497 deletions

View file

@ -15,14 +15,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents Airtable
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us

View file

@ -15,14 +15,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents code snippet
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us.

View file

@ -22,13 +22,14 @@ import (
"github.com/documize/community/domain"
"github.com/documize/community/domain/permission"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
"github.com/documize/community/model/page"
)
// Handler contains the runtime information such as logging and database.
type Handler struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// GetSections returns available smart sections.

View file

@ -15,14 +15,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents Draw.io
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us

View file

@ -21,14 +21,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents Gemini
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us.
@ -154,7 +154,7 @@ func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData
return
}
func auth(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func auth(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
@ -222,7 +222,7 @@ func auth(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *
provider.WriteJSON(w, g)
}
func workspace(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func workspace(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
@ -294,7 +294,7 @@ func workspace(ctx *provider.Context, store *domain.Store, w http.ResponseWriter
provider.WriteJSON(w, workspace)
}
func items(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func items(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
@ -369,7 +369,7 @@ func items(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r
provider.WriteJSON(w, items)
}
func secs(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func secs(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
sec, _ := getSecrets(ctx, store)
provider.WriteJSON(w, sec)
}

View file

@ -14,8 +14,8 @@ package gemini
import (
"strings"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// the HTML that is rendered by this section.
@ -87,7 +87,7 @@ type geminiConfig struct {
Filter map[string]interface{} `json:"filter"`
}
func (c *geminiConfig) Clean(ctx *provider.Context, store *domain.Store) {
func (c *geminiConfig) Clean(ctx *provider.Context, store *store.Store) {
if ctx != nil {
sec, err := getSecrets(ctx, store)
if err == nil {
@ -103,7 +103,7 @@ func (c *geminiConfig) Clean(ctx *provider.Context, store *domain.Store) {
c.URL = strings.TrimSpace(c.URL)
}
func (c *geminiConfig) SaveSecrets(ctx *provider.Context, store *domain.Store) {
func (c *geminiConfig) SaveSecrets(ctx *provider.Context, store *store.Store) {
var sec secrets
sec.APIKey = strings.TrimSpace(c.APIKey)
sec.Username = strings.TrimSpace(c.Username)
@ -117,7 +117,7 @@ type secrets struct {
APIKey string `json:"apikey"`
}
func getSecrets(ctx *provider.Context, store *domain.Store) (sec secrets, err error) {
func getSecrets(ctx *provider.Context, store *store.Store) (sec secrets, err error) {
err = ctx.UnmarshalSecrets(&sec, store)
return
}

View file

@ -21,8 +21,8 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
jira "gopkg.in/andygrunwald/go-jira.v1"
)
@ -34,7 +34,7 @@ const (
// Provider represents Gemini
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us.
@ -129,7 +129,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
}
}
func auth(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func auth(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
creds, err := getCredentials(ctx, store)
if err != nil {
provider.WriteForbidden(w)
@ -147,7 +147,7 @@ func auth(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *
provider.WriteJSON(w, "OK")
}
func previewIssues(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func previewIssues(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
creds, err := getCredentials(ctx, store)
if err != nil {
provider.WriteForbidden(w)
@ -173,7 +173,7 @@ func previewIssues(ctx *provider.Context, store *domain.Store, w http.ResponseWr
provider.WriteJSON(w, issues)
}
func previewGrid(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
func previewGrid(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) {
creds, err := getCredentials(ctx, store)
if err != nil {
provider.WriteForbidden(w)
@ -202,7 +202,7 @@ func previewGrid(ctx *provider.Context, store *domain.Store, w http.ResponseWrit
}
// Pull config from HTTP request.
func readConfig(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) (config jiraConfig, err error) {
func readConfig(ctx *provider.Context, store *store.Store, w http.ResponseWriter, r *http.Request) (config jiraConfig, err error) {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
@ -218,7 +218,7 @@ func readConfig(ctx *provider.Context, store *domain.Store, w http.ResponseWrite
}
// Get Jira connector configuration.
func getCredentials(ctx *provider.Context, store *domain.Store) (login jiraLogin, err error) {
func getCredentials(ctx *provider.Context, store *store.Store) (login jiraLogin, err error) {
creds, err := store.Setting.GetUser(ctx.OrgID, "", "jira", "")
err = json.Unmarshal([]byte(creds), &login)

View file

@ -16,14 +16,14 @@ import (
"github.com/documize/blackfriday"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents Markdown
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us

View file

@ -22,8 +22,8 @@ import (
"net/url"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
const me = "papertrail"
@ -31,7 +31,7 @@ const me = "papertrail"
// Provider represents Papertrail
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us.
@ -162,7 +162,7 @@ func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData
return
}
func auth(rt *env.Runtime, store *domain.Store, ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
func auth(rt *env.Runtime, store *store.Store, ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
result, err := fetchEvents(rt, config)
if result == nil {

View file

@ -21,14 +21,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents PlantUML Text Diagram
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us

View file

@ -21,6 +21,7 @@ import (
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/store"
)
// SecretReplacement is a constant used to replace secrets in data-structures when required.
@ -32,14 +33,14 @@ var sectionsMap = make(map[string]Provider)
// TypeMeta details a "smart section" that represents a "page" in a document.
type TypeMeta struct {
ID string `json:"id"`
Order int `json:"order"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Title string `json:"title"`
Description string `json:"description"`
Preview bool `json:"preview"` // coming soon!
Callback func(*env.Runtime, *domain.Store, http.ResponseWriter, *http.Request) error `json:"-"`
ID string `json:"id"`
Order int `json:"order"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Title string `json:"title"`
Description string `json:"description"`
Preview bool `json:"preview"` // coming soon!
Callback func(*env.Runtime, *store.Store, http.ResponseWriter, *http.Request) error `json:"-"`
}
// ConfigHandle returns the key name for database config table
@ -102,7 +103,7 @@ func Command(section string, ctx *Context, w http.ResponseWriter, r *http.Reques
}
// Callback passes parameters to the given section callback, the returned error indicates success.
func Callback(section string, rt *env.Runtime, store *domain.Store, w http.ResponseWriter, r *http.Request) error {
func Callback(section string, rt *env.Runtime, store *store.Store, w http.ResponseWriter, r *http.Request) error {
s, ok := sectionsMap[section]
if ok {
if cb := s.Meta().Callback; cb != nil {
@ -194,7 +195,7 @@ func WriteForbidden(w http.ResponseWriter) {
// The secrets must be in the form of a JSON format string, for example `{"mysecret":"lover"}`.
// An empty string signifies no valid secrets for this user/org combination.
// Note that this function can only be called within the Command method of a section.
func (c *Context) SaveSecrets(JSONobj string, s *domain.Store) error {
func (c *Context) SaveSecrets(JSONobj string, s *store.Store) error {
if !c.inCommand {
return errors.New("SaveSecrets() may only be called from within Command()")
}
@ -204,7 +205,7 @@ func (c *Context) SaveSecrets(JSONobj string, s *domain.Store) error {
// MarshalSecrets to the database.
// Parameter the same as for json.Marshal().
func (c *Context) MarshalSecrets(sec interface{}, s *domain.Store) error {
func (c *Context) MarshalSecrets(sec interface{}, s *store.Store) error {
if !c.inCommand {
return errors.New("MarshalSecrets() may only be called from within Command()")
}
@ -220,7 +221,7 @@ func (c *Context) MarshalSecrets(sec interface{}, s *domain.Store) error {
// JSONpath format is defined at https://dev.mysql.com/doc/refman/5.7/en/json-path-syntax.html .
// An empty JSONpath returns the whole JSON object, as JSON.
// Errors return the empty string.
func (c *Context) GetSecrets(JSONpath string, s *domain.Store) string {
func (c *Context) GetSecrets(JSONpath string, s *store.Store) string {
m := c.prov.Meta()
v, _ := s.Setting.GetUser(c.OrgID, c.UserID, m.ContentType, JSONpath)
@ -232,7 +233,7 @@ var ErrNoSecrets = errors.New("no secrets in database")
// UnmarshalSecrets from the database.
// Parameter the same as for "v" in json.Unmarshal().
func (c *Context) UnmarshalSecrets(v interface{}, s *domain.Store) error {
func (c *Context) UnmarshalSecrets(v interface{}, s *store.Store) error {
secTxt := c.GetSecrets("", s) // get all the json of the secrets
if len(secTxt) > 0 {
return json.Unmarshal([]byte(secTxt), v)

View file

@ -15,7 +15,6 @@ import (
"fmt"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/airtable"
"github.com/documize/community/domain/section/code"
"github.com/documize/community/domain/section/flowchart"
@ -28,10 +27,11 @@ import (
"github.com/documize/community/domain/section/table"
"github.com/documize/community/domain/section/trello"
"github.com/documize/community/domain/section/wysiwyg"
"github.com/documize/community/domain/store"
)
// Register sections
func Register(rt *env.Runtime, s *domain.Store) {
func Register(rt *env.Runtime, s *store.Store) {
provider.Register("code", &code.Provider{Runtime: rt, Store: s})
provider.Register("jira", &jira.Provider{Runtime: rt, Store: s})
provider.Register("gemini", &gemini.Provider{Runtime: rt, Store: s})

View file

@ -15,14 +15,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents Table
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us

View file

@ -20,8 +20,8 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
var meta provider.TypeMeta
@ -39,7 +39,7 @@ func init() {
// Provider represents Trello
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us.

View file

@ -15,14 +15,14 @@ import (
"net/http"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
)
// Provider represents WYSIWYG
type Provider struct {
Runtime *env.Runtime
Store *domain.Store
Store *store.Store
}
// Meta describes us