Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/gsap-3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
techknowlogick authored Jan 21, 2021
2 parents 35817dc + b5570d3 commit 900ee64
Show file tree
Hide file tree
Showing 20 changed files with 329 additions and 28 deletions.
18 changes: 11 additions & 7 deletions docs/content/doc/installation/with-docker.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,23 @@ ports:
- "127.0.0.1:2222:22"
```

In addition, `/home/git/.ssh/authorized_keys` on the host needs to be modified. It needs to act in the same way as `authorized_keys` within the Gitea container. Therefore add
In addition, `/home/git/.ssh/authorized_keys` on the host needs to be modified. It needs to act in the same way as `authorized_keys` within the Gitea container. Therefore add the public key of the key you created above ("Gitea Host Key") to `~/git/.ssh/authorized_keys`.
This can be done via `echo "$(cat /home/git/.ssh/id_rsa.pub)" >> /home/git/.ssh/authorized_keys`.
Important: The pubkey from the `git` user needs to be added "as is" while all other pubkeys added via the Gitea web interface will be prefixed with `command="/app [...]`.

```bash
command="/app/gitea/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa <YOUR_SSH_PUBKEY>
```
The file should then look somewhat like

and replace `<YOUR_SSH_PUBKEY>` with a valid SSH public key of yours.
```bash
# SSH pubkey from git user
ssh-rsa <Gitea Host Key>

In addition the public key of the `git` user on the host needs to be added to `/home/git/.ssh/authorized_keys` so authentication against the container can succeed: `echo "$(cat /home/git/.ssh/id_rsa.pub)" >> /home/git/.ssh/authorized_keys`.
# other keys from users
command="/app/gitea/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <user pubkey>
```

Here is a detailed explanation what is happening when a SSH request is made:

1. A SSH request is made against the host using the `git` user, e.g. `git clone git@domain:user/repo.git`.
1. A SSH request is made against the host (usually port 22) using the `git` user, e.g. `git clone git@domain:user/repo.git`.
2. In `/home/git/.ssh/authorized_keys` , the command executes the `/app/gitea/gitea` script.
3. `/app/gitea/gitea` forwards the SSH request to port 2222 which is mapped to the SSH port (22) of the container.
4. Due to the existence of the public key of the `git` user in `/home/git/.ssh/authorized_keys` the authentication host → container succeeds and the SSH request get forwarded to Gitea running in the docker container.
Expand Down
14 changes: 5 additions & 9 deletions integrations/api_issue_stopwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package integrations
import (
"net/http"
"testing"
"time"

"code.gitea.io/gitea/models"
api "code.gitea.io/gitea/modules/structs"
Expand All @@ -31,14 +30,11 @@ func TestAPIListStopWatches(t *testing.T) {
issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: stopwatch.IssueID}).(*models.Issue)
if assert.Len(t, apiWatches, 1) {
assert.EqualValues(t, stopwatch.CreatedUnix.AsTime().Unix(), apiWatches[0].Created.Unix())
apiWatches[0].Created = time.Time{}
assert.EqualValues(t, api.StopWatch{
Created: time.Time{},
IssueIndex: issue.Index,
IssueTitle: issue.Title,
RepoName: repo.Name,
RepoOwnerName: repo.OwnerName,
}, *apiWatches[0])
assert.EqualValues(t, issue.Index, apiWatches[0].IssueIndex)
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
assert.Greater(t, int64(apiWatches[0].Seconds), int64(0))
}
}

Expand Down
2 changes: 1 addition & 1 deletion integrations/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestCreateIssueAttachment(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)

link, exists := htmlDoc.doc.Find("form").Attr("action")
link, exists := htmlDoc.doc.Find("form#new-issue").Attr("action")
assert.True(t, exists, "The template has changed")

postData := map[string]string{
Expand Down
10 changes: 10 additions & 0 deletions models/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ type Stopwatch struct {
CreatedUnix timeutil.TimeStamp `xorm:"created"`
}

// Seconds returns the amount of time passed since creation, based on local server time
func (s Stopwatch) Seconds() int64 {
return int64(timeutil.TimeStampNow() - s.CreatedUnix)
}

// Duration returns a human-readable duration string based on local server time
func (s Stopwatch) Duration() string {
return SecToTime(s.Seconds())
}

func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
sw = new(Stopwatch)
exists, err = e.
Expand Down
2 changes: 2 additions & 0 deletions modules/convert/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) {

result = append(result, api.StopWatch{
Created: sw.CreatedUnix.AsTime(),
Seconds: sw.Seconds(),
Duration: sw.Duration(),
IssueIndex: issue.Index,
IssueTitle: issue.Title,
RepoOwnerName: repo.OwnerName,
Expand Down
2 changes: 2 additions & 0 deletions modules/structs/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
type StopWatch struct {
// swagger:strfmt date-time
Created time.Time `json:"created"`
Seconds int64 `json:"seconds"`
Duration string `json:"duration"`
IssueIndex int64 `json:"issue_index"`
IssueTitle string `json:"issue_title"`
RepoOwnerName string `json:"repo_owner_name"`
Expand Down
11 changes: 7 additions & 4 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ page = Page
template = Template
language = Language
notifications = Notifications
active_stopwatch = Active Time Tracker
create_new = Create…
user_profile_and_more = Profile and Settings…
signed_in_as = Signed in as
Expand Down Expand Up @@ -1068,6 +1069,7 @@ issues.commented_at = `commented <a href="#%s">%s</a>`
issues.delete_comment_confirm = Are you sure you want to delete this comment?
issues.context.copy_link = Copy Link
issues.context.quote_reply = Quote Reply
issues.context.reference_issue = Reference in new issue
issues.context.edit = Edit
issues.context.delete = Delete
issues.no_content = There is no content yet.
Expand Down Expand Up @@ -1138,13 +1140,15 @@ issues.lock.title = Lock conversation on this issue.
issues.unlock.title = Unlock conversation on this issue.
issues.comment_on_locked = You cannot comment on a locked issue.
issues.tracker = Time Tracker
issues.start_tracking_short = Start
issues.start_tracking_short = Start Timer
issues.start_tracking = Start Time Tracking
issues.start_tracking_history = `started working %s`
issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed
issues.tracking_already_started = `You have already started time tracking on <a href="%s">another issue</a>!`
issues.stop_tracking = Stop
issues.stop_tracking = Stop Timer
issues.stop_tracking_history = `stopped working %s`
issues.cancel_tracking = Discard
issues.cancel_tracking_history = `cancelled time tracking %s`
issues.add_time = Manually Add Time
issues.add_time_short = Add Time
issues.add_time_cancel = Cancel
Expand All @@ -1153,8 +1157,6 @@ issues.del_time_history= `deleted spent time %s`
issues.add_time_hours = Hours
issues.add_time_minutes = Minutes
issues.add_time_sum_to_small = No time was entered.
issues.cancel_tracking = Cancel
issues.cancel_tracking_history = `cancelled time tracking %s`
issues.time_spent_total = Total Time Spent
issues.time_spent_from_all_authors = `Total Time Spent: %s`
issues.due_date = Due Date
Expand Down Expand Up @@ -1225,6 +1227,7 @@ issues.review.resolve_conversation = Resolve conversation
issues.review.un_resolve_conversation = Unresolve conversation
issues.review.resolved_by = marked this conversation as resolved
issues.assignee.error = Not all assignees was added due to an unexpected error.
issues.reference_issue.body = Body

pulls.desc = Enable pull requests and code reviews.
pulls.new = New Pull Request
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"monaco-editor": "0.21.2",
"monaco-editor-webpack-plugin": "2.1.0",
"postcss": "8.2.1",
"pretty-ms": "7.0.1",
"raw-loader": "4.0.2",
"sortablejs": "1.12.0",
"swagger-ui-dist": "3.38.0",
Expand Down
45 changes: 45 additions & 0 deletions routers/repo/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package repo

import (
"net/http"
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
Expand Down Expand Up @@ -61,3 +62,47 @@ func CancelStopwatch(c *context.Context) {
url := issue.HTMLURL()
c.Redirect(url, http.StatusSeeOther)
}

// GetActiveStopwatch is the middleware that sets .ActiveStopwatch on context
func GetActiveStopwatch(c *context.Context) {
if strings.HasPrefix(c.Req.URL.Path, "/api") {
return
}

if !c.IsSigned {
return
}

_, sw, err := models.HasUserStopwatch(c.User.ID)
if err != nil {
c.ServerError("HasUserStopwatch", err)
return
}

if sw == nil || sw.ID == 0 {
return
}

issue, err := models.GetIssueByID(sw.IssueID)
if err != nil || issue == nil {
c.ServerError("GetIssueByID", err)
return
}
if err = issue.LoadRepo(); err != nil {
c.ServerError("LoadRepo", err)
return
}

c.Data["ActiveStopwatch"] = StopwatchTmplInfo{
issue.Repo.FullName(),
issue.Index,
sw.Seconds() + 1, // ensure time is never zero in ui
}
}

// StopwatchTmplInfo is a view on a stopwatch specifically for template rendering
type StopwatchTmplInfo struct {
RepoSlug string
IssueIndex int64
Seconds int64
}
1 change: 1 addition & 0 deletions routers/routes/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
}

m.Use(user.GetNotificationCount)
m.Use(repo.GetActiveStopwatch)
m.Use(func(ctx *context.Context) {
ctx.Data["UnitWikiGlobalDisabled"] = models.UnitTypeWiki.UnitGlobalDisabled()
ctx.Data["UnitIssuesGlobalDisabled"] = models.UnitTypeIssues.UnitGlobalDisabled()
Expand Down
38 changes: 38 additions & 0 deletions templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,44 @@
</div>
{{else if .IsSigned}}
<div class="right stackable menu">
{{$issueURL := Printf "%s/%s/issues/%d" AppSubUrl .ActiveStopwatch.RepoSlug .ActiveStopwatch.IssueIndex}}
<a class="active-stopwatch-trigger item ui label {{if not .ActiveStopwatch}}hidden{{end}}" href="{{$issueURL}}">
<span class="text">
<span class="fitted item">
{{svg "octicon-stopwatch"}}
<span class="red" style="position:absolute; right:-0.6em; top:-0.6em;">{{svg "octicon-dot-fill"}}</span>
</span>
<span class="sr-mobile-only">{{.i18n.Tr "active_stopwatch"}}</span>
</span>
</a>
<div class="ui popup very wide">
<div class="df ac">
<a class="stopwatch-link df ac" href="{{$issueURL}}">
{{svg "octicon-issue-opened"}}
<span class="stopwatch-issue">{{.ActiveStopwatch.RepoSlug}}#{{.ActiveStopwatch.IssueIndex}}</span>
<span class="ui label blue stopwatch-time my-0 mx-4" data-seconds="{{.ActiveStopwatch.Seconds}}">
{{if .ActiveStopwatch}}{{Sec2Time .ActiveStopwatch.Seconds}}{{end}}
</span>
</a>
<form class="stopwatch-commit" method="POST" action="{{$issueURL}}/times/stopwatch/toggle">
{{.CsrfTokenHtml}}
<button
class="ui button mini compact basic icon fitted poping up"
data-content="{{.i18n.Tr "repo.issues.stop_tracking"}}"
data-position="top right" data-variation="small inverted"
>{{svg "octicon-square-fill"}}</button>
</form>
<form class="stopwatch-cancel" method="POST" action="{{$issueURL}}/times/stopwatch/cancel">
{{.CsrfTokenHtml}}
<button
class="ui button mini compact basic icon fitted poping up"
data-content="{{.i18n.Tr "repo.issues.cancel_tracking"}}"
data-position="top right" data-variation="small inverted"
>{{svg "octicon-trashcan"}}</button>
</form>
</div>
</div>

<a href="{{AppSubUrl}}/notifications" class="item poping up" data-content='{{.i18n.Tr "notifications"}}' data-variation="tiny inverted">
<span class="text">
<span class="fitted">{{svg "octicon-bell"}}</span>
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
</div>
{{end}}

{{template "repo/issue/view_content/reference_issue_dialog" .}}

{{if .IsSplitStyle}}
<script>
document.addEventListener('DOMContentLoaded', () => {
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form class="ui comment form stackable grid" action="{{.Link}}" method="post">
<form class="ui comment form stackable grid" id="new-issue" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
{{if .Flash}}
<div class="sixteen wide column">
Expand Down
4 changes: 3 additions & 1 deletion templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
{{end}}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}}
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "diff" false "IsCommentPoster" $.IsIssuePoster}}
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "issue" true "diff" false "IsCommentPoster" $.IsIssuePoster}}
{{end}}
</div>
</div>
Expand Down Expand Up @@ -210,6 +210,8 @@
</div>
</div>

{{template "repo/issue/view_content/reference_issue_dialog" .}}

<div class="hide" id="no-content">
<span class="no-content">{{.i18n.Tr "repo.issues.no_content"}}</span>
</div>
Expand Down
13 changes: 8 additions & 5 deletions templates/repo/issue/view_content/context_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
{{svg "octicon-kebab-horizontal"}}
</a>
<div class="menu">
{{if .issue}}
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
{{else}}
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
{{end}}
{{ $referenceUrl := "" }}
{{ if .issue }}
{{ $referenceUrl = Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
{{ else }}
{{ $referenceUrl = Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
{{ end }}
<div class="item context clipboard" data-clipboard-text="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
<div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div>
<div class="item context reference-issue" data-target="{{.item.ID}}" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-reference="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.reference_issue"}}</div>
{{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}}
<div class="divider"></div>
<div class="item context edit-content">{{.ctx.i18n.Tr "repo.issues.context.edit"}}</div>
Expand Down
30 changes: 30 additions & 0 deletions templates/repo/issue/view_content/reference_issue_dialog.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="ui small modal" id="reference-issue-modal">
<div class="header">
{{.i18n.Tr "repo.issues.context.reference_issue"}}
</div>
<div class="content" style="text-align:left">
<form class="ui form" action="{{ Printf "%s/issues/new" .Repository.Link }}" method="post">
{{.CsrfTokenHtml}}
<div class="ui segment content">
<div class="field">
<span class="text"><strong>{{.i18n.Tr "repository"}}</strong></span>
<div class="ui search normal selection dropdown issue_reference_repository_search">
<div class="default text">{{.Repository.FullName}}</div>
<div class="menu"></div>
</div>
</div>
<div class="field">
<span class="text"><strong>{{.i18n.Tr "repo.milestones.title"}}</strong></span>
<input name="title" value="" autofocus required maxlength="255" autocomplete="off">
</div>
<div class="field">
<span class="text"><strong>{{.i18n.Tr "repo.issues.reference_issue.body"}}</strong></span>
<textarea name="content" class="form-control"></textarea>
</div>
<div class="text right">
<button class="ui green button">{{.i18n.Tr "repo.issues.create"}}</button>
</div>
</div>
</form>
</div>
</div>
Loading

0 comments on commit 900ee64

Please sign in to comment.