1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

refactored smart section code

This commit is contained in:
Harvey Kandola 2017-07-21 13:39:53 +01:00
parent 5acfae3d0d
commit 3defc062bd
40 changed files with 172 additions and 306 deletions

View file

@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
## Latest version
v1.50.1
v1.50.2
## OS Support

View file

@ -14,6 +14,7 @@ package convert
import (
"errors"
"github.com/documize/community/core/api/convert/html"
"github.com/documize/community/core/api/plugins"
api "github.com/documize/community/core/convapi"
@ -53,7 +54,7 @@ func Convert(ctx context.Context, xtn string, fileRequest *api.DocumentConversio
/* TODO add sanitisation for body & title HTML
var titlePolicy, bodyPolicy *bluemonday.Policy
func init() {
func xxx() {
policy := bluemonday.UGCPolicy()
policy.RequireNoFollowOnLinks(true)

View file

@ -26,8 +26,8 @@ import (
"github.com/documize/community/core/api/util"
"github.com/documize/community/core/log"
"github.com/documize/community/core/secrets"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/web"
"github.com/documize/community/domain/section/provider"
)
// Authenticate user based up HTTP Authorization header.

View file

@ -23,34 +23,6 @@ import (
"github.com/documize/community/core/log"
)
// var jwtKey string
// func init() {
// env.GetString(&jwtKey, "salt", false, "the salt string used to encode JWT tokens, if not set a random value will be generated",
// func(t *string, n string) bool {
// if jwtKey == "" {
// b := make([]byte, 17)
// _, err := rand.Read(b)
// if err != nil {
// jwtKey = err.Error()
// log.Error("problem using crypto/rand", err)
// return false
// }
// for k, v := range b {
// if (v >= 'a' && v <= 'z') || (v >= 'A' && v <= 'Z') || (v >= '0' && v <= '0') {
// b[k] = v
// } else {
// s := fmt.Sprintf("%x", v)
// b[k] = s[0]
// }
// }
// jwtKey = string(b)
// log.Info("Please set DOCUMIZESALT or use -salt with this value: " + jwtKey)
// }
// return true
// })
// }
// Generates JSON Web Token (http://jwt.io)
func generateJWT(user, org, domain string) string {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{

View file

@ -24,9 +24,9 @@ import (
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/api/util"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/streamutil"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain/section/provider"
htmldiff "github.com/documize/html-diff"
"github.com/gorilla/mux"
)

View file

@ -21,9 +21,9 @@ import (
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/api/util"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/streamutil"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain/section/provider"
"github.com/gorilla/mux"
)

View file

@ -26,30 +26,6 @@ import (
"github.com/gorilla/mux"
)
// var port, certFile, keyFile, forcePort2SSL string
// Product details app edition and version
// var Product env.ProdInfo
// func init() {
// // Product.Major = "1"
// // Product.Minor = "50"
// // Product.Patch = "0"
// // Product.Version = fmt.Sprintf("%s.%s.%s", Product.Major, Product.Minor, Product.Patch)
// // Product.Edition = "Community"
// // Product.Title = fmt.Sprintf("%s Edition", Product.Edition)
// // Product.License = env.License{}
// // Product.License.Seats = 1
// // Product.License.Valid = true
// // Product.License.Trial = false
// // Product.License.Edition = "Community"
// // env.GetString(&certFile, "cert", false, "the cert.pem file used for https", nil)
// // env.GetString(&keyFile, "key", false, "the key.pem file used for https", nil)
// // env.GetString(&port, "port", false, "http/https port number", nil)
// // env.GetString(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS", nil)
// }
var testHost string // used during automated testing
// Serve the Documize endpoint.

View file

@ -31,13 +31,6 @@ import (
var PluginFile = "DB" // this points to the database
var insecure = "false"
// func init() {
// env.GetString(&PluginFile, "plugin", false,
// "the JSON file describing plugins, default 'DB' uses the database config table 'FILEPLUGINS' entry", nil)
// env.GetString(&insecure, "insecure", false,
// "if 'true' allow https endpoints with invalid certificates (only for testing)", nil)
// }
type infoLog struct{}
func (i infoLog) Write(b []byte) (int, error) {

View file

@ -45,85 +45,6 @@ func (dr *databaseRequest) MakeTx() (err error) {
return err
}
// func init() {
// var err error
// env.GetString(&connectionString, "db", true,
// `'username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize"`,
// func(*string, string) bool {
// Db, err = sqlx.Open("mysql", stdConn(connectionString))
// if err != nil {
// log.Error("Unable to setup database", err)
// }
// Db.SetMaxIdleConns(30)
// Db.SetMaxOpenConns(100)
// Db.SetConnMaxLifetime(time.Second * 14400)
// err = Db.Ping()
// if err != nil {
// log.Error("Unable to connect to database, connection string should be of the form: '"+
// "username:password@tcp(host:3306)/database'", err)
// os.Exit(2)
// }
// // go into setup mode if required
// if web.SiteMode != web.SiteModeOffline {
// if database.Check(Db, connectionString) {
// if err := database.Migrate(true /* the config table exists */); err != nil {
// log.Error("Unable to run database migration: ", err)
// os.Exit(2)
// }
// } else {
// log.Info("database.Check(Db) !OK, going into setup mode")
// }
// }
// return false // value not changed
// })
// }
// var stdParams = map[string]string{
// "charset": "utf8",
// "parseTime": "True",
// "maxAllowedPacket": "4194304", // 4194304 // 16777216 = 16MB
// }
// func stdConn(cs string) string {
// queryBits := strings.Split(cs, "?")
// ret := queryBits[0] + "?"
// retFirst := true
// if len(queryBits) == 2 {
// paramBits := strings.Split(queryBits[1], "&")
// for _, pb := range paramBits {
// found := false
// if assignBits := strings.Split(pb, "="); len(assignBits) == 2 {
// _, found = stdParams[strings.TrimSpace(assignBits[0])]
// }
// if !found { // if we can't work out what it is, put it through
// if retFirst {
// retFirst = false
// } else {
// ret += "&"
// }
// ret += pb
// }
// }
// }
// for k, v := range stdParams {
// if retFirst {
// retFirst = false
// } else {
// ret += "&"
// }
// ret += k + "=" + v
// }
// return ret
// }
type baseManager struct {
}

View file

@ -1,43 +0,0 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package section
import (
"fmt"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/airtable"
"github.com/documize/community/core/section/code"
"github.com/documize/community/core/section/gemini"
"github.com/documize/community/core/section/github"
"github.com/documize/community/core/section/markdown"
"github.com/documize/community/core/section/papertrail"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/section/table"
"github.com/documize/community/core/section/trello"
"github.com/documize/community/core/section/wysiwyg"
)
// Register sections
func Register() {
provider.Register("code", &code.Provider{})
provider.Register("gemini", &gemini.Provider{})
provider.Register("github", &github.Provider{})
provider.Register("markdown", &markdown.Provider{})
provider.Register("papertrail", &papertrail.Provider{})
provider.Register("table", &table.Provider{})
provider.Register("trello", &trello.Provider{})
provider.Register("wysiwyg", &wysiwyg.Provider{})
provider.Register("airtable", &airtable.Provider{})
p := provider.List()
log.Info(fmt.Sprintf("Documize registered %d sections and tabs", len(p)))
}

View file

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

View file

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

View file

@ -20,12 +20,13 @@ import (
"io/ioutil"
"net/http"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
)
// Provider represents Gemini
type Provider struct {
Runtime env.Runtime
}
// Meta describes us.
@ -87,29 +88,29 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
}
// Refresh just sends back data as-is.
func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
var c = geminiConfig{}
err := json.Unmarshal([]byte(config), &c)
if err != nil {
log.Error("Unable to read Gemini config", err)
p.Runtime.Log.Error("Unable to read Gemini config", err)
return
}
c.Clean(ctx)
if len(c.URL) == 0 {
log.Info("Gemini.Refresh received empty URL")
p.Runtime.Log.Info("Gemini.Refresh received empty URL")
return
}
if len(c.Username) == 0 {
log.Info("Gemini.Refresh received empty username")
p.Runtime.Log.Info("Gemini.Refresh received empty username")
return
}
if len(c.APIKey) == 0 {
log.Info("Gemini.Refresh received empty API key")
p.Runtime.Log.Info("Gemini.Refresh received empty API key")
return
}
@ -136,16 +137,15 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
dec := json.NewDecoder(res.Body)
err = dec.Decode(&items)
if err != nil {
fmt.Println(err)
p.Runtime.Log.Error("unable to Decode gemini items", err)
return
}
j, err := json.Marshal(items)
if err != nil {
log.Error("unable to marshall gemini items", err)
p.Runtime.Log.Error("unable to marshal gemini items", err)
return
}
@ -196,7 +196,6 @@ func auth(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
provider.WriteError(w, "gemini", err)
return
}
@ -215,7 +214,6 @@ func auth(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
err = dec.Decode(&g)
if err != nil {
fmt.Println(err)
provider.WriteError(w, "gemini", err)
return
}
@ -288,7 +286,6 @@ func workspace(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
err = dec.Decode(&workspace)
if err != nil {
fmt.Println(err)
provider.WriteError(w, "gemini", err)
return
}
@ -334,7 +331,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
filter, err := json.Marshal(config.Filter)
if err != nil {
fmt.Println(err)
provider.WriteError(w, "gemini", err)
return
}
@ -348,7 +344,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
provider.WriteError(w, "gemini", err)
return
}
@ -374,7 +369,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
}
func secs(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
sec, err := getSecrets(ctx)
log.IfErr(err)
sec, _ := getSecrets(ctx)
provider.WriteJSON(w, sec)
}

View file

@ -14,8 +14,7 @@ package gemini
import (
"strings"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/domain/section/provider"
)
// the HTML that is rendered by this section.
@ -108,7 +107,7 @@ func (c *geminiConfig) SaveSecrets(ctx *provider.Context) {
sec.APIKey = strings.TrimSpace(c.APIKey)
sec.Username = strings.TrimSpace(c.Username)
sec.URL = strings.TrimSpace(c.URL)
log.IfErr(ctx.MarshalSecrets(sec))
ctx.MarshalSecrets(sec)
}
type secrets struct {

View file

@ -15,15 +15,13 @@ import (
"bytes"
"encoding/json"
"errors"
//"fmt"
"html/template"
"io/ioutil"
"net/http"
"strings"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
gogithub "github.com/google/go-github/github"
)
@ -45,6 +43,7 @@ func init() {
// Provider represents GitHub
type Provider struct {
Runtime env.Runtime
}
// Meta describes us.
@ -59,7 +58,6 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
if len(method) == 0 {
msg := "missing method name"
log.ErrorString("github: " + msg)
provider.WriteMessage(w, "gitub", msg)
return
}
@ -80,9 +78,8 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
body, err := ioutil.ReadAll(r.Body)
if err != nil {
msg := "Bad body"
log.ErrorString("github: " + msg)
provider.WriteMessage(w, "github", msg)
p.Runtime.Log.Error("bad body", errors.New("Missing body"))
provider.WriteMessage(w, "github", "bad body")
return
}
@ -90,7 +87,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
// write the new one, direct from JS
if err = ctx.SaveSecrets(string(body)); err != nil {
log.Error("github settoken configuration", err)
p.Runtime.Log.Error("github settoken configuration", err)
provider.WriteError(w, "github", err)
return
}
@ -104,7 +101,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
err = json.Unmarshal(body, &config)
if err != nil {
log.Error("github Command Unmarshal", err)
p.Runtime.Log.Error("github Command Unmarshal", err)
provider.WriteError(w, "github", err)
return
}
@ -127,7 +124,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
if err != nil {
// token now invalid, so wipe it
ctx.SaveSecrets("") // ignore error, already in an error state
log.Error("github check token validation", err)
p.Runtime.Log.Error("github check token validation", err)
provider.WriteError(w, "github", err)
return
}
@ -135,11 +132,11 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
default:
if listFailed(method, config, client, w) {
if listFailed(p.Runtime, method, config, client, w) {
gr := githubRender{}
for _, rep := range reports {
log.IfErr(rep.refresh(&gr, &config, client))
rep.refresh(&gr, &config, client)
}
provider.WriteJSON(w, &gr)
@ -153,9 +150,8 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
var c = githubConfig{}
err := json.Unmarshal([]byte(configJSON), &c)
if err != nil {
log.Error("unable to unmarshall github config", err)
p.Runtime.Log.Error("unable to unmarshall github config", err)
return "internal configuration error '" + err.Error() + "'"
}
@ -166,7 +162,7 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
byts, err := json.Marshal(refreshReportData(&c, client))
if err != nil {
log.Error("unable to marshall github data", err)
p.Runtime.Log.Error("unable to marshall github data", err)
return "internal configuration error '" + err.Error() + "'"
}
@ -177,7 +173,7 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
var gr = githubRender{}
for _, rep := range reports {
log.IfErr(rep.refresh(&gr, c, client))
rep.refresh(&gr, c, client)
}
return &gr
}
@ -192,7 +188,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
err = json.Unmarshal([]byte(config), &c)
if err != nil {
log.Error("unable to unmarshall github config", err)
p.Runtime.Log.Error("unable to unmarshall github config", err)
return "Please delete and recreate this Github section."
}
@ -208,7 +204,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
err = json.Unmarshal([]byte(data), &payload)
if err != nil {
log.Error("unable to unmarshall github data", err)
p.Runtime.Log.Error("unable to unmarshall github data", err)
return "Please delete and recreate this Github section."
}
@ -222,12 +218,12 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
rep, ok := reports[repID]
if !ok {
msg := "github report not found for: " + repID
log.ErrorString(msg)
p.Runtime.Log.Info(msg)
return "Documize internal error: " + msg
}
if err = rep.render(&payload, &c); err != nil {
log.Error("unable to render "+repID, err)
p.Runtime.Log.Error("unable to render "+repID, err)
return "Documize internal github render " + repID + " error: " + err.Error() + "<BR>" + data
}
@ -236,7 +232,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
t, err = t.Parse(rep.template)
if err != nil {
log.Error("github render template.Parse error:", err)
p.Runtime.Log.Error("github render template.Parse error:", err)
//for k, v := range strings.Split(rep.template, "\n") {
// fmt.Println("DEBUG", k+1, v)
//}
@ -246,7 +242,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
buffer := new(bytes.Buffer)
err = t.Execute(buffer, payload)
if err != nil {
log.Error("github render template.Execute error:", err)
p.Runtime.Log.Error("github render template.Execute error:", err)
return "Documize internal github template.Execute error: " + err.Error()
}

View file

@ -15,27 +15,26 @@ import (
"fmt"
"net/http"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
gogithub "github.com/google/go-github/github"
)
func listFailed(method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
func listFailed(rt env.Runtime, method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
switch method { // which list to choose?
case "owners":
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
rt.Log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
orgs, _, err := client.Organizations.List("", nil)
if err != nil {
log.Error("github get user's organisations:", err)
rt.Log.Error("github get user's organisations:", err)
provider.WriteError(w, "github", err)
return
}
@ -59,7 +58,7 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
rt.Log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
@ -74,7 +73,7 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
}
if err != nil {
log.Error("github get user/org repositories:", err)
rt.Log.Error("github get user/org repositories:", err)
provider.WriteError(w, "github", err)
return
}

View file

@ -15,11 +15,13 @@ import (
"net/http"
"github.com/documize/blackfriday"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
)
// Provider represents Markdown
type Provider struct {
Runtime env.Runtime
}
// Meta describes us

View file

@ -21,14 +21,15 @@ import (
"net/http"
"net/url"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
)
const me = "papertrail"
// Provider represents Papertrail
type Provider struct {
Runtime env.Runtime
}
// Meta describes us.
@ -116,19 +117,19 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
switch method {
case "auth":
auth(ctx, config, w, r)
auth(p.Runtime, ctx, config, w, r)
case "options":
options(config, w, r)
}
}
// Refresh just sends back data as-is.
func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
var c = papertrailConfig{}
err := json.Unmarshal([]byte(config), &c)
if err != nil {
log.Error("unable to read Papertrail config", err)
p.Runtime.Log.Error("unable to read Papertrail config", err)
return
}
@ -137,21 +138,21 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
c.APIToken = ctx.GetSecrets("APIToken")
if len(c.APIToken) == 0 {
log.Error("missing API token", err)
p.Runtime.Log.Error("missing API token", err)
return
}
result, err := fetchEvents(c)
result, err := fetchEvents(p.Runtime, c)
if err != nil {
log.Error("Papertrail fetchEvents failed", err)
p.Runtime.Log.Error("Papertrail fetchEvents failed", err)
return
}
j, err := json.Marshal(result)
if err != nil {
log.Error("unable to marshal Papaertrail events", err)
p.Runtime.Log.Error("unable to marshal Papaertrail events", err)
return
}
@ -159,8 +160,8 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
return
}
func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
result, err := fetchEvents(config)
func auth(rt env.Runtime, ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
result, err := fetchEvents(rt, config)
if result == nil {
err = errors.New("nil result of papertrail query")
@ -168,7 +169,7 @@ func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter,
if err != nil {
log.IfErr(ctx.SaveSecrets(`{"APIToken":""}`)) // invalid token, so reset it
ctx.SaveSecrets(`{"APIToken":""}`) // invalid token, so reset it
if err.Error() == "forbidden" {
provider.WriteForbidden(w)
@ -179,7 +180,7 @@ func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter,
return
}
log.IfErr(ctx.SaveSecrets(`{"APIToken":"` + config.APIToken + `"}`))
ctx.SaveSecrets(`{"APIToken":"` + config.APIToken + `"}`)
provider.WriteJSON(w, result)
}
@ -252,7 +253,7 @@ func options(config papertrailConfig, w http.ResponseWriter, r *http.Request) {
provider.WriteJSON(w, options)
}
func fetchEvents(config papertrailConfig) (result interface{}, err error) {
func fetchEvents(rt env.Runtime, config papertrailConfig) (result interface{}, err error) {
var filter string
if len(config.Query) > 0 {
filter = fmt.Sprintf("q=%s", url.QueryEscape(config.Query))
@ -268,7 +269,7 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
var req *http.Request
req, err = http.NewRequest("GET", "https://papertrailapp.com/api/v1/events/search.json?"+filter, nil)
if err != nil {
log.Error("new request", err)
rt.Log.Error("new request", err)
return
}
req.Header.Set("X-Papertrail-Token", config.APIToken)
@ -278,12 +279,12 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
res, err = client.Do(req)
if err != nil {
log.Error("message", err)
rt.Log.Error("message", err)
return
}
if res.StatusCode != http.StatusOK {
log.Error("forbidden", err)
rt.Log.Error("forbidden", err)
return
}
@ -293,7 +294,7 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
err = dec.Decode(&result)
if err != nil {
log.Error("unable to read result", err)
rt.Log.Error("unable to read result", err)
}
return

View file

@ -0,0 +1,45 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package section
import (
"fmt"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/airtable"
"github.com/documize/community/domain/section/code"
"github.com/documize/community/domain/section/gemini"
"github.com/documize/community/domain/section/github"
"github.com/documize/community/domain/section/markdown"
"github.com/documize/community/domain/section/papertrail"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/section/table"
"github.com/documize/community/domain/section/trello"
"github.com/documize/community/domain/section/wysiwyg"
)
// Register sections
func Register(rt env.Runtime) {
provider.Register("code", &code.Provider{Runtime: rt})
provider.Register("gemini", &gemini.Provider{Runtime: rt})
provider.Register("github", &github.Provider{Runtime: rt})
provider.Register("markdown", &markdown.Provider{Runtime: rt})
provider.Register("papertrail", &papertrail.Provider{Runtime: rt})
provider.Register("table", &table.Provider{Runtime: rt})
provider.Register("code", &code.Provider{Runtime: rt})
provider.Register("trello", &trello.Provider{Runtime: rt})
provider.Register("wysiwyg", &wysiwyg.Provider{Runtime: rt})
provider.Register("airtable", &airtable.Provider{Runtime: rt})
p := provider.List()
rt.Log.Info(fmt.Sprintf("Registered %d sections", len(p)))
}

View file

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

View file

@ -20,8 +20,8 @@ import (
"net/http"
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
)
var meta provider.TypeMeta
@ -36,8 +36,9 @@ func init() {
meta.PageType = "tab"
}
// Provider represents GitHub
// Provider represents Trello
type Provider struct {
Runtime env.Runtime
}
// Meta describes us.
@ -46,7 +47,7 @@ func (*Provider) Meta() provider.TypeMeta {
}
// Command stub.
func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
method := query.Get("method")
@ -70,7 +71,7 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
if len(config.AppKey) == 0 {
log.ErrorString("missing trello App Key")
p.Runtime.Log.Info("missing trello App Key")
provider.WriteMessage(w, "trello", "Missing appKey")
return
}
@ -91,9 +92,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
render, err := getCards(config)
if err != nil {
log.IfErr(err)
p.Runtime.Log.Error("failed to render cards", err)
provider.WriteError(w, "trello", err)
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
ctx.SaveSecrets("") // failure means our secrets are invalid
return
}
@ -103,9 +104,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
render, err := getBoards(config)
if err != nil {
log.IfErr(err)
p.Runtime.Log.Error("failed to render board", err)
provider.WriteError(w, "trello", err)
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
ctx.SaveSecrets("") // failure means our secrets are invalid
return
}
@ -115,9 +116,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
render, err := getLists(config)
if err != nil {
log.IfErr(err)
p.Runtime.Log.Error("failed to get Trello lists", err)
provider.WriteError(w, "trello", err)
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
ctx.SaveSecrets("") // failure means our secrets are invalid
return
}
@ -136,7 +137,7 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
return
default:
log.ErrorString("trello unknown method name: " + method)
p.Runtime.Log.Info("unknown trello method called: " + method)
provider.WriteMessage(w, "trello", "missing method name")
return
}
@ -145,8 +146,11 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
var s secrets
s.Token = config.Token
b, e := json.Marshal(s)
log.IfErr(e)
log.IfErr(ctx.SaveSecrets(string(b)))
if err != nil {
p.Runtime.Log.Error("failed save Trello secrets", e)
}
ctx.SaveSecrets(string(b))
}
// Render just sends back HMTL as-is.
@ -176,7 +180,7 @@ func (*Provider) Render(ctx *provider.Context, config, data string) string {
}
// Refresh just sends back data as-is.
func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
func (p *Provider) Refresh(ctx *provider.Context, config, data string) string {
var c = trelloConfig{}
json.Unmarshal([]byte(config), &c)
@ -189,7 +193,7 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
j, err := json.Marshal(refreshed)
if err != nil {
log.Error("unable to marshall trello cards", err)
p.Runtime.Log.Error("failed to marshal trello data", err)
return data
}
@ -224,7 +228,6 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
}
if err != nil {
fmt.Println(err)
return nil, err
}
@ -250,7 +253,6 @@ func getLists(config trelloConfig) (lists []trelloList, err error) {
err = dec.Decode(&lists)
if err != nil {
fmt.Println(err)
return nil, err
}

View file

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

View file

@ -19,49 +19,49 @@ import (
"github.com/documize/community/core/api/endpoint"
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/env"
"github.com/documize/community/core/section"
"github.com/documize/community/domain/section"
"github.com/documize/community/edition/boot"
"github.com/documize/community/edition/logging"
_ "github.com/documize/community/embed" // the compressed front-end code and static data
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
)
func init() {
var rt env.Runtime
func main() {
// runtime stores server/application level information
runtime := env.Runtime{}
rt := env.Runtime{}
// wire up logging implementation
runtime.Log = logging.NewLogger()
rt.Log = logging.NewLogger()
// define product edition details
runtime.Product = env.ProdInfo{}
runtime.Product.Major = "1"
runtime.Product.Minor = "50"
runtime.Product.Patch = "1"
runtime.Product.Version = fmt.Sprintf("%s.%s.%s", runtime.Product.Major, runtime.Product.Minor, runtime.Product.Patch)
runtime.Product.Edition = "Community"
runtime.Product.Title = fmt.Sprintf("%s Edition", runtime.Product.Edition)
runtime.Product.License = env.License{}
runtime.Product.License.Seats = 1
runtime.Product.License.Valid = true
runtime.Product.License.Trial = false
runtime.Product.License.Edition = "Community"
rt.Product = env.ProdInfo{}
rt.Product.Major = "1"
rt.Product.Minor = "50"
rt.Product.Patch = "2"
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
rt.Product.Edition = "Community"
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)
rt.Product.License = env.License{}
rt.Product.License.Seats = 1
rt.Product.License.Valid = true
rt.Product.License.Trial = false
rt.Product.License.Edition = "Community"
// parse settings from command line and environment
runtime.Flags = env.ParseFlags()
flagsOK := boot.InitRuntime(&runtime)
rt.Flags = env.ParseFlags()
flagsOK := boot.InitRuntime(&rt)
if flagsOK {
// runtime.Log = runtime.Log.SetDB(runtime.Db)
}
// temp code repair
api.Runtime = runtime
request.Db = runtime.Db
}
api.Runtime = rt
request.Db = rt.Db
func main() {
section.Register()
section.Register(rt)
ready := make(chan struct{}, 1) // channel is used for testing
endpoint.Serve(ready)

View file

@ -1,6 +1,6 @@
{
"name": "documize",
"version": "1.50.1",
"version": "1.50.2",
"description": "The Document IDE",
"private": true,
"repository": "",

View file

@ -1,16 +1,16 @@
{
"community":
{
"version": "1.50.1",
"version": "1.50.2",
"major": 1,
"minor": 50,
"patch": 1
"patch": 2
},
"enterprise":
{
"version": "1.52.1",
"version": "1.52.2",
"major": 1,
"minor": 52,
"patch": 1
"patch": 2
}
}