Skip to content

Commit db4da7b

Browse files
committed
Add APIContext
1 parent b4f47a7 commit db4da7b

File tree

8 files changed

+93
-63
lines changed

8 files changed

+93
-63
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ There are 5 ways to install Gogs:
105105
- [Puppet](https://forge.puppetlabs.com/Siteminds/gogs) (IT)
106106
- [Kanboard](http://kanboard.net/plugin/gogs-webhook) (Project Management)
107107
- [BearyChat](https://bearychat.com/) (Team Communication)
108+
- [HiWork](http://www.hiwork.cc/) (Team Communication)
108109

109110
### Product Support
110111

README_ZH.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
7777
- [Puppet](https://forge.puppetlabs.com/Siteminds/gogs)(IT)
7878
- [Kanboard](http://kanboard.net/plugin/gogs-webhook)(项目管理)
7979
- [BearyChat](https://bearychat.com/)(团队交流)
80+
- [HiWork](http://www.hiwork.cc/)(团队交流)
8081

8182
### 产品支持
8283

modules/context/api.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Gogs Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package context
6+
7+
import (
8+
"gopkg.in/macaron.v1"
9+
)
10+
11+
type APIContext struct {
12+
*Context
13+
}
14+
15+
func APIContexter() macaron.Handler {
16+
return func(c *Context) {
17+
ctx := &APIContext{
18+
Context: c,
19+
}
20+
c.Map(ctx)
21+
}
22+
}

modules/context/context.go

+2-63
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,13 @@ import (
1818
"github.com/go-macaron/session"
1919
"gopkg.in/macaron.v1"
2020

21-
"github.com/gogits/git-module"
22-
2321
"github.com/gogits/gogs/models"
2422
"github.com/gogits/gogs/modules/auth"
2523
"github.com/gogits/gogs/modules/base"
2624
"github.com/gogits/gogs/modules/log"
2725
"github.com/gogits/gogs/modules/setting"
2826
)
2927

30-
type PullRequest struct {
31-
BaseRepo *models.Repository
32-
Allowed bool
33-
SameRepo bool
34-
HeadInfo string // [<user>:]<branch>
35-
}
36-
37-
type Repository struct {
38-
AccessMode models.AccessMode
39-
IsWatching bool
40-
IsViewBranch bool
41-
IsViewTag bool
42-
IsViewCommit bool
43-
Repository *models.Repository
44-
Owner *models.User
45-
Commit *git.Commit
46-
Tag *git.Tag
47-
GitRepo *git.Repository
48-
BranchName string
49-
TagName string
50-
TreeName string
51-
CommitID string
52-
RepoLink string
53-
CloneLink models.CloneLink
54-
CommitsCount int64
55-
Mirror *models.Mirror
56-
57-
PullRequest *PullRequest
58-
}
59-
60-
// IsOwner returns true if current user is the owner of repository.
61-
func (r *Repository) IsOwner() bool {
62-
return r.AccessMode >= models.ACCESS_MODE_OWNER
63-
}
64-
65-
// IsAdmin returns true if current user has admin or higher access of repository.
66-
func (r *Repository) IsAdmin() bool {
67-
return r.AccessMode >= models.ACCESS_MODE_ADMIN
68-
}
69-
70-
// IsWriter returns true if current user has write or higher access of repository.
71-
func (r *Repository) IsWriter() bool {
72-
return r.AccessMode >= models.ACCESS_MODE_WRITE
73-
}
74-
75-
// HasAccess returns true if the current user has at least read access for this repository
76-
func (r *Repository) HasAccess() bool {
77-
return r.AccessMode >= models.ACCESS_MODE_READ
78-
}
79-
8028
// Context represents context of a request.
8129
type Context struct {
8230
*macaron.Context
@@ -90,17 +38,7 @@ type Context struct {
9038
IsBasicAuth bool
9139

9240
Repo *Repository
93-
94-
Org struct {
95-
IsOwner bool
96-
IsMember bool
97-
IsTeamMember bool // Is member of team.
98-
IsTeamAdmin bool // In owner team or team that has admin permission level.
99-
Organization *models.User
100-
OrgLink string
101-
102-
Team *models.Team
103-
}
41+
Org *Organization
10442
}
10543

10644
// HasError returns true if error occurs in form validation.
@@ -223,6 +161,7 @@ func Contexter() macaron.Handler {
223161
Repo: &Repository{
224162
PullRequest: &PullRequest{},
225163
},
164+
Org: &Organization{},
226165
}
227166
// Compute current URL for real-time change language.
228167
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")

modules/context/org.go

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import (
1313
"github.com/gogits/gogs/modules/setting"
1414
)
1515

16+
type Organization struct {
17+
IsOwner bool
18+
IsMember bool
19+
IsTeamMember bool // Is member of team.
20+
IsTeamAdmin bool // In owner team or team that has admin permission level.
21+
Organization *models.User
22+
OrgLink string
23+
24+
Team *models.Team
25+
}
26+
1627
func HandleOrgAssignment(ctx *Context, args ...bool) {
1728
var (
1829
requireMember bool

modules/context/repo.go

+50
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,56 @@ import (
1818
"github.com/gogits/gogs/modules/setting"
1919
)
2020

21+
type PullRequest struct {
22+
BaseRepo *models.Repository
23+
Allowed bool
24+
SameRepo bool
25+
HeadInfo string // [<user>:]<branch>
26+
}
27+
28+
type Repository struct {
29+
AccessMode models.AccessMode
30+
IsWatching bool
31+
IsViewBranch bool
32+
IsViewTag bool
33+
IsViewCommit bool
34+
Repository *models.Repository
35+
Owner *models.User
36+
Commit *git.Commit
37+
Tag *git.Tag
38+
GitRepo *git.Repository
39+
BranchName string
40+
TagName string
41+
TreeName string
42+
CommitID string
43+
RepoLink string
44+
CloneLink models.CloneLink
45+
CommitsCount int64
46+
Mirror *models.Mirror
47+
48+
PullRequest *PullRequest
49+
}
50+
51+
// IsOwner returns true if current user is the owner of repository.
52+
func (r *Repository) IsOwner() bool {
53+
return r.AccessMode >= models.ACCESS_MODE_OWNER
54+
}
55+
56+
// IsAdmin returns true if current user has admin or higher access of repository.
57+
func (r *Repository) IsAdmin() bool {
58+
return r.AccessMode >= models.ACCESS_MODE_ADMIN
59+
}
60+
61+
// IsWriter returns true if current user has write or higher access of repository.
62+
func (r *Repository) IsWriter() bool {
63+
return r.AccessMode >= models.ACCESS_MODE_WRITE
64+
}
65+
66+
// HasAccess returns true if the current user has at least read access for this repository
67+
func (r *Repository) HasAccess() bool {
68+
return r.AccessMode >= models.ACCESS_MODE_READ
69+
}
70+
2171
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
2272
// Non-fork repository will not return error in this method.
2373
if err := repo.GetBaseRepo(); err != nil {

public/css/gogs.css

+3
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,9 @@ footer .container .links > *:first-child {
23762376
.user.settings .email.list .item:not(:first-child) .button {
23772377
margin-top: -10px;
23782378
}
2379+
.user.profile .ui.card #profile-avatar {
2380+
height: 290px;
2381+
}
23792382
.user.profile .ui.card .username {
23802383
display: block;
23812384
}

public/less/_user.less

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
&.profile {
2525
.ui.card {
26+
#profile-avatar {
27+
height: 290px;
28+
}
2629
.username {
2730
display: block;
2831
}

0 commit comments

Comments
 (0)