mirror of
https://github.com/documize/community.git
synced 2025-07-20 13:49:42 +02:00
refactored getAppURL
This commit is contained in:
parent
6cc6b6d70f
commit
2e39b7a471
5 changed files with 22 additions and 26 deletions
|
@ -1,11 +1,11 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
//
|
//
|
||||||
// This software (Documize Community Edition) is licensed under
|
// This software (Documize Community Edition) is licensed under
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
//
|
//
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
// by contacting <sales@documize.com>.
|
// by contacting <sales@documize.com>.
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/api/request"
|
|
||||||
"github.com/documize/community/core/api/store"
|
"github.com/documize/community/core/api/store"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
)
|
)
|
||||||
|
@ -26,18 +25,6 @@ func init() {
|
||||||
storageProvider = new(store.LocalStorageProvider)
|
storageProvider = new(store.LocalStorageProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
//getAppURL returns full HTTP url for the app
|
|
||||||
func getAppURL(c request.Context, endpoint string) string {
|
|
||||||
|
|
||||||
scheme := "http://"
|
|
||||||
|
|
||||||
if c.SSL {
|
|
||||||
scheme = "https://"
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s%s/%s", scheme, c.AppURL, endpoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writePayloadError(w http.ResponseWriter, method string, err error) {
|
func writePayloadError(w http.ResponseWriter, method string, err error) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
|
@ -407,7 +407,7 @@ func SetFolderPermissions(w http.ResponseWriter, r *http.Request) {
|
||||||
hasEveryoneRole := false
|
hasEveryoneRole := false
|
||||||
roleCount := 0
|
roleCount := 0
|
||||||
|
|
||||||
url := getAppURL(p.Context, fmt.Sprintf("s/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
url := p.Context.GetAppURL(fmt.Sprintf("s/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
||||||
|
|
||||||
for _, role := range model.Roles {
|
for _, role := range model.Roles {
|
||||||
role.OrgID = p.Context.OrgID
|
role.OrgID = p.Context.OrgID
|
||||||
|
@ -742,13 +742,13 @@ func InviteToFolder(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := getAppURL(p.Context, fmt.Sprintf("s/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
url := p.Context.GetAppURL(fmt.Sprintf("s/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
||||||
go mail.ShareFolderExistingUser(email, inviter.Fullname(), url, label.Name, model.Message)
|
go mail.ShareFolderExistingUser(email, inviter.Fullname(), url, label.Name, model.Message)
|
||||||
log.Info(fmt.Sprintf("%s is sharing space %s with existing user %s", inviter.Email, label.Name, email))
|
log.Info(fmt.Sprintf("%s is sharing space %s with existing user %s", inviter.Email, label.Name, email))
|
||||||
} else {
|
} else {
|
||||||
// On-board new user
|
// On-board new user
|
||||||
if strings.Contains(email, "@") {
|
if strings.Contains(email, "@") {
|
||||||
url := getAppURL(p.Context, fmt.Sprintf("auth/share/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
url := p.Context.GetAppURL(fmt.Sprintf("auth/share/%s/%s", label.RefID, utility.MakeSlug(label.Name)))
|
||||||
err = inviteNewUserToSharedFolder(p, email, inviter, url, label, model.Message)
|
err = inviteNewUserToSharedFolder(p, email, inviter, url, label, model.Message)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -80,7 +80,7 @@ Disallow: /
|
||||||
|
|
||||||
// Anonymous access would mean we allow bots to crawl.
|
// Anonymous access would mean we allow bots to crawl.
|
||||||
if org.AllowAnonymousAccess {
|
if org.AllowAnonymousAccess {
|
||||||
sitemap := getAppURL(p.Context, "sitemap.xml")
|
sitemap := p.Context.GetAppURL("sitemap.xml")
|
||||||
robots = fmt.Sprintf(
|
robots = fmt.Sprintf(
|
||||||
`User-agent: *
|
`User-agent: *
|
||||||
Disallow: /settings/
|
Disallow: /settings/
|
||||||
|
@ -138,7 +138,7 @@ func GetSitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
for _, folder := range folders {
|
for _, folder := range folders {
|
||||||
var item sitemapItem
|
var item sitemapItem
|
||||||
item.URL = getAppURL(p.Context, fmt.Sprintf("s/%s/%s", folder.RefID, utility.MakeSlug(folder.Name)))
|
item.URL = p.Context.GetAppURL(fmt.Sprintf("s/%s/%s", folder.RefID, utility.MakeSlug(folder.Name)))
|
||||||
item.Date = folder.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
item.Date = folder.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func GetSitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
for _, document := range documents {
|
for _, document := range documents {
|
||||||
var item sitemapItem
|
var item sitemapItem
|
||||||
item.URL = getAppURL(p.Context, fmt.Sprintf("s/%s/%s/d/%s/%s",
|
item.URL = p.Context.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
||||||
document.FolderID, utility.MakeSlug(document.Folder), document.DocumentID, utility.MakeSlug(document.Document)))
|
document.FolderID, utility.MakeSlug(document.Folder), document.DocumentID, utility.MakeSlug(document.Document)))
|
||||||
item.Date = document.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
item.Date = document.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
|
|
|
@ -174,13 +174,13 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
||||||
auth := fmt.Sprintf("%s:%s:%s", p.Context.AppURL, userModel.Email, requestedPassword[:size])
|
auth := fmt.Sprintf("%s:%s:%s", p.Context.AppURL, userModel.Email, requestedPassword[:size])
|
||||||
encrypted := utility.EncodeBase64([]byte(auth))
|
encrypted := utility.EncodeBase64([]byte(auth))
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/%s", getAppURL(p.Context, "auth/sso"), url.QueryEscape(string(encrypted)))
|
url := fmt.Sprintf("%s/%s", p.Context.GetAppURL("auth/sso"), url.QueryEscape(string(encrypted)))
|
||||||
go mail.InviteNewUser(userModel.Email, inviter.Fullname(), url, userModel.Email, requestedPassword)
|
go mail.InviteNewUser(userModel.Email, inviter.Fullname(), url, userModel.Email, requestedPassword)
|
||||||
|
|
||||||
log.Info(fmt.Sprintf("%s invited by %s on %s", userModel.Email, inviter.Email, p.Context.AppURL))
|
log.Info(fmt.Sprintf("%s invited by %s on %s", userModel.Email, inviter.Email, p.Context.AppURL))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
go mail.InviteExistingUser(userModel.Email, inviter.Fullname(), getAppURL(p.Context, ""))
|
go mail.InviteExistingUser(userModel.Email, inviter.Fullname(), p.Context.GetAppURL(""))
|
||||||
|
|
||||||
log.Info(fmt.Sprintf("%s is giving access to an existing user %s", inviter.Email, userModel.Email))
|
log.Info(fmt.Sprintf("%s is giving access to an existing user %s", inviter.Email, userModel.Email))
|
||||||
}
|
}
|
||||||
|
@ -605,9 +605,7 @@ func ForgotUserPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
log.IfErr(tx.Commit())
|
log.IfErr(tx.Commit())
|
||||||
|
|
||||||
appURL := getAppURL(p.Context, fmt.Sprintf("auth/reset/%s", token))
|
appURL := p.Context.GetAppURL(fmt.Sprintf("auth/reset/%s", token))
|
||||||
|
|
||||||
fmt.Println(appURL)
|
|
||||||
|
|
||||||
go mail.PasswordReset(user.Email, appURL)
|
go mail.PasswordReset(user.Email, appURL)
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,17 @@ type Context struct {
|
||||||
Transaction *sqlx.Tx
|
Transaction *sqlx.Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetAppURL returns full HTTP url for the app
|
||||||
|
func (c *Context) GetAppURL(endpoint string) string {
|
||||||
|
scheme := "http://"
|
||||||
|
|
||||||
|
if c.SSL {
|
||||||
|
scheme = "https://"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s%s/%s", scheme, c.AppURL, endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
// NewContext simply returns a blank Context type.
|
// NewContext simply returns a blank Context type.
|
||||||
func NewContext() Context {
|
func NewContext() Context {
|
||||||
return Context{}
|
return Context{}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue