Selaa lähdekoodia

Merge branch 'master' of gitote.in:gitote/gitote

Yoginth 7 vuotta sitten
vanhempi
commit
1b82225af8

+ 17 - 0
models/errors/org.go

@@ -0,0 +1,17 @@
+package errors
+
+import "fmt"
+
+type TeamNotExist struct {
+	TeamID int64
+	Name   string
+}
+
+func IsTeamNotExist(err error) bool {
+	_, ok := err.(TeamNotExist)
+	return ok
+}
+
+func (err TeamNotExist) Error() string {
+	return fmt.Sprintf("team does not exist [team_id: %d, name: %s]", err.TeamID, err.Name)
+}

+ 1 - 2
models/org.go

@@ -11,8 +11,7 @@ import (
 )
 
 var (
-	ErrOrgNotExist  = errors.New("Organization does not exist")
-	ErrTeamNotExist = errors.New("Team does not exist")
+	ErrOrgNotExist = errors.New("Organization does not exist")
 )
 
 // IsOwnedBy returns true if given user is in the owner team.

+ 3 - 3
models/org_team.go

@@ -1,8 +1,8 @@
 package models
 
 import (
-	"errors"
 	"fmt"
+	"gitote/gitote/models/errors"
 	"strings"
 
 	"github.com/go-xorm/xorm"
@@ -269,7 +269,7 @@ func getTeamOfOrgByName(e Engine, orgID int64, name string) (*Team, error) {
 	if err != nil {
 		return nil, err
 	} else if !has {
-		return nil, ErrTeamNotExist
+		return nil, errors.TeamNotExist{0, name}
 	}
 	return t, nil
 }
@@ -285,7 +285,7 @@ func getTeamByID(e Engine, teamID int64) (*Team, error) {
 	if err != nil {
 		return nil, err
 	} else if !has {
-		return nil, ErrTeamNotExist
+		return nil, errors.TeamNotExist{teamID, ""}
 	}
 	return t, nil
 }

+ 23 - 1
pkg/context/api.go

@@ -3,6 +3,7 @@ package context
 import (
 	"fmt"
 	"gitote/gitote/pkg/setting"
+	"net/http"
 	"strings"
 
 	"gitlab.com/yoginth/paginater"
@@ -28,7 +29,7 @@ func (c *APIContext) Error(status int, title string, obj interface{}) {
 		message = obj.(string)
 	}
 
-	if status == 500 {
+	if status == http.StatusInternalServerError {
 		log.Error(3, "%s: %s", title, message)
 	}
 
@@ -38,6 +39,27 @@ func (c *APIContext) Error(status int, title string, obj interface{}) {
 	})
 }
 
+// NotFound renders the 404 response.
+func (c *APIContext) NotFound() {
+	c.Status(http.StatusNotFound)
+}
+
+// ServerError renders the 500 response.
+func (c *APIContext) ServerError(title string, err error) {
+	c.Error(http.StatusInternalServerError, title, err)
+}
+
+// NotFoundOrServerError use error check function to determine if the error
+// is about not found. It responses with 404 status code for not found error,
+// or error context description for logging purpose of 500 server error.
+func (c *APIContext) NotFoundOrServerError(title string, errck func(error) bool, err error) {
+	if errck(err) {
+		c.NotFound()
+		return
+	}
+	c.ServerError(title, err)
+}
+
 // SetLinkHeader sets pagination link header by given total number and page size.
 func (c *APIContext) SetLinkHeader(total, pageSize int) {
 	page := paginater.New(total, pageSize, c.QueryInt("page"), 0)

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
public/css/gitote.min.css


+ 1 - 1
public/expansion/expansion.js

@@ -17,4 +17,4 @@ var nextWord = (function() {
         if (!copy || !copy.length) copy = wordArray.slice();
         return copy.splice(Math.random() * copy.length | 0, 1);
     }
-}());
+}());

+ 2 - 1
public/less/_base.less

@@ -580,6 +580,7 @@ footer {
 
 .infobar {
 	color: @white;
+	user-select: none;
 	
 	&.align {
 		margin-right: 18px;
@@ -594,7 +595,7 @@ footer {
 	&.expansion {
 		cursor: pointer;
 	    letter-spacing: .2px;
-	    user-select: none;
+		-webkit-tap-highlight-color: transparent;
 	    display: inline-block;
 	    position: relative;
 	    z-index: 1;

+ 18 - 34
routes/api/v1/api.go

@@ -10,6 +10,7 @@ import (
 	"gitote/gitote/routes/api/v1/org"
 	"gitote/gitote/routes/api/v1/repo"
 	"gitote/gitote/routes/api/v1/user"
+	"net/http"
 	"strings"
 
 	"github.com/go-macaron/binding"
@@ -33,43 +34,34 @@ func repoAssignment() macaron.Handler {
 		} else {
 			owner, err = models.GetUserByName(userName)
 			if err != nil {
-				if errors.IsUserNotExist(err) {
-					c.Status(404)
-				} else {
-					c.Error(500, "GetUserByName", err)
-				}
+				c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 				return
 			}
 		}
 		c.Repo.Owner = owner
 
-		// Get repository.
 		repo, err := models.GetRepositoryByName(owner.ID, repoName)
 		if err != nil {
-			if errors.IsRepoNotExist(err) {
-				c.Status(404)
-			} else {
-				c.Error(500, "GetRepositoryByName", err)
-			}
+			c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
 			return
 		} else if err = repo.GetOwner(); err != nil {
-			c.Error(500, "GetOwner", err)
+			c.ServerError("GetOwner", err)
 			return
 		}
 
-		if c.IsLogged && c.User.IsAdmin {
+		if c.IsTokenAuth && c.User.IsAdmin {
 			c.Repo.AccessMode = models.ACCESS_MODE_OWNER
 		} else {
-			mode, err := models.AccessLevel(c.User.ID, repo)
+			mode, err := models.AccessLevel(c.UserID(), repo)
 			if err != nil {
-				c.Error(500, "AccessLevel", err)
+				c.ServerError("AccessLevel", err)
 				return
 			}
 			c.Repo.AccessMode = mode
 		}
 
 		if !c.Repo.HasAccess() {
-			c.Status(404)
+			c.NotFound()
 			return
 		}
 
@@ -81,7 +73,7 @@ func repoAssignment() macaron.Handler {
 func reqToken() macaron.Handler {
 	return func(c *context.Context) {
 		if !c.IsTokenAuth {
-			c.Error(401)
+			c.Error(http.StatusUnauthorized)
 			return
 		}
 	}
@@ -90,7 +82,7 @@ func reqToken() macaron.Handler {
 func reqBasicAuth() macaron.Handler {
 	return func(c *context.Context) {
 		if !c.IsBasicAuth {
-			c.Error(401)
+			c.Error(http.StatusUnauthorized)
 			return
 		}
 	}
@@ -99,7 +91,7 @@ func reqBasicAuth() macaron.Handler {
 func reqAdmin() macaron.Handler {
 	return func(c *context.Context) {
 		if !c.IsLogged || !c.User.IsAdmin {
-			c.Error(403)
+			c.Error(http.StatusForbidden)
 			return
 		}
 	}
@@ -108,7 +100,7 @@ func reqAdmin() macaron.Handler {
 func reqRepoWriter() macaron.Handler {
 	return func(c *context.Context) {
 		if !c.Repo.IsWriter() {
-			c.Error(403)
+			c.Error(http.StatusForbidden)
 			return
 		}
 	}
@@ -132,11 +124,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 		if assignOrg {
 			c.Org.Organization, err = models.GetUserByName(c.Params(":orgname"))
 			if err != nil {
-				if errors.IsUserNotExist(err) {
-					c.Status(404)
-				} else {
-					c.Error(500, "GetUserByName", err)
-				}
+				c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 				return
 			}
 		}
@@ -144,11 +132,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 		if assignTeam {
 			c.Org.Team, err = models.GetTeamByID(c.ParamsInt64(":teamid"))
 			if err != nil {
-				if errors.IsUserNotExist(err) {
-					c.Status(404)
-				} else {
-					c.Error(500, "GetTeamById", err)
-				}
+				c.NotFoundOrServerError("GetTeamByID", errors.IsTeamNotExist, err)
 				return
 			}
 		}
@@ -157,7 +141,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 
 func mustEnableIssues(c *context.APIContext) {
 	if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker {
-		c.Status(404)
+		c.NotFound()
 		return
 	}
 }
@@ -232,12 +216,12 @@ func RegisterRoutes(m *macaron.Macaron) {
 
 		m.Group("/repos", func() {
 			m.Get("/search", repo.Search)
+			m.Get("/:username/:reponame", repoAssignment(), repo.Get)
 		})
 
 		m.Group("/repos", func() {
 			m.Post("/migrate", bind(form.MigrateRepo{}), repo.Migrate)
-			m.Combo("/:username/:reponame", repoAssignment()).Get(repo.Get).
-				Delete(repo.Delete)
+			m.Delete("/:username/:reponame", repoAssignment(), repo.Delete)
 
 			m.Group("/:username/:reponame", func() {
 				m.Group("/hooks", func() {
@@ -319,7 +303,7 @@ func RegisterRoutes(m *macaron.Macaron) {
 		}, orgAssignment(true))
 
 		m.Any("/*", func(c *context.Context) {
-			c.Error(404)
+			c.NotFound()
 		})
 
 		m.Group("/admin", func() {

+ 3 - 3
templates/base/info_bar.tmpl

@@ -14,9 +14,9 @@
                 {{end}}
                 <span class="infobar align">
                     <span class="infobar heart">❤</span>
-                    <span 
-                        id="expansion" 
-                        class="infobar expansion" 
+                    <span
+                        id="expansion"
+                        class="infobar expansion"
                         onclick="document.getElementById('expansion').innerHTML = nextWord();" >
                         Get It Together
                     </span>

+ 1 - 1
templates/pages/about.tmpl

@@ -14,7 +14,7 @@
         </p>
         <ul>
             <li class="pages-small">
-                Gitote is the software hosting platform. It was created in 2018 as an <a href="collaborate">open source project</a> 
+                Gitote is the software hosting platform. It was created in 2018 as an <a href="{{AppURL}}gitote/gitote">open source project</a> 
                 to help developers easily share and collaborate softwares.
             </li>
             <li class="pages-small">