Skip to content

Commit

Permalink
GitHub section improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HarveyKandola committed May 17, 2017
1 parent 60131df commit 65666c5
Show file tree
Hide file tree
Showing 11 changed files with 685 additions and 667 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li

## Latest version

v1.47.1
v1.47.2

## OS Support

Expand Down
13 changes: 10 additions & 3 deletions app/app/styles/section/github.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
}

.section-github-render {
font-size: 0.9rem;

a:hover {
text-decoration: underline;
}
Expand Down Expand Up @@ -77,8 +79,8 @@
}

.github-table tbody tr td {
border: none!important;
padding: 5px 20px !important;
border: none !important;
padding: 5px 0 !important;
}

.github-table .right-column {
Expand Down Expand Up @@ -114,6 +116,11 @@
}
}

.contributor-meta {
white-space: nowrap;
width: 1%;
}

span.issue-state {
float: left;
margin-right: 10px;
Expand All @@ -123,6 +130,6 @@
img.github-avatar {
width: 24px;
border-radius: 4px;
margin-right: 10px;
margin-left: 10px;
}
}
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "documize",
"version": "1.47.1",
"version": "1.47.2",
"description": "The Document IDE",
"private": true,
"repository": "",
Expand Down
2 changes: 1 addition & 1 deletion core/api/convert/apidocumizecom/msword.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 29 additions & 15 deletions core/api/endpoint/authentication_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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 {
Expand All @@ -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 !context.Authenticated {
w.WriteHeader(http.StatusUnauthorized)
return
}

if err != nil {
return
}
user, err := getSecuredUser(p, org.RefID, context.UserID)

context.Administrator = user.Admin
context.Editor = user.Editor
context.Global = user.Global
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}

request.SetContext(r, context)
p = request.GetPersister(r)

valid = context.Authenticated || org.AllowAnonymousAccess
context.Administrator = user.Admin
context.Editor = user.Editor
context.Global = user.Global

util.WriteJSON(w, user)
return
}

Expand Down
31 changes: 14 additions & 17 deletions core/api/endpoint/conversion_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -47,15 +60,13 @@ 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 "", "", ""
}

b := new(bytes.Buffer)
_, err = io.Copy(b, filedata)

if err != nil {
writeServerError(w, method, err)
return "", "", ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/api/endpoint/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion core/api/endpoint/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/section/github/commits.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize unity 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
Expand All @@ -22,7 +22,7 @@ import (
gogithub "github.com/google/go-github/github"
)

const commitTimeFormat = "January 2 2006, 15:04"
const commitTimeFormat = "2006-01-02, 15:04"

type githubCommit struct {
Owner string `json:"owner"`
Expand Down
4 changes: 2 additions & 2 deletions core/section/github/commits_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const commitsTemplate = `
<table class="github-table" style="width: 100%;">
<thead>
<tr>
<th class="title">Commits <span>&middot; {{len .BranchCommits}} commits by {{.NumContributors}} contributors</span>
<th class="title">Commits <span>&middot; {{len .BranchCommits}} commits</span>
</th>
<th></th>
</tr>
Expand All @@ -85,8 +85,8 @@ const commitsTemplate = `
</td>
<td class="right-column">
<div class="contributor-meta">
<img class="github-avatar" title="@{{$commit.Name}}" alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" />
{{$commit.Date}}
<img class="github-avatar" title="@{{$commit.Name}}" alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" />
</div>
</td>
</tr>
Expand Down
1,246 changes: 623 additions & 623 deletions embed/bindata_assetfs.go

Large diffs are not rendered by default.

0 comments on commit 65666c5

Please sign in to comment.