mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
GitHub section improvements
This commit is contained in:
parent
60131df628
commit
65666c5a89
11 changed files with 686 additions and 668 deletions
|
@ -26,7 +26,7 @@ import (
|
|||
// Msword type provides a peg to hang the Convert method on.
|
||||
type Msword struct{}
|
||||
|
||||
// Convert converts a file into the Countersoft Documize format.
|
||||
// Convert converts a file into the Documize format.
|
||||
func (file *Msword) Convert(r api.DocumentConversionRequest, reply *api.DocumentConversionResponse) error {
|
||||
byts, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,6 +24,7 @@ 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/utility"
|
||||
"github.com/documize/community/core/web"
|
||||
)
|
||||
|
@ -238,9 +239,19 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
// ValidToken finds and validates authentication token.
|
||||
func ValidToken(r *http.Request) (context request.Context, valid bool) {
|
||||
valid = false
|
||||
// ValidateAuthToken finds and validates authentication token.
|
||||
func ValidateAuthToken(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Info("cb gh")
|
||||
// TODO should this go after token validation?
|
||||
if s := r.URL.Query().Get("section"); s != "" {
|
||||
if err := provider.Callback(s, w, r); err != nil {
|
||||
log.Error("section validation failure", err)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
token := findJWT(r)
|
||||
hasToken := len(token) > 1
|
||||
|
@ -263,6 +274,7 @@ func ValidToken(r *http.Request) (context request.Context, valid bool) {
|
|||
|
||||
// Inability to find org record spells the end of this request.
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -274,6 +286,7 @@ func ValidToken(r *http.Request) (context request.Context, valid bool) {
|
|||
domain := request.GetSubdomainFromHost(r)
|
||||
domain2 := request.GetRequestSubdomain(r)
|
||||
if org.Domain != domain && org.Domain != domain2 {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -283,6 +296,7 @@ func ValidToken(r *http.Request) (context request.Context, valid bool) {
|
|||
// So you have a bad token
|
||||
if hasToken {
|
||||
if tokenErr != nil {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -305,23 +319,23 @@ func ValidToken(r *http.Request) (context request.Context, valid bool) {
|
|||
context.Global = false
|
||||
|
||||
// Fetch user permissions for this org
|
||||
if context.Authenticated {
|
||||
user, err := getSecuredUser(p, org.RefID, context.UserID)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
context.Administrator = user.Admin
|
||||
context.Editor = user.Editor
|
||||
context.Global = user.Global
|
||||
if !context.Authenticated {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
request.SetContext(r, context)
|
||||
p = request.GetPersister(r)
|
||||
user, err := getSecuredUser(p, org.RefID, context.UserID)
|
||||
|
||||
valid = context.Authenticated || org.AllowAnonymousAccess
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
context.Administrator = user.Admin
|
||||
context.Editor = user.Editor
|
||||
context.Global = user.Global
|
||||
|
||||
util.WriteJSON(w, user)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,23 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// UploadConvertDocument is an endpoint to both upload and convert a document
|
||||
func UploadConvertDocument(w http.ResponseWriter, r *http.Request) {
|
||||
job, folderID, orgID := uploadDocument(w, r)
|
||||
if job == "" {
|
||||
return // error already handled
|
||||
}
|
||||
|
||||
convertDocument(w, r, job, folderID, api.ConversionJobRequest{
|
||||
Job: job,
|
||||
IndexDepth: 4,
|
||||
OrgID: orgID,
|
||||
})
|
||||
}
|
||||
|
||||
func uploadDocument(w http.ResponseWriter, r *http.Request) (string, string, string) {
|
||||
method := "uploadDocument"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
folderID := params["folderID"]
|
||||
|
||||
|
@ -47,7 +60,6 @@ func uploadDocument(w http.ResponseWriter, r *http.Request) (string, string, str
|
|||
|
||||
// grab file
|
||||
filedata, filename, err := r.FormFile("attachment")
|
||||
|
||||
if err != nil {
|
||||
writeMissingDataError(w, method, "attachment")
|
||||
return "", "", ""
|
||||
|
@ -55,7 +67,6 @@ func uploadDocument(w http.ResponseWriter, r *http.Request) (string, string, str
|
|||
|
||||
b := new(bytes.Buffer)
|
||||
_, err = io.Copy(b, filedata)
|
||||
|
||||
if err != nil {
|
||||
writeServerError(w, method, err)
|
||||
return "", "", ""
|
||||
|
@ -90,7 +101,6 @@ func convertDocument(w http.ResponseWriter, r *http.Request, job, folderID strin
|
|||
var err error
|
||||
|
||||
filename, fileResult, err = storageProvider.Convert(conversion)
|
||||
|
||||
if err != nil {
|
||||
writePayloadError(w, method, err)
|
||||
return
|
||||
|
@ -124,19 +134,6 @@ func convertDocument(w http.ResponseWriter, r *http.Request, job, folderID strin
|
|||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// UploadConvertDocument is an endpoint to both upload and convert a document
|
||||
func UploadConvertDocument(w http.ResponseWriter, r *http.Request) {
|
||||
job, folderID, orgID := uploadDocument(w, r)
|
||||
if job == "" {
|
||||
return // error already handled
|
||||
}
|
||||
convertDocument(w, r, job, folderID, api.ConversionJobRequest{
|
||||
Job: job,
|
||||
IndexDepth: 4,
|
||||
OrgID: orgID,
|
||||
})
|
||||
}
|
||||
|
||||
func processDocument(p request.Persister, filename, job, folderID string, fileResult *api.DocumentConversionResponse) (newDocument entity.Document, err error) {
|
||||
// Convert into database objects
|
||||
document := store.ConvertFileResult(filename, fileResult)
|
||||
|
|
|
@ -134,7 +134,7 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPublic, "meta", []string{"GET", "OPTIONS"}, nil, GetMeta))
|
||||
log.IfErr(Add(RoutePrefixPublic, "authenticate/keycloak", []string{"POST", "OPTIONS"}, nil, AuthenticateKeycloak))
|
||||
log.IfErr(Add(RoutePrefixPublic, "authenticate", []string{"POST", "OPTIONS"}, nil, Authenticate))
|
||||
// log.IfErr(Add(RoutePrefixPublic, "validate", []string{"GET", "OPTIONS"}, nil, ValidateAuthToken))
|
||||
log.IfErr(Add(RoutePrefixPublic, "validate", []string{"GET", "OPTIONS"}, nil, ValidateAuthToken))
|
||||
log.IfErr(Add(RoutePrefixPublic, "forgot", []string{"POST", "OPTIONS"}, nil, ForgotUserPassword))
|
||||
log.IfErr(Add(RoutePrefixPublic, "reset/{token}", []string{"POST", "OPTIONS"}, nil, ResetUserPassword))
|
||||
log.IfErr(Add(RoutePrefixPublic, "share/{folderID}", []string{"POST", "OPTIONS"}, nil, AcceptSharedFolder))
|
||||
|
|
|
@ -35,7 +35,7 @@ var Product core.ProdInfo
|
|||
func init() {
|
||||
Product.Major = "1"
|
||||
Product.Minor = "47"
|
||||
Product.Patch = "1"
|
||||
Product.Patch = "2"
|
||||
Product.Version = fmt.Sprintf("%s.%s.%s", Product.Major, Product.Minor, Product.Patch)
|
||||
Product.Edition = "Community"
|
||||
Product.Title = fmt.Sprintf("%s Edition", Product.Edition)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue