Skip to content

Commit 2985b3e

Browse files
authored
Merge branch 'master' into test-more-lfs
2 parents 503ec29 + 1ed7f18 commit 2985b3e

File tree

12 files changed

+349
-22
lines changed

12 files changed

+349
-22
lines changed

integrations/api_admin_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2017 The Gitea 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 integrations
6+
7+
import (
8+
"fmt"
9+
"net/http"
10+
"testing"
11+
12+
"code.gitea.io/gitea/models"
13+
api "code.gitea.io/sdk/gitea"
14+
)
15+
16+
func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
17+
prepareTestEnv(t)
18+
// user1 is an admin user
19+
session := loginUser(t, "user1")
20+
keyOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
21+
22+
urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys", keyOwner.Name)
23+
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
24+
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n",
25+
"title": "test-key",
26+
})
27+
resp := session.MakeRequest(t, req, http.StatusCreated)
28+
29+
var newPublicKey api.PublicKey
30+
DecodeJSON(t, resp, &newPublicKey)
31+
models.AssertExistsAndLoadBean(t, &models.PublicKey{
32+
ID: newPublicKey.ID,
33+
Name: newPublicKey.Title,
34+
Content: newPublicKey.Key,
35+
Fingerprint: newPublicKey.Fingerprint,
36+
OwnerID: keyOwner.ID,
37+
})
38+
39+
req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d",
40+
keyOwner.Name, newPublicKey.ID)
41+
session.MakeRequest(t, req, http.StatusNoContent)
42+
models.AssertNotExistsBean(t, &models.PublicKey{ID: newPublicKey.ID})
43+
}
44+
45+
func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
46+
prepareTestEnv(t)
47+
// user1 is an admin user
48+
session := loginUser(t, "user1")
49+
50+
req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d", models.NonexistentID)
51+
session.MakeRequest(t, req, http.StatusNotFound)
52+
}
53+
54+
func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) {
55+
prepareTestEnv(t)
56+
adminUsername := "user1"
57+
normalUsername := "user2"
58+
session := loginUser(t, adminUsername)
59+
60+
urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys", adminUsername)
61+
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
62+
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n",
63+
"title": "test-key",
64+
})
65+
resp := session.MakeRequest(t, req, http.StatusCreated)
66+
var newPublicKey api.PublicKey
67+
DecodeJSON(t, resp, &newPublicKey)
68+
69+
session = loginUser(t, normalUsername)
70+
req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d",
71+
adminUsername, newPublicKey.ID)
72+
session.MakeRequest(t, req, http.StatusForbidden)
73+
}

integrations/links_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ func TestRedirectsNoLogin(t *testing.T) {
4646
prepareTestEnv(t)
4747

4848
var redirects = map[string]string{
49-
"/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
50-
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
49+
"/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
50+
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
51+
"/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
52+
"/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
5153
}
5254
for link, redirectLink := range redirects {
5355
req := NewRequest(t, "GET", link)

models/ssh_key.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,7 @@ func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
506506
func DeletePublicKey(doer *User, id int64) (err error) {
507507
key, err := GetPublicKeyByID(id)
508508
if err != nil {
509-
if IsErrKeyNotExist(err) {
510-
return nil
511-
}
512-
return fmt.Errorf("GetPublicKeyByID: %v", err)
509+
return err
513510
}
514511

515512
// Check if user has access to delete this key.

modules/context/repo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
618618

619619
if refType == RepoRefLegacy {
620620
// redirect from old URL scheme to new URL scheme
621-
ctx.Redirect(path.Join(setting.AppSubURL, strings.TrimSuffix(ctx.Req.URL.String(), ctx.Params("*")), ctx.Repo.BranchNameSubURL()))
621+
ctx.Redirect(path.Join(
622+
setting.AppSubURL,
623+
strings.TrimSuffix(ctx.Req.URL.String(), ctx.Params("*")),
624+
ctx.Repo.BranchNameSubURL(),
625+
ctx.Repo.TreePath))
622626
return
623627
}
624628
}

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ function initReactionSelector(parent) {
151151
react.remove();
152152
}
153153
if (!resp.empty) {
154-
react = $('<div class="ui attached segment reactions"></div>').appendTo(content);
154+
react = $('<div class="ui attached segment reactions"></div>');
155+
var attachments = content.find('.segment.bottom:first');
156+
if (attachments.length > 0) {
157+
react.insertBefore(attachments);
158+
} else {
159+
react.appendTo(content);
160+
}
155161
react.html(resp.html);
156162
var hasEmoji = react.find('.has-emoji');
157163
for (var i = 0; i < hasEmoji.length; i++) {

public/less/_base.less

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ pre, code {
152152
box-shadow: none;
153153
}
154154

155-
/* overide semantic selector '.ui.menu:not(.vertical) .item > .button' */
156-
.menu:not(.vertical) .item .button {
157-
padding-bottom: .78571429em;
158-
padding-top: .78571429em;
159-
font-size: 1em;
155+
/* Overide semantic selector '.ui.menu:not(.vertical) .item > .button' */
156+
/* This fixes the commit graph button on the commits page */
157+
.menu:not(.vertical) .item > .button.compact {
158+
padding: .58928571em 1.125em;
159+
}
160+
.menu:not(.vertical) .item > .button.small {
161+
font-size: .92857143rem;
160162
}
161163

162164
.text {

0 commit comments

Comments
 (0)