Skip to content

Commit ac43eab

Browse files
committed
Refactoring: rename Signed -> Logged
1 parent 8d04174 commit ac43eab

37 files changed

+106
-104
lines changed

pkg/context/auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ func Toggle(options *ToggleOptions) macaron.Handler {
3030
}
3131

3232
// Check prohibit login users.
33-
if ctx.IsSigned && ctx.User.ProhibitLogin {
33+
if ctx.IsLogged && ctx.User.ProhibitLogin {
3434
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
3535
ctx.HTML(200, "user/auth/prohibit_login")
3636
return
3737
}
3838

3939
// Check non-logged users landing page.
40-
if !ctx.IsSigned && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME {
40+
if !ctx.IsLogged && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME {
4141
ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
4242
return
4343
}
4444

4545
// Redirect to dashboard if user tries to visit any non-login page.
46-
if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" {
46+
if options.SignOutRequired && ctx.IsLogged && ctx.Req.RequestURI != "/" {
4747
ctx.Redirect(setting.AppSubURL + "/")
4848
return
4949
}
@@ -56,7 +56,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
5656
}
5757

5858
if options.SignInRequired {
59-
if !ctx.IsSigned {
59+
if !ctx.IsLogged {
6060
// Restrict API calls with error message.
6161
if auth.IsAPIPath(ctx.Req.URL.Path) {
6262
ctx.JSON(403, map[string]string{
@@ -76,7 +76,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
7676
}
7777

7878
// Redirect to log in page if auto-signin info is provided and has not signed in.
79-
if !options.SignOutRequired && !ctx.IsSigned && !auth.IsAPIPath(ctx.Req.URL.Path) &&
79+
if !options.SignOutRequired && !ctx.IsLogged && !auth.IsAPIPath(ctx.Req.URL.Path) &&
8080
len(ctx.GetCookie(setting.CookieUserName)) > 0 {
8181
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
8282
ctx.Redirect(setting.AppSubURL + "/user/login")

pkg/context/context.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,20 @@ type Context struct {
3434
Session session.Store
3535

3636
User *models.User
37-
IsSigned bool
37+
IsLogged bool
3838
IsBasicAuth bool
3939

4040
Repo *Repository
4141
Org *Organization
4242
}
4343

44-
func (ctx *Context) UserID() int64 {
45-
if !ctx.IsSigned {
44+
// UserID returns ID of current logged in user.
45+
// It returns 0 if visitor is anonymous.
46+
func (c *Context) UserID() int64 {
47+
if !c.IsLogged {
4648
return 0
4749
}
48-
return ctx.User.ID
50+
return c.User.ID
4951
}
5052

5153
// HasError returns true if error occurs in form validation.
@@ -112,7 +114,7 @@ func (ctx *Context) Handle(status int, title string, err error) {
112114
case http.StatusInternalServerError:
113115
ctx.Data["Title"] = "Internal Server Error"
114116
log.Error(2, "%s: %v", title, err)
115-
if !setting.ProdMode || (ctx.IsSigned && ctx.User.IsAdmin) {
117+
if !setting.ProdMode || (ctx.IsLogged && ctx.User.IsAdmin) {
116118
ctx.Data["ErrorMsg"] = err
117119
}
118120
}
@@ -193,15 +195,15 @@ func Contexter() macaron.Handler {
193195
ctx.User, ctx.IsBasicAuth = auth.SignedInUser(ctx.Context, ctx.Session)
194196

195197
if ctx.User != nil {
196-
ctx.IsSigned = true
197-
ctx.Data["IsSigned"] = ctx.IsSigned
198-
ctx.Data["SignedUser"] = ctx.User
199-
ctx.Data["SignedUserID"] = ctx.User.ID
200-
ctx.Data["SignedUserName"] = ctx.User.Name
198+
ctx.IsLogged = true
199+
ctx.Data["IsLogged"] = ctx.IsLogged
200+
ctx.Data["LoggedUser"] = ctx.User
201+
ctx.Data["LoggedUserID"] = ctx.User.ID
202+
ctx.Data["LoggedUserName"] = ctx.User.Name
201203
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
202204
} else {
203-
ctx.Data["SignedUserID"] = 0
204-
ctx.Data["SignedUserName"] = ""
205+
ctx.Data["LoggedUserID"] = 0
206+
ctx.Data["LoggedUserName"] = ""
205207
}
206208

207209
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.

pkg/context/org.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
6363
}
6464

6565
// Admin has super access.
66-
if ctx.IsSigned && ctx.User.IsAdmin {
66+
if ctx.IsLogged && ctx.User.IsAdmin {
6767
ctx.Org.IsOwner = true
6868
ctx.Org.IsMember = true
6969
ctx.Org.IsTeamMember = true
7070
ctx.Org.IsTeamAdmin = true
71-
} else if ctx.IsSigned {
71+
} else if ctx.IsLogged {
7272
ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.ID)
7373
if ctx.Org.IsOwner {
7474
ctx.Org.IsMember = true

pkg/context/repo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
151151
}
152152

153153
// Check if the user is the same as the repository owner
154-
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(ownerName) {
154+
if ctx.IsLogged && ctx.User.LowerName == strings.ToLower(ownerName) {
155155
owner = ctx.User
156156
} else {
157157
owner, err = models.GetUserByName(ownerName)
@@ -194,7 +194,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
194194
ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
195195

196196
// Admin has super access.
197-
if ctx.IsSigned && ctx.User.IsAdmin {
197+
if ctx.IsLogged && ctx.User.IsAdmin {
198198
ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER
199199
} else {
200200
mode, err := models.AccessLevel(ctx.UserID(), repo)
@@ -278,7 +278,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
278278
ctx.Data["CloneLink"] = repo.CloneLink()
279279
ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
280280

281-
if ctx.IsSigned {
281+
if ctx.IsLogged {
282282
ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID)
283283
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID)
284284
}
@@ -424,7 +424,7 @@ func RepoRef() macaron.Handler {
424424
ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
425425

426426
// People who have push access or have fored repository can propose a new pull request.
427-
if ctx.Repo.IsWriter() || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) {
427+
if ctx.Repo.IsWriter() || (ctx.IsLogged && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) {
428428
// Pull request is allowed if this is a fork repository
429429
// and base repository accepts pull requests.
430430
if ctx.Repo.Repository.BaseRepo != nil {
@@ -459,7 +459,7 @@ func RepoRef() macaron.Handler {
459459

460460
func RequireRepoAdmin() macaron.Handler {
461461
return func(ctx *Context) {
462-
if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
462+
if !ctx.IsLogged || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
463463
ctx.NotFound()
464464
return
465465
}
@@ -468,7 +468,7 @@ func RequireRepoAdmin() macaron.Handler {
468468

469469
func RequireRepoWriter() macaron.Handler {
470470
return func(ctx *Context) {
471-
if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
471+
if !ctx.IsLogged || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
472472
ctx.NotFound()
473473
return
474474
}

routers/api/v1/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func repoAssignment() macaron.Handler {
3434
)
3535

3636
// Check if the user is the same as the repository owner.
37-
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
37+
if ctx.IsLogged && ctx.User.LowerName == strings.ToLower(userName) {
3838
owner = ctx.User
3939
} else {
4040
owner, err = models.GetUserByName(userName)
@@ -63,7 +63,7 @@ func repoAssignment() macaron.Handler {
6363
return
6464
}
6565

66-
if ctx.IsSigned && ctx.User.IsAdmin {
66+
if ctx.IsLogged && ctx.User.IsAdmin {
6767
ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER
6868
} else {
6969
mode, err := models.AccessLevel(ctx.User.ID, repo)
@@ -86,7 +86,7 @@ func repoAssignment() macaron.Handler {
8686
// Contexter middleware already checks token for user sign in process.
8787
func reqToken() macaron.Handler {
8888
return func(ctx *context.Context) {
89-
if !ctx.IsSigned {
89+
if !ctx.IsLogged {
9090
ctx.Error(401)
9191
return
9292
}
@@ -104,7 +104,7 @@ func reqBasicAuth() macaron.Handler {
104104

105105
func reqAdmin() macaron.Handler {
106106
return func(ctx *context.Context) {
107-
if !ctx.IsSigned || !ctx.User.IsAdmin {
107+
if !ctx.IsLogged || !ctx.User.IsAdmin {
108108
ctx.Error(403)
109109
return
110110
}

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Search(ctx *context.APIContext) {
2828
}
2929

3030
// Check visibility.
31-
if ctx.IsSigned && opts.OwnerID > 0 {
31+
if ctx.IsLogged && opts.OwnerID > 0 {
3232
if ctx.User.ID == opts.OwnerID {
3333
opts.Private = true
3434
} else {

routers/api/v1/user/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Search(ctx *context.APIContext) {
4141
AvatarUrl: users[i].AvatarLink(),
4242
FullName: users[i].FullName,
4343
}
44-
if ctx.IsSigned {
44+
if ctx.IsLogged {
4545
results[i].Email = users[i].Email
4646
}
4747
}
@@ -64,7 +64,7 @@ func GetInfo(ctx *context.APIContext) {
6464
}
6565

6666
// Hide user e-mail when API caller isn't signed in.
67-
if !ctx.IsSigned {
67+
if !ctx.IsLogged {
6868
u.Email = ""
6969
}
7070
ctx.JSON(200, u.APIFormat())

routers/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
func Home(ctx *context.Context) {
24-
if ctx.IsSigned {
24+
if ctx.IsLogged {
2525
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
2626
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
2727
ctx.HTML(200, user.ACTIVATE)

routers/repo/issue.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func MustAllowPulls(ctx *context.Context) {
7070
}
7171

7272
// User can send pull request if owns a forked repository.
73-
if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
73+
if ctx.IsLogged && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
7474
ctx.Repo.PullRequest.Allowed = true
7575
ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
7676
}
@@ -115,7 +115,7 @@ func issues(ctx *context.Context, isPullList bool) {
115115
}
116116

117117
// Must sign in to see issues about you.
118-
if viewType != "all" && !ctx.IsSigned {
118+
if viewType != "all" && !ctx.IsLogged {
119119
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
120120
ctx.Redirect(setting.AppSubURL + "/user/login")
121121
return
@@ -138,7 +138,7 @@ func issues(ctx *context.Context, isPullList bool) {
138138
}
139139

140140
var uid int64 = -1
141-
if ctx.IsSigned {
141+
if ctx.IsLogged {
142142
uid = ctx.User.ID
143143
}
144144

@@ -197,7 +197,7 @@ func issues(ctx *context.Context, isPullList bool) {
197197

198198
// Get posters.
199199
for i := range issues {
200-
if !ctx.IsSigned {
200+
if !ctx.IsLogged {
201201
issues[i].IsRead = true
202202
continue
203203
}
@@ -587,7 +587,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
587587
}
588588
}
589589

590-
if ctx.IsSigned {
590+
if ctx.IsLogged {
591591
// Update issue-user.
592592
if err = issue.ReadBy(ctx.User.ID); err != nil {
593593
ctx.Handle(500, "ReadBy", err)
@@ -652,7 +652,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
652652
ctx.Data["Participants"] = participants
653653
ctx.Data["NumParticipants"] = len(participants)
654654
ctx.Data["Issue"] = issue
655-
ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
655+
ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsLogged && issue.IsPoster(ctx.User.ID))
656656
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
657657
ctx.HTML(200, ISSUE_VIEW)
658658
}
@@ -687,7 +687,7 @@ func UpdateIssueTitle(ctx *context.Context) {
687687
return
688688
}
689689

690-
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) {
690+
if !ctx.IsLogged || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) {
691691
ctx.Error(403)
692692
return
693693
}
@@ -714,7 +714,7 @@ func UpdateIssueContent(ctx *context.Context) {
714714
return
715715
}
716716

717-
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) {
717+
if !ctx.IsLogged || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) {
718718
ctx.Error(403)
719719
return
720720
}
@@ -843,7 +843,7 @@ func NewComment(ctx *context.Context, f form.CreateComment) {
843843
var comment *models.Comment
844844
defer func() {
845845
// Check if issue admin/poster changes the status of issue.
846-
if (ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
846+
if (ctx.Repo.IsWriter() || (ctx.IsLogged && issue.IsPoster(ctx.User.ID))) &&
847847
(f.Status == "reopen" || f.Status == "close") &&
848848
!(issue.IsPull && issue.PullRequest.HasMerged) {
849849

routers/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
153153
return nil
154154
}
155155

156-
if ctx.IsSigned {
156+
if ctx.IsLogged {
157157
// Update issue-user.
158158
if err = issue.ReadBy(ctx.User.ID); err != nil {
159159
ctx.Handle(500, "ReadBy", err)

routers/user/home.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,15 @@ func showOrgProfile(ctx *context.Context) {
379379
count int64
380380
err error
381381
)
382-
if ctx.IsSigned && !ctx.User.IsAdmin {
382+
if ctx.IsLogged && !ctx.User.IsAdmin {
383383
repos, count, err = org.GetUserRepositories(ctx.User.ID, page, setting.UI.User.RepoPagingNum)
384384
if err != nil {
385385
ctx.Handle(500, "GetUserRepositories", err)
386386
return
387387
}
388388
ctx.Data["Repos"] = repos
389389
} else {
390-
showPrivate := ctx.IsSigned && ctx.User.IsAdmin
390+
showPrivate := ctx.IsLogged && ctx.User.IsAdmin
391391
repos, err = models.GetUserRepositories(&models.UserRepoOptions{
392392
UserID: org.ID,
393393
Private: showPrivate,

routers/user/profile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func Profile(ctx *context.Context) {
7373
ctx.Data["PageIsUserProfile"] = true
7474
ctx.Data["Owner"] = ctxUser
7575

76-
orgs, err := models.GetOrgsByUserID(ctxUser.ID, ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID))
76+
orgs, err := models.GetOrgsByUserID(ctxUser.ID, ctx.IsLogged && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID))
7777
if err != nil {
7878
ctx.Handle(500, "GetOrgsByUserIDDesc", err)
7979
return
@@ -95,7 +95,7 @@ func Profile(ctx *context.Context) {
9595
page = 1
9696
}
9797

98-
showPrivate := ctx.IsSigned && (ctxUser.ID == ctx.User.ID || ctx.User.IsAdmin)
98+
showPrivate := ctx.IsLogged && (ctxUser.ID == ctx.User.ID || ctx.User.IsAdmin)
9999
ctx.Data["Repos"], err = models.GetUserRepositories(&models.UserRepoOptions{
100100
UserID: ctxUser.ID,
101101
Private: showPrivate,

0 commit comments

Comments
 (0)