Merge branch 'master' of https://github.com/go-gitea/gitea
This commit is contained in:
commit
81dfd9e15e
|
|
@ -1,5 +1,6 @@
|
|||
FROM alpine:3.6
|
||||
MAINTAINER Thomas Boerger <thomas@webhippie.de>
|
||||
|
||||
LABEL maintainer="The Gitea Authors"
|
||||
|
||||
EXPOSE 22 3000
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
FROM multiarch/alpine:aarch64-v3.6
|
||||
|
||||
LABEL maintainer="The Gitea Authors"
|
||||
|
||||
EXPOSE 22 3000
|
||||
|
||||
RUN apk --no-cache add \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
FROM multiarch/alpine:armhf-v3.6
|
||||
MAINTAINER Thomas Boerger <thomas@webhippie.de>
|
||||
|
||||
LABEL maintainer="The Gitea Authors"
|
||||
|
||||
EXPOSE 22 3000
|
||||
|
||||
|
|
|
|||
|
|
@ -17,3 +17,4 @@ Antoine Girard <sapk@sapk.fr> (@sapk)
|
|||
Lauris Bukšis-Haberkorns <lauris@nix.lv> (@lafriks)
|
||||
Jonas Östanbäck <jonas.ostanback@gmail.com> (@cez81)
|
||||
David Schneiderbauer <dschneiderbauer@gmail.com> (@daviian)
|
||||
Peter Žeby <morlinest@gmail.com> (@morlinest)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ func TestAPIUserReposNotLogin(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAPISearchRepoNotLogin(t *testing.T) {
|
||||
func TestAPISearchRepo(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
const keyword = "test"
|
||||
|
||||
|
|
@ -46,6 +47,102 @@ func TestAPISearchRepoNotLogin(t *testing.T) {
|
|||
assert.Contains(t, repo.Name, keyword)
|
||||
assert.False(t, repo.Private)
|
||||
}
|
||||
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 15}).(*models.User)
|
||||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 16}).(*models.User)
|
||||
orgUser := models.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User)
|
||||
|
||||
// Map of expected results, where key is user for login
|
||||
type expectedResults map[*models.User]struct {
|
||||
count int
|
||||
repoOwnerID int64
|
||||
repoName string
|
||||
includesPrivate bool
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name, requestURL string
|
||||
expectedResults
|
||||
}{
|
||||
{name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50", expectedResults: expectedResults{
|
||||
nil: {count: 12},
|
||||
user: {count: 12},
|
||||
user2: {count: 12}},
|
||||
},
|
||||
{name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10}},
|
||||
},
|
||||
{name: "RepositoriesDefaultMax10", requestURL: "/api/v1/repos/search", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10}},
|
||||
},
|
||||
{name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s", "big_test_"), expectedResults: expectedResults{
|
||||
nil: {count: 4, repoName: "big_test_"},
|
||||
user: {count: 4, repoName: "big_test_"},
|
||||
user2: {count: 4, repoName: "big_test_"}},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{
|
||||
// FIXME: Should return 4 (all public repositories related to "another" user = owned + collaborative), now returns only public repositories directly owned by user
|
||||
nil: {count: 2},
|
||||
user: {count: 8, includesPrivate: true},
|
||||
// FIXME: Should return 4 (all public repositories related to "another" user = owned + collaborative), now returns only public repositories directly owned by user
|
||||
user2: {count: 2}},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 1},
|
||||
user2: {count: 2, includesPrivate: true}},
|
||||
},
|
||||
{name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1, repoOwnerID: orgUser.ID},
|
||||
user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true},
|
||||
user2: {count: 1, repoOwnerID: orgUser.ID}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
for userToLogin, expected := range testCase.expectedResults {
|
||||
var session *TestSession
|
||||
var testName string
|
||||
if userToLogin != nil && userToLogin.ID > 0 {
|
||||
testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID)
|
||||
session = loginUser(t, userToLogin.Name)
|
||||
} else {
|
||||
testName = "AnonymousUser"
|
||||
session = emptyTestSession(t)
|
||||
}
|
||||
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
request := NewRequest(t, "GET", testCase.requestURL)
|
||||
response := session.MakeRequest(t, request, http.StatusOK)
|
||||
|
||||
var body api.SearchResults
|
||||
DecodeJSON(t, response, &body)
|
||||
|
||||
assert.Len(t, body.Data, expected.count)
|
||||
for _, repo := range body.Data {
|
||||
assert.NotEmpty(t, repo.Name)
|
||||
|
||||
if len(expected.repoName) > 0 {
|
||||
assert.Contains(t, repo.Name, expected.repoName)
|
||||
}
|
||||
|
||||
if expected.repoOwnerID > 0 {
|
||||
assert.Equal(t, expected.repoOwnerID, repo.Owner.ID)
|
||||
}
|
||||
|
||||
if !expected.includesPrivate {
|
||||
assert.False(t, repo.Private)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIViewRepo(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func TestRenameRepoAction(t *testing.T) {
|
|||
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
|
||||
AssertExistsAndLoadBean(t, actionBean)
|
||||
|
||||
_, err := x.Id(repo.ID).Cols("name", "lower_name").Update(repo)
|
||||
_, err := x.ID(repo.ID).Cols("name", "lower_name").Update(repo)
|
||||
assert.NoError(t, err)
|
||||
CheckConsistencyFor(t, &Action{})
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ func TestTransferRepoAction(t *testing.T) {
|
|||
assert.NoError(t, TransferRepoAction(user2, user2, repo))
|
||||
AssertExistsAndLoadBean(t, actionBean)
|
||||
|
||||
_, err := x.Id(repo.ID).Cols("owner_id").Update(repo)
|
||||
_, err := x.ID(repo.ID).Cols("owner_id").Update(repo)
|
||||
assert.NoError(t, err)
|
||||
CheckConsistencyFor(t, &Action{})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func Notices(page, pageSize int) ([]*Notice, error) {
|
|||
|
||||
// DeleteNotice deletes a system notice by given ID.
|
||||
func DeleteNotice(id int64) error {
|
||||
_, err := x.Id(id).Delete(new(Notice))
|
||||
_, err := x.ID(id).Delete(new(Notice))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, white
|
|||
return nil
|
||||
}
|
||||
|
||||
if _, err = x.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
|
||||
if _, err = x.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func ListGPGKeys(uid int64) ([]*GPGKey, error) {
|
|||
// GetGPGKeyByID returns public key by given ID.
|
||||
func GetGPGKeyByID(keyID int64) (*GPGKey, error) {
|
||||
key := new(GPGKey)
|
||||
has, err := x.Id(keyID).Get(key)
|
||||
has, err := x.ID(keyID).Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -401,8 +401,9 @@ func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
|
|||
for _, k := range keys {
|
||||
//Pre-check (& optimization) that emails attached to key can be attached to the commiter email and can validate
|
||||
canValidate := false
|
||||
lowerCommiterEmail := strings.ToLower(c.Committer.Email)
|
||||
for _, e := range k.Emails {
|
||||
if e.IsActivated && e.Email == c.Committer.Email {
|
||||
if e.IsActivated && strings.ToLower(e.Email) == lowerCommiterEmail {
|
||||
canValidate = true
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ func (issue *Issue) ReadBy(userID int64) error {
|
|||
}
|
||||
|
||||
func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
|
||||
if _, err := e.Id(issue.ID).Cols(cols...).Update(issue); err != nil {
|
||||
if _, err := e.ID(issue.ID).Cols(cols...).Update(issue); err != nil {
|
||||
return err
|
||||
}
|
||||
UpdateIssueIndexer(issue.ID)
|
||||
|
|
@ -911,7 +911,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
|
|||
|
||||
for i := 0; i < len(attachments); i++ {
|
||||
attachments[i].IssueID = opts.Issue.ID
|
||||
if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1008,7 +1008,7 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
|
|||
|
||||
func getIssueByID(e Engine, id int64) (*Issue, error) {
|
||||
issue := new(Issue)
|
||||
has, err := e.Id(id).Get(issue)
|
||||
has, err := e.ID(id).Get(issue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -1435,7 +1435,7 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen
|
|||
}
|
||||
|
||||
func updateIssue(e Engine, issue *Issue) error {
|
||||
_, err := e.Id(issue.ID).AllCols().Update(issue)
|
||||
_, err := e.ID(issue.ID).AllCols().Update(issue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
attachments[i].IssueID = opts.Issue.ID
|
||||
attachments[i].CommentID = comment.ID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return nil, fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -619,7 +619,7 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
|
|||
// GetCommentByID returns the comment by given ID.
|
||||
func GetCommentByID(id int64) (*Comment, error) {
|
||||
c := new(Comment)
|
||||
has, err := x.Id(id).Get(c)
|
||||
has, err := x.ID(id).Get(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -697,7 +697,7 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
|
|||
|
||||
// UpdateComment updates information of comment.
|
||||
func UpdateComment(c *Comment) error {
|
||||
if _, err := x.Id(c.ID).AllCols().Update(c); err != nil {
|
||||
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
|
||||
return err
|
||||
} else if c.Type == CommentTypeComment {
|
||||
UpdateIssueIndexer(c.IssueID)
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@ func InitIssueIndexer() {
|
|||
func populateIssueIndexer() error {
|
||||
batch := indexer.IssueIndexerBatch()
|
||||
for page := 1; ; page++ {
|
||||
repos, _, err := Repositories(&SearchRepoOptions{
|
||||
repos, _, err := SearchRepositoryByName(&SearchRepoOptions{
|
||||
Page: page,
|
||||
PageSize: 10,
|
||||
OrderBy: SearchOrderByID,
|
||||
Private: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Repositories: %v", err)
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ func GetLabelsByIssueID(issueID int64) ([]*Label, error) {
|
|||
}
|
||||
|
||||
func updateLabel(e Engine, l *Label) error {
|
||||
_, err := e.Id(l.ID).AllCols().Update(l)
|
||||
_, err := e.ID(l.ID).AllCols().Update(l)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ func DeleteLabel(repoID, labelID int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Id(labelID).Delete(new(Label)); err != nil {
|
||||
if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
|
||||
return err
|
||||
} else if _, err = sess.
|
||||
Where("label_id = ?", labelID).
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*M
|
|||
}
|
||||
|
||||
func updateMilestone(e Engine, m *Milestone) error {
|
||||
_, err := e.Id(m.ID).AllCols().Update(m)
|
||||
_, err := e.ID(m.ID).AllCols().Update(m)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
|
|||
|
||||
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
|
||||
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
|
||||
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||
return err
|
||||
}
|
||||
return sess.Commit()
|
||||
|
|
@ -329,13 +329,13 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Id(m.ID).Delete(new(Milestone)); err != nil {
|
||||
if _, err = sess.ID(m.ID).Delete(new(Milestone)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
|
||||
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
|
||||
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func UpdateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {
|
|||
|
||||
iu.IsMentioned = true
|
||||
if has {
|
||||
_, err = e.Id(iu.ID).Cols("is_mentioned").Update(iu)
|
||||
_, err = e.ID(iu.ID).Cols("is_mentioned").Update(iu)
|
||||
} else {
|
||||
_, err = e.Insert(iu)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
|
|||
} else {
|
||||
iw.IsWatching = isWatching
|
||||
|
||||
if _, err := x.Id(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
|
||||
if _, err := x.ID(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ func LoginSources() ([]*LoginSource, error) {
|
|||
// GetLoginSourceByID returns login source by given ID.
|
||||
func GetLoginSourceByID(id int64) (*LoginSource, error) {
|
||||
source := new(LoginSource)
|
||||
has, err := x.Id(id).Get(source)
|
||||
has, err := x.ID(id).Get(source)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -328,7 +328,7 @@ func UpdateSource(source *LoginSource) error {
|
|||
}
|
||||
}
|
||||
|
||||
_, err := x.Id(source.ID).AllCols().Update(source)
|
||||
_, err := x.ID(source.ID).AllCols().Update(source)
|
||||
if err == nil && source.IsOAuth2() && source.IsActived {
|
||||
oAuth2Config := source.OAuth2()
|
||||
err = oauth2.RegisterProvider(source.Name, oAuth2Config.Provider, oAuth2Config.ClientID, oAuth2Config.ClientSecret, oAuth2Config.OpenIDConnectAutoDiscoveryURL, oAuth2Config.CustomURLMapping)
|
||||
|
|
@ -336,7 +336,7 @@ func UpdateSource(source *LoginSource) error {
|
|||
|
||||
if err != nil {
|
||||
// restore original values since we cannot update the provider it self
|
||||
x.Id(source.ID).AllCols().Update(originalLoginSource)
|
||||
x.ID(source.ID).AllCols().Update(originalLoginSource)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
@ -362,7 +362,7 @@ func DeleteSource(source *LoginSource) error {
|
|||
oauth2.RemoveProvider(source.Name)
|
||||
}
|
||||
|
||||
_, err = x.Id(source.ID).Delete(new(LoginSource))
|
||||
_, err = x.ID(source.ID).Delete(new(LoginSource))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -647,7 +647,7 @@ func UserSignIn(username, password string) (*User, error) {
|
|||
|
||||
default:
|
||||
var source LoginSource
|
||||
hasSource, err := x.Id(user.LoginSource).Get(&source)
|
||||
hasSource, err := x.ID(user.LoginSource).Get(&source)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !hasSource {
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
|
|||
if int(v-minDBVersion) > len(migrations) {
|
||||
// User downgraded Gitea.
|
||||
currentVersion.Version = int64(len(migrations) + minDBVersion)
|
||||
_, err = x.Id(1).Update(currentVersion)
|
||||
_, err = x.ID(1).Update(currentVersion)
|
||||
return err
|
||||
}
|
||||
for i, m := range migrations[v-minDBVersion:] {
|
||||
|
|
@ -184,7 +184,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
|
|||
return fmt.Errorf("do migrate: %v", err)
|
||||
}
|
||||
currentVersion.Version = v + int64(i) + 1
|
||||
if _, err = x.Id(1).Update(currentVersion); err != nil {
|
||||
if _, err = x.ID(1).Update(currentVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,21 +10,15 @@ import (
|
|||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// UserV15 describes the added field for User
|
||||
type UserV15 struct {
|
||||
KeepEmailPrivate bool
|
||||
AllowCreateOrganization bool
|
||||
}
|
||||
|
||||
// TableName will be invoked by XORM to customrize the table name
|
||||
func (*UserV15) TableName() string {
|
||||
return "user"
|
||||
}
|
||||
|
||||
func createAllowCreateOrganizationColumn(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(UserV15)); err != nil {
|
||||
type User struct {
|
||||
KeepEmailPrivate bool
|
||||
AllowCreateOrganization bool
|
||||
}
|
||||
|
||||
if err := x.Sync2(new(User)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
} else if _, err = x.Where("type=0").Cols("allow_create_organization").Update(&UserV15{AllowCreateOrganization: true}); err != nil {
|
||||
} else if _, err = x.Where("`type` = 0").Cols("allow_create_organization").Update(&User{AllowCreateOrganization: true}); err != nil {
|
||||
return fmt.Errorf("set allow_create_organization: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -13,17 +13,6 @@ import (
|
|||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config map[string]interface{} `xorm:"JSON"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Enumerate all the unit types
|
||||
const (
|
||||
V16UnitTypeCode = iota + 1 // 1 code
|
||||
|
|
@ -37,14 +26,25 @@ const (
|
|||
V16UnitTypeExternalTracker // 9 ExternalTracker
|
||||
)
|
||||
|
||||
// Repo describes a repository
|
||||
type Repo struct {
|
||||
ID int64
|
||||
EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
|
||||
ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
|
||||
}
|
||||
|
||||
func addUnitsToTables(x *xorm.Engine) error {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config map[string]interface{} `xorm:"JSON"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Repo describes a repository
|
||||
type Repo struct {
|
||||
ID int64
|
||||
EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
|
||||
ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
|
||||
}
|
||||
|
||||
var repos []Repo
|
||||
err := x.Table("repository").Select("*").Find(&repos)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func addRepoSize(x *xorm.Engine) (err error) {
|
|||
}
|
||||
|
||||
repo.Size = countObject.Size + countObject.SizePack
|
||||
if _, err = x.Id(repo.ID).Cols("size").Update(repo); err != nil {
|
||||
if _, err = x.ID(repo.ID).Cols("size").Update(repo); err != nil {
|
||||
return fmt.Errorf("update size: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,19 @@ package migrations
|
|||
import (
|
||||
"html"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func unescapeUserFullNames(x *xorm.Engine) (err error) {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
FullName string
|
||||
}
|
||||
|
||||
const batchSize = 100
|
||||
for start := 0; ; start += batchSize {
|
||||
users := make([]*models.User, 0, batchSize)
|
||||
if err := x.Limit(start, batchSize).Find(users); err != nil {
|
||||
users := make([]*User, 0, batchSize)
|
||||
if err := x.Limit(batchSize, start).Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
|
|
@ -24,7 +27,7 @@ func unescapeUserFullNames(x *xorm.Engine) (err error) {
|
|||
}
|
||||
for _, user := range users {
|
||||
user.FullName = html.UnescapeString(user.FullName)
|
||||
if _, err := x.Cols("full_name").Update(user); err != nil {
|
||||
if _, err := x.ID(user.ID).Cols("full_name").Update(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,26 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func removeCommitsUnitType(x *xorm.Engine) (err error) {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config core.Conversion `xorm:"TEXT"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Update team unit types
|
||||
const batchSize = 100
|
||||
for start := 0; ; start += batchSize {
|
||||
|
|
@ -33,7 +47,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
|
|||
}
|
||||
}
|
||||
team.UnitTypes = ut
|
||||
if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
|
||||
if _, err := x.ID(team.ID).Cols("unit_types").Update(team); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,26 +13,37 @@ import (
|
|||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// Stopwatch see models/issue_stopwatch.go
|
||||
type Stopwatch struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IssueID int64 `xorm:"INDEX"`
|
||||
UserID int64 `xorm:"INDEX"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64
|
||||
}
|
||||
|
||||
// TrackedTime see models/issue_tracked_time.go
|
||||
type TrackedTime struct {
|
||||
ID int64 `xorm:"pk autoincr" json:"id"`
|
||||
IssueID int64 `xorm:"INDEX" json:"issue_id"`
|
||||
UserID int64 `xorm:"INDEX" json:"user_id"`
|
||||
Created time.Time `xorm:"-" json:"created"`
|
||||
CreatedUnix int64 `json:"-"`
|
||||
Time int64 `json:"time"`
|
||||
}
|
||||
|
||||
func addTimetracking(x *xorm.Engine) error {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config map[string]interface{} `xorm:"JSON"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Stopwatch see models/issue_stopwatch.go
|
||||
type Stopwatch struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IssueID int64 `xorm:"INDEX"`
|
||||
UserID int64 `xorm:"INDEX"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64
|
||||
}
|
||||
|
||||
// TrackedTime see models/issue_tracked_time.go
|
||||
type TrackedTime struct {
|
||||
ID int64 `xorm:"pk autoincr" json:"id"`
|
||||
IssueID int64 `xorm:"INDEX" json:"issue_id"`
|
||||
UserID int64 `xorm:"INDEX" json:"user_id"`
|
||||
Created time.Time `xorm:"-" json:"created"`
|
||||
CreatedUnix int64 `json:"-"`
|
||||
Time int64 `json:"time"`
|
||||
}
|
||||
|
||||
if err := x.Sync2(new(Stopwatch)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
}
|
||||
|
|
@ -40,25 +51,23 @@ func addTimetracking(x *xorm.Engine) error {
|
|||
return fmt.Errorf("Sync2: %v", err)
|
||||
}
|
||||
//Updating existing issue units
|
||||
var units []*RepoUnit
|
||||
x.Where("type = ?", V16UnitTypeIssues).Find(&units)
|
||||
units := make([]*RepoUnit, 0, 100)
|
||||
err := x.Where("`type` = ?", V16UnitTypeIssues).Find(&units)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query repo units: %v", err)
|
||||
}
|
||||
for _, unit := range units {
|
||||
if unit.Config == nil {
|
||||
unit.Config = make(map[string]interface{})
|
||||
}
|
||||
changes := false
|
||||
if _, ok := unit.Config["EnableTimetracker"]; !ok {
|
||||
unit.Config["EnableTimetracker"] = setting.Service.DefaultEnableTimetracking
|
||||
changes = true
|
||||
}
|
||||
if _, ok := unit.Config["AllowOnlyContributorsToTrackTime"]; !ok {
|
||||
unit.Config["AllowOnlyContributorsToTrackTime"] = setting.Service.DefaultAllowOnlyContributorsToTrackTime
|
||||
changes = true
|
||||
}
|
||||
if changes {
|
||||
if _, err := x.Id(unit.ID).Cols("config").Update(unit); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ type Engine interface {
|
|||
Exec(string, ...interface{}) (sql.Result, error)
|
||||
Find(interface{}, ...interface{}) error
|
||||
Get(interface{}) (bool, error)
|
||||
Id(interface{}) *xorm.Session
|
||||
ID(interface{}) *xorm.Session
|
||||
In(string, ...interface{}) *xorm.Session
|
||||
Incr(column string, arg ...interface{}) *xorm.Session
|
||||
Insert(...interface{}) (int64, error)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ func updateIssueNotification(e Engine, userID, issueID, updatedByID int64) error
|
|||
notification.Status = NotificationStatusUnread
|
||||
notification.UpdatedBy = updatedByID
|
||||
|
||||
_, err = e.Id(notification.ID).Update(notification)
|
||||
_, err = e.ID(notification.ID).Update(notification)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ func setNotificationStatusReadIfUnread(e Engine, userID, issueID int64) error {
|
|||
|
||||
notification.Status = NotificationStatusRead
|
||||
|
||||
_, err = e.Id(notification.ID).Update(notification)
|
||||
_, err = e.ID(notification.ID).Update(notification)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ func SetNotificationStatus(notificationID int64, user *User, status Notification
|
|||
|
||||
notification.Status = status
|
||||
|
||||
_, err = x.Id(notificationID).Update(notification)
|
||||
_, err = x.ID(notificationID).Update(notification)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ func deleteOrg(e *xorm.Session, u *User) error {
|
|||
return fmt.Errorf("deleteBeans: %v", err)
|
||||
}
|
||||
|
||||
if _, err = e.Id(u.ID).Delete(new(User)); err != nil {
|
||||
if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -412,7 +412,7 @@ func ChangeOrgUserStatus(orgID, uid int64, public bool) error {
|
|||
}
|
||||
|
||||
ou.IsPublic = public
|
||||
_, err = x.Id(ou.ID).Cols("is_public").Update(ou)
|
||||
_, err = x.ID(ou.ID).Cols("is_public").Update(ou)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -480,7 +480,7 @@ func RemoveOrgUser(orgID, userID int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err := sess.Id(ou.ID).Delete(ou); err != nil {
|
||||
if _, err := sess.ID(ou.ID).Delete(ou); err != nil {
|
||||
return err
|
||||
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
|
|||
}
|
||||
|
||||
t.NumRepos++
|
||||
if _, err = e.Id(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
if _, err = e.ID(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
return fmt.Errorf("update team: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
|
|||
}
|
||||
|
||||
t.NumRepos--
|
||||
if _, err = e.Id(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
if _, err = e.ID(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ func NewTeam(t *Team) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
has, err := x.Id(t.OrgID).Get(new(User))
|
||||
has, err := x.ID(t.OrgID).Get(new(User))
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
|
|
@ -289,7 +289,7 @@ func GetTeam(orgID int64, name string) (*Team, error) {
|
|||
|
||||
func getTeamByID(e Engine, teamID int64) (*Team, error) {
|
||||
t := new(Team)
|
||||
has, err := e.Id(teamID).Get(t)
|
||||
has, err := e.ID(teamID).Get(t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -331,7 +331,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
|
|||
return ErrTeamAlreadyExist{t.OrgID, t.LowerName}
|
||||
}
|
||||
|
||||
if _, err = sess.Id(t.ID).AllCols().Update(t); err != nil {
|
||||
if _, err = sess.ID(t.ID).AllCols().Update(t); err != nil {
|
||||
return fmt.Errorf("update: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ func DeleteTeam(t *Team) error {
|
|||
}
|
||||
|
||||
// Delete team.
|
||||
if _, err := sess.Id(t.ID).Delete(new(Team)); err != nil {
|
||||
if _, err := sess.ID(t.ID).Delete(new(Team)); err != nil {
|
||||
return err
|
||||
}
|
||||
// Update organization number of teams.
|
||||
|
|
@ -498,7 +498,7 @@ func AddTeamMember(team *Team, userID int64) error {
|
|||
TeamID: team.ID,
|
||||
}); err != nil {
|
||||
return err
|
||||
} else if _, err := sess.Id(team.ID).Update(team); err != nil {
|
||||
} else if _, err := sess.ID(team.ID).Update(team); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -521,7 +521,7 @@ func AddTeamMember(team *Team, userID int64) error {
|
|||
if team.IsOwnerTeam() {
|
||||
ou.IsOwner = true
|
||||
}
|
||||
if _, err := sess.Id(ou.ID).Cols("num_teams, is_owner").Update(ou); err != nil {
|
||||
if _, err := sess.ID(ou.ID).Cols("num_teams, is_owner").Update(ou); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -551,7 +551,7 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
|
|||
}); err != nil {
|
||||
return err
|
||||
} else if _, err = e.
|
||||
Id(team.ID).
|
||||
ID(team.ID).
|
||||
Cols("num_members").
|
||||
Update(team); err != nil {
|
||||
return err
|
||||
|
|
@ -578,7 +578,7 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
|
|||
ou.IsOwner = false
|
||||
}
|
||||
if _, err = e.
|
||||
Id(ou.ID).
|
||||
ID(ou.ID).
|
||||
Cols("num_teams").
|
||||
Update(ou); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ func (pr *PullRequest) setMerged() (err error) {
|
|||
if err = pr.Issue.changeStatus(sess, pr.Merger, pr.Issue.Repo, true); err != nil {
|
||||
return fmt.Errorf("Issue.changeStatus: %v", err)
|
||||
}
|
||||
if _, err = sess.Id(pr.ID).Cols("has_merged").Update(pr); err != nil {
|
||||
if _, err = sess.ID(pr.ID).Cols("has_merged, status, merged_commit_id, merger_id, merged_unix").Update(pr); err != nil {
|
||||
return fmt.Errorf("update pull request: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -795,7 +795,7 @@ func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) {
|
|||
|
||||
func getPullRequestByID(e Engine, id int64) (*PullRequest, error) {
|
||||
pr := new(PullRequest)
|
||||
has, err := e.Id(id).Get(pr)
|
||||
has, err := e.ID(id).Get(pr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -829,13 +829,13 @@ func GetPullRequestByIssueID(issueID int64) (*PullRequest, error) {
|
|||
|
||||
// Update updates all fields of pull request.
|
||||
func (pr *PullRequest) Update() error {
|
||||
_, err := x.Id(pr.ID).AllCols().Update(pr)
|
||||
_, err := x.ID(pr.ID).AllCols().Update(pr)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateCols updates specific fields of pull request.
|
||||
func (pr *PullRequest) UpdateCols(cols ...string) error {
|
||||
_, err := x.Id(pr.ID).Cols(cols...).Update(pr)
|
||||
_, err := x.ID(pr.ID).Cols(cols...).Update(pr)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ func addReleaseAttachments(releaseID int64, attachmentUUIDs []string) (err error
|
|||
for i := range attachments {
|
||||
attachments[i].ReleaseID = releaseID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = x.Id(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
if _, err = x.ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ func GetRelease(repoID int64, tagName string) (*Release, error) {
|
|||
func GetReleaseByID(id int64) (*Release, error) {
|
||||
rel := new(Release)
|
||||
has, err := x.
|
||||
Id(id).
|
||||
ID(id).
|
||||
Get(rel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -365,7 +365,7 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []stri
|
|||
}
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
|
||||
_, err = x.Id(rel.ID).AllCols().Update(rel)
|
||||
_, err = x.ID(rel.ID).AllCols().Update(rel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
|||
return fmt.Errorf("git tag -d: %v - %s", err, stderr)
|
||||
}
|
||||
|
||||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil {
|
||||
if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
} else {
|
||||
|
|
@ -412,7 +412,7 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
|||
rel.Title = ""
|
||||
rel.Note = ""
|
||||
|
||||
if _, err = x.Id(rel.ID).AllCols().Update(rel); err != nil {
|
||||
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -621,7 +621,7 @@ func (repo *Repository) updateSize(e Engine) error {
|
|||
}
|
||||
|
||||
repo.Size = repoInfoSize.Size + repoInfoSize.SizePack
|
||||
_, err = e.Id(repo.ID).Cols("size").Update(repo)
|
||||
_, err = e.ID(repo.ID).Cols("size").Update(repo)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -1428,7 +1428,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
|
|||
repo.Owner = newOwner
|
||||
|
||||
// Update repository.
|
||||
if _, err := sess.Id(repo.ID).Update(repo); err != nil {
|
||||
if _, err := sess.ID(repo.ID).Update(repo); err != nil {
|
||||
return fmt.Errorf("update owner: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -1460,7 +1460,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
|
|||
}
|
||||
|
||||
t.NumRepos--
|
||||
if _, err := sess.Id(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
if _, err := sess.ID(t.ID).Cols("num_repos").Update(t); err != nil {
|
||||
return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1579,7 +1579,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
|
|||
repo.Website = repo.Website[:255]
|
||||
}
|
||||
|
||||
if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
|
||||
if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
|
||||
return fmt.Errorf("update: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -1698,7 +1698,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||
return ErrRepoNotExist{repoID, uid, ""}
|
||||
}
|
||||
|
||||
if cnt, err := sess.Id(repoID).Delete(&Repository{}); err != nil {
|
||||
if cnt, err := sess.ID(repoID).Delete(&Repository{}); err != nil {
|
||||
return err
|
||||
} else if cnt != 1 {
|
||||
return ErrRepoNotExist{repoID, uid, ""}
|
||||
|
|
@ -1879,7 +1879,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
|
|||
|
||||
func getRepositoryByID(e Engine, id int64) (*Repository, error) {
|
||||
repo := new(Repository)
|
||||
has, err := e.Id(id).Get(repo)
|
||||
has, err := e.ID(id).Get(repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ type SearchRepoOptions struct {
|
|||
Starred bool `json:"-"`
|
||||
Page int `json:"-"`
|
||||
IsProfile bool `json:"-"`
|
||||
AllPublic bool `json:"-"` // Include also all public repositories
|
||||
// Limit of result
|
||||
//
|
||||
// maximum: setting.ExplorePagingNum
|
||||
|
|
@ -129,6 +130,8 @@ const (
|
|||
SearchOrderByNewest = "created_unix DESC"
|
||||
SearchOrderBySize = "size ASC"
|
||||
SearchOrderBySizeReverse = "size DESC"
|
||||
SearchOrderByID = "id ASC"
|
||||
SearchOrderByIDReverse = "id DESC"
|
||||
)
|
||||
|
||||
// SearchRepositoryByName takes keyword and part of repository name to search,
|
||||
|
|
@ -147,11 +150,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
|||
starJoin = true
|
||||
}
|
||||
|
||||
opts.Keyword = strings.ToLower(opts.Keyword)
|
||||
if opts.Keyword != "" {
|
||||
cond = cond.And(builder.Like{"lower_name", opts.Keyword})
|
||||
}
|
||||
|
||||
// Append conditions
|
||||
if !opts.Starred && opts.OwnerID > 0 {
|
||||
var searcherReposCond builder.Cond = builder.Eq{"owner_id": opts.OwnerID}
|
||||
|
|
@ -182,6 +180,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
|||
cond = cond.And(builder.Eq{"is_private": false})
|
||||
}
|
||||
|
||||
if opts.OwnerID > 0 && opts.AllPublic {
|
||||
cond = cond.Or(builder.Eq{"is_private": false})
|
||||
}
|
||||
|
||||
opts.Keyword = strings.ToLower(opts.Keyword)
|
||||
if opts.Keyword != "" {
|
||||
cond = cond.And(builder.Like{"lower_name", opts.Keyword})
|
||||
}
|
||||
|
||||
if len(opts.OrderBy) == 0 {
|
||||
opts.OrderBy = SearchOrderByAlphabetically
|
||||
}
|
||||
|
|
@ -225,78 +232,3 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
// Repositories returns all repositories
|
||||
func Repositories(opts *SearchRepoOptions) (_ RepositoryList, count int64, err error) {
|
||||
if len(opts.OrderBy) == 0 {
|
||||
opts.OrderBy = "id ASC"
|
||||
}
|
||||
|
||||
repos := make(RepositoryList, 0, opts.PageSize)
|
||||
|
||||
if err = x.
|
||||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
|
||||
OrderBy(opts.OrderBy.String()).
|
||||
Find(&repos); err != nil {
|
||||
return nil, 0, fmt.Errorf("Repo: %v", err)
|
||||
}
|
||||
|
||||
if err = repos.loadAttributes(x); err != nil {
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
|
||||
}
|
||||
|
||||
count = countRepositories(-1, opts.Private)
|
||||
|
||||
return repos, count, nil
|
||||
}
|
||||
|
||||
// GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
|
||||
func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList, _ int64, _ error) {
|
||||
var cond = builder.NewCond()
|
||||
|
||||
if len(opts.OrderBy) == 0 {
|
||||
opts.OrderBy = SearchOrderByRecentUpdated
|
||||
}
|
||||
|
||||
if !opts.Private {
|
||||
cond = builder.Eq{
|
||||
"is_private": false,
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Searcher != nil && !opts.Searcher.IsAdmin {
|
||||
var ownerIds []int64
|
||||
|
||||
ownerIds = append(ownerIds, opts.Searcher.ID)
|
||||
err := opts.Searcher.GetOrganizations(true)
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Organization: %v", err)
|
||||
}
|
||||
|
||||
for _, org := range opts.Searcher.Orgs {
|
||||
ownerIds = append(ownerIds, org.ID)
|
||||
}
|
||||
|
||||
cond = cond.Or(builder.In("owner_id", ownerIds))
|
||||
}
|
||||
|
||||
count, err := x.Where(cond).Count(new(Repository))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
}
|
||||
|
||||
if err = x.Where(cond).
|
||||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
|
||||
Limit(opts.PageSize).
|
||||
OrderBy(opts.OrderBy.String()).
|
||||
Find(&repos); err != nil {
|
||||
return nil, 0, fmt.Errorf("Repo: %v", err)
|
||||
}
|
||||
|
||||
if err = repos.loadAttributes(x); err != nil {
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
|
||||
}
|
||||
|
||||
return repos, count, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,8 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
Keyword: "repo_12",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, repos, 1) {
|
||||
assert.Equal(t, "test_repo_12", repos[0].Name)
|
||||
|
|
@ -32,12 +30,11 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
Keyword: "test_repo",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
assert.Len(t, repos, 2)
|
||||
|
||||
// test search private repository on explore page
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
|
|
@ -48,7 +45,6 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, repos, 1) {
|
||||
assert.Equal(t, "test_repo_13", repos[0].Name)
|
||||
|
|
@ -63,7 +59,99 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(3), count)
|
||||
assert.Len(t, repos, 3)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
opts *SearchRepoOptions
|
||||
count int
|
||||
}{
|
||||
{name: "PublicRepositoriesByName",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", PageSize: 10},
|
||||
count: 4},
|
||||
{name: "PublicAndPrivateRepositoriesByName",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 1, PageSize: 10, Private: true},
|
||||
count: 8},
|
||||
{name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 1, PageSize: 5, Private: true},
|
||||
count: 8},
|
||||
{name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 2, PageSize: 5, Private: true},
|
||||
count: 8},
|
||||
{name: "PublicRepositoriesOfUser",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15},
|
||||
count: 3}, // FIXME: Should return 2 (only directly owned repositories), now includes 1 public repository from owned organization
|
||||
{name: "PublicAndPrivateRepositoriesOfUser",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true},
|
||||
count: 6}, // FIXME: Should return 4 (only directly owned repositories), now includes 2 repositories from owned organization
|
||||
{name: "PublicRepositoriesOfUserIncludingCollaborative",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Collaborate: true},
|
||||
count: 4},
|
||||
{name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true},
|
||||
count: 8},
|
||||
{name: "PublicRepositoriesOfOrganization",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17},
|
||||
count: 1},
|
||||
{name: "PublicAndPrivateRepositoriesOfOrganization",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17, Private: true},
|
||||
count: 2},
|
||||
{name: "AllPublic/PublicRepositoriesByName",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", PageSize: 10, AllPublic: true},
|
||||
count: 4},
|
||||
{name: "AllPublic/PublicAndPrivateRepositoriesByName",
|
||||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 1, PageSize: 10, Private: true, AllPublic: true},
|
||||
count: 8},
|
||||
{name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Collaborate: true, AllPublic: true},
|
||||
count: 12},
|
||||
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true, AllPublic: true},
|
||||
count: 16},
|
||||
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
|
||||
opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true, AllPublic: true},
|
||||
count: 10},
|
||||
{name: "AllPublic/PublicRepositoriesOfOrganization",
|
||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17, AllPublic: true},
|
||||
count: 12},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
if testCase.opts.OwnerID > 0 {
|
||||
testCase.opts.Searcher = &User{ID: testCase.opts.OwnerID}
|
||||
}
|
||||
repos, count, err := SearchRepositoryByName(testCase.opts)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(testCase.count), count)
|
||||
|
||||
var expectedLen int
|
||||
if testCase.opts.PageSize*testCase.opts.Page > testCase.count {
|
||||
expectedLen = testCase.count % testCase.opts.PageSize
|
||||
} else {
|
||||
expectedLen = testCase.opts.PageSize
|
||||
}
|
||||
assert.Len(t, repos, expectedLen)
|
||||
|
||||
for _, repo := range repos {
|
||||
assert.NotEmpty(t, repo.Name)
|
||||
|
||||
if len(testCase.opts.Keyword) > 0 {
|
||||
assert.Contains(t, repo.Name, testCase.opts.Keyword)
|
||||
}
|
||||
|
||||
// FIXME: Can't check, need to fix current behaviour (see previous FIXME comments in test cases)
|
||||
/*if testCase.opts.OwnerID > 0 && !testCase.opts.Collaborate && !AllPublic {
|
||||
assert.Equal(t, testCase.opts.OwnerID, repo.Owner.ID)
|
||||
}*/
|
||||
|
||||
if !testCase.opts.Private {
|
||||
assert.False(t, repo.IsPrivate)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ func GetMirrorByRepoID(repoID int64) (*Mirror, error) {
|
|||
}
|
||||
|
||||
func updateMirror(e Engine, m *Mirror) error {
|
||||
_, err := e.Id(m.ID).AllCols().Update(m)
|
||||
_, err := e.ID(m.ID).AllCols().Update(m)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -722,7 +722,7 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) {
|
|||
// GetDeployKeyByID returns deploy key by given ID.
|
||||
func GetDeployKeyByID(id int64) (*DeployKey, error) {
|
||||
key := new(DeployKey)
|
||||
has, err := x.Id(id).Get(key)
|
||||
has, err := x.ID(id).Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
@ -748,7 +748,7 @@ func GetDeployKeyByRepo(keyID, repoID int64) (*DeployKey, error) {
|
|||
|
||||
// UpdateDeployKey updates deploy key information.
|
||||
func UpdateDeployKey(key *DeployKey) error {
|
||||
_, err := x.Id(key.ID).AllCols().Update(key)
|
||||
_, err := x.ID(key.ID).AllCols().Update(key)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -782,7 +782,7 @@ func DeleteDeployKey(doer *User, id int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Id(key.ID).Delete(new(DeployKey)); err != nil {
|
||||
if _, err = sess.ID(key.ID).Delete(new(DeployKey)); err != nil {
|
||||
return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ func ListAccessTokens(uid int64) ([]*AccessToken, error) {
|
|||
|
||||
// UpdateAccessToken updates information of access token.
|
||||
func UpdateAccessToken(t *AccessToken) error {
|
||||
_, err := x.Id(t.ID).AllCols().Update(t)
|
||||
_, err := x.ID(t.ID).AllCols().Update(t)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteAccessTokenByID deletes access token by given ID.
|
||||
func DeleteAccessTokenByID(id, userID int64) error {
|
||||
cnt, err := x.Id(id).Delete(&AccessToken{
|
||||
cnt, err := x.ID(id).Delete(&AccessToken{
|
||||
UID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func NewTwoFactor(t *TwoFactor) error {
|
|||
|
||||
// UpdateTwoFactor updates a two-factor authentication token.
|
||||
func UpdateTwoFactor(t *TwoFactor) error {
|
||||
_, err := x.Id(t.ID).AllCols().Update(t)
|
||||
_, err := x.ID(t.ID).AllCols().Update(t)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ func GetTwoFactorByUID(uid int64) (*TwoFactor, error) {
|
|||
|
||||
// DeleteTwoFactorByID deletes two-factor authentication token by given ID.
|
||||
func DeleteTwoFactorByID(id, userID int64) error {
|
||||
cnt, err := x.Id(id).Delete(&TwoFactor{
|
||||
cnt, err := x.ID(id).Delete(&TwoFactor{
|
||||
UID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -90,14 +90,14 @@ func pushUpdateDeleteTag(repo *Repository, gitRepo *git.Repository, tagName stri
|
|||
return fmt.Errorf("GetRelease: %v", err)
|
||||
}
|
||||
if rel.IsTag {
|
||||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil {
|
||||
if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
} else {
|
||||
rel.IsDraft = true
|
||||
rel.NumCommits = 0
|
||||
rel.Sha1 = ""
|
||||
if _, err = x.Id(rel.ID).AllCols().Update(rel); err != nil {
|
||||
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string)
|
|||
if rel.IsTag && author != nil {
|
||||
rel.PublisherID = author.ID
|
||||
}
|
||||
if _, err = x.Id(rel.ID).AllCols().Update(rel); err != nil {
|
||||
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ func (u *User) generateRandomAvatar(e Engine) error {
|
|||
}
|
||||
defer fw.Close()
|
||||
|
||||
if _, err := e.Id(u.ID).Cols("avatar").Update(u); err != nil {
|
||||
if _, err := e.ID(u.ID).Cols("avatar").Update(u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ func (u *User) DeleteAvatar() error {
|
|||
|
||||
u.UseCustomAvatar = false
|
||||
u.Avatar = ""
|
||||
if _, err := x.Id(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
|
||||
if _, err := x.ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
|
||||
return fmt.Errorf("UpdateUser: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -862,7 +862,7 @@ func updateUser(e Engine, u *User) error {
|
|||
u.Website = base.TruncateString(u.Website, 255)
|
||||
u.Description = base.TruncateString(u.Description, 255)
|
||||
|
||||
_, err := e.Id(u.ID).AllCols().Update(u)
|
||||
_, err := e.ID(u.ID).AllCols().Update(u)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -893,7 +893,7 @@ func updateUserCols(e Engine, u *User, cols ...string) error {
|
|||
u.Website = base.TruncateString(u.Website, 255)
|
||||
u.Description = base.TruncateString(u.Description, 255)
|
||||
|
||||
_, err := e.Id(u.ID).Cols(cols...).Update(u)
|
||||
_, err := e.ID(u.ID).Cols(cols...).Update(u)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -1019,7 +1019,7 @@ func deleteUser(e *xorm.Session, u *User) error {
|
|||
}
|
||||
// ***** END: ExternalLoginUser *****
|
||||
|
||||
if _, err = e.Id(u.ID).Delete(new(User)); err != nil {
|
||||
if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -1112,7 +1112,7 @@ func GetUserByKeyID(keyID int64) (*User, error) {
|
|||
|
||||
func getUserByID(e Engine, id int64) (*User, error) {
|
||||
u := new(User)
|
||||
has, err := e.Id(id).Get(u)
|
||||
has, err := e.ID(id).Get(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ func DeleteEmailAddress(email *EmailAddress) (err error) {
|
|||
UID: email.UID,
|
||||
}
|
||||
if email.ID > 0 {
|
||||
deleted, err = x.Id(email.ID).Delete(&address)
|
||||
deleted, err = x.ID(email.ID).Delete(&address)
|
||||
} else {
|
||||
deleted, err = x.
|
||||
Where("email=?", email.Email).
|
||||
|
|
@ -222,7 +222,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
|
|||
}
|
||||
|
||||
user.Email = email.Email
|
||||
if _, err = sess.Id(user.ID).Cols("email").Update(user); err != nil {
|
||||
if _, err = sess.ID(user.ID).Cols("email").Update(user); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func DeleteUserOpenID(openid *UserOpenID) (err error) {
|
|||
UID: openid.UID,
|
||||
}
|
||||
if openid.ID > 0 {
|
||||
deleted, err = x.Id(openid.ID).Delete(&address)
|
||||
deleted, err = x.ID(openid.ID).Delete(&address)
|
||||
} else {
|
||||
deleted, err = x.
|
||||
Where("openid=?", openid.URI).
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
|
|||
|
||||
// UpdateWebhook updates information of webhook.
|
||||
func UpdateWebhook(w *Webhook) error {
|
||||
_, err := x.Id(w.ID).AllCols().Update(w)
|
||||
_, err := x.ID(w.ID).AllCols().Update(w)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -477,7 +477,7 @@ func createHookTask(e Engine, t *HookTask) error {
|
|||
|
||||
// UpdateHookTask updates information of hook task.
|
||||
func UpdateHookTask(t *HookTask) error {
|
||||
_, err := x.Id(t.ID).AllCols().Update(t)
|
||||
_, err := x.ID(t.ID).AllCols().Update(t)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,13 +174,54 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
|
|||
ctx.Redirect(redirectPath)
|
||||
}
|
||||
|
||||
// RepoIDAssignment returns an macaron handler which assigns the repo to the context.
|
||||
func repoAssignment(ctx *Context, repo *models.Repository) {
|
||||
// Admin has super access.
|
||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
||||
ctx.Repo.AccessMode = models.AccessModeOwner
|
||||
} else {
|
||||
var userID int64
|
||||
if ctx.User != nil {
|
||||
userID = ctx.User.ID
|
||||
}
|
||||
mode, err := models.AccessLevel(userID, repo)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "AccessLevel", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.AccessMode = mode
|
||||
}
|
||||
|
||||
// Check access.
|
||||
if ctx.Repo.AccessMode == models.AccessModeNone {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
EarlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
}
|
||||
ctx.Handle(404, "no access right", nil)
|
||||
return
|
||||
}
|
||||
ctx.Data["HasAccess"] = true
|
||||
|
||||
if repo.IsMirror {
|
||||
var err error
|
||||
ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetMirror", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
|
||||
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
|
||||
ctx.Data["Mirror"] = ctx.Repo.Mirror
|
||||
}
|
||||
|
||||
ctx.Repo.Repository = repo
|
||||
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
|
||||
}
|
||||
|
||||
// RepoIDAssignment returns a macaron handler which assigns the repo to the context.
|
||||
func RepoIDAssignment() macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
repoID := ctx.ParamsInt64(":repoid")
|
||||
|
||||
// Get repository.
|
||||
|
|
@ -198,48 +239,7 @@ func RepoIDAssignment() macaron.Handler {
|
|||
ctx.Handle(500, "GetOwner", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Admin has super access.
|
||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
||||
ctx.Repo.AccessMode = models.AccessModeOwner
|
||||
} else {
|
||||
var userID int64
|
||||
if ctx.User != nil {
|
||||
userID = ctx.User.ID
|
||||
}
|
||||
mode, err := models.AccessLevel(userID, repo)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "AccessLevel", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.AccessMode = mode
|
||||
}
|
||||
|
||||
// Check access.
|
||||
if ctx.Repo.AccessMode == models.AccessModeNone {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
EarlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
}
|
||||
ctx.Handle(404, "no access right", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["HasAccess"] = true
|
||||
|
||||
if repo.IsMirror {
|
||||
ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetMirror", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
|
||||
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
|
||||
ctx.Data["Mirror"] = ctx.Repo.Mirror
|
||||
}
|
||||
|
||||
ctx.Repo.Repository = repo
|
||||
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
|
||||
repoAssignment(ctx, repo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -298,47 +298,10 @@ func RepoAssignment() macaron.Handler {
|
|||
}
|
||||
repo.Owner = owner
|
||||
|
||||
// Admin has super access.
|
||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
||||
ctx.Repo.AccessMode = models.AccessModeOwner
|
||||
} else {
|
||||
var userID int64
|
||||
if ctx.User != nil {
|
||||
userID = ctx.User.ID
|
||||
}
|
||||
mode, err := models.AccessLevel(userID, repo)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "AccessLevel", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.AccessMode = mode
|
||||
}
|
||||
|
||||
// Check access.
|
||||
if ctx.Repo.AccessMode == models.AccessModeNone {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
EarlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
}
|
||||
ctx.Handle(404, "no access right", err)
|
||||
repoAssignment(ctx, repo)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
ctx.Data["HasAccess"] = true
|
||||
|
||||
if repo.IsMirror {
|
||||
ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetMirror", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
|
||||
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
|
||||
ctx.Data["Mirror"] = ctx.Repo.Mirror
|
||||
}
|
||||
|
||||
ctx.Repo.Repository = repo
|
||||
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
|
||||
|
||||
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ func Repos(ctx *context.Context) {
|
|||
ctx.Data["PageIsAdminRepositories"] = true
|
||||
|
||||
routers.RenderRepoSearch(ctx, &routers.RepoSearchOptions{
|
||||
Ranger: models.Repositories,
|
||||
Private: true,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
TplName: tplRepos,
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ func Swagger(ctx *context.Context) {
|
|||
|
||||
// RepoSearchOptions when calling search repositories
|
||||
type RepoSearchOptions struct {
|
||||
Ranger func(*models.SearchRepoOptions) (models.RepositoryList, int64, error)
|
||||
Searcher *models.User
|
||||
OwnerID int64
|
||||
Private bool
|
||||
PageSize int
|
||||
TplName base.TplName
|
||||
|
|
@ -88,9 +87,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
|||
err error
|
||||
orderBy models.SearchOrderBy
|
||||
)
|
||||
ctx.Data["SortType"] = ctx.Query("sort")
|
||||
|
||||
ctx.Data["SortType"] = ctx.Query("sort")
|
||||
switch ctx.Query("sort") {
|
||||
case "newest":
|
||||
orderBy = models.SearchOrderByNewest
|
||||
case "oldest":
|
||||
orderBy = models.SearchOrderByOldest
|
||||
case "recentupdate":
|
||||
|
|
@ -106,39 +107,26 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
|||
case "size":
|
||||
orderBy = models.SearchOrderBySize
|
||||
default:
|
||||
orderBy = models.SearchOrderByNewest
|
||||
ctx.Data["SortType"] = "recentupdate"
|
||||
orderBy = models.SearchOrderByRecentUpdated
|
||||
}
|
||||
|
||||
keyword := strings.Trim(ctx.Query("q"), " ")
|
||||
if len(keyword) == 0 {
|
||||
repos, count, err = opts.Ranger(&models.SearchRepoOptions{
|
||||
Page: page,
|
||||
PageSize: opts.PageSize,
|
||||
Searcher: ctx.User,
|
||||
OrderBy: orderBy,
|
||||
Private: opts.Private,
|
||||
Collaborate: true,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "opts.Ranger", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if isKeywordValid(keyword) {
|
||||
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||||
Keyword: keyword,
|
||||
OrderBy: orderBy,
|
||||
Private: opts.Private,
|
||||
Page: page,
|
||||
PageSize: opts.PageSize,
|
||||
Searcher: ctx.User,
|
||||
Collaborate: true,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||||
Page: page,
|
||||
PageSize: opts.PageSize,
|
||||
OrderBy: orderBy,
|
||||
Private: opts.Private,
|
||||
Keyword: keyword,
|
||||
OwnerID: opts.OwnerID,
|
||||
Searcher: ctx.User,
|
||||
Collaborate: true,
|
||||
AllPublic: true,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Total"] = count
|
||||
|
|
@ -154,11 +142,15 @@ func ExploreRepos(ctx *context.Context) {
|
|||
ctx.Data["PageIsExplore"] = true
|
||||
ctx.Data["PageIsExploreRepositories"] = true
|
||||
|
||||
var ownerID int64
|
||||
if ctx.User != nil && !ctx.User.IsAdmin {
|
||||
ownerID = ctx.User.ID
|
||||
}
|
||||
|
||||
RenderRepoSearch(ctx, &RepoSearchOptions{
|
||||
Ranger: models.GetRecentUpdatedRepositories,
|
||||
PageSize: setting.UI.ExplorePagingNum,
|
||||
Searcher: ctx.User,
|
||||
Private: ctx.User != nil && ctx.User.IsAdmin,
|
||||
OwnerID: ownerID,
|
||||
Private: ctx.User != nil,
|
||||
TplName: tplExploreRepos,
|
||||
})
|
||||
}
|
||||
|
|
@ -188,6 +180,8 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
|
|||
|
||||
ctx.Data["SortType"] = ctx.Query("sort")
|
||||
switch ctx.Query("sort") {
|
||||
case "newest":
|
||||
orderBy = "id DESC"
|
||||
case "oldest":
|
||||
orderBy = "id ASC"
|
||||
case "recentupdate":
|
||||
|
|
@ -199,7 +193,8 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
|
|||
case "alphabetically":
|
||||
orderBy = "name ASC"
|
||||
default:
|
||||
orderBy = "id DESC"
|
||||
ctx.Data["SortType"] = "alphabetically"
|
||||
orderBy = "name ASC"
|
||||
}
|
||||
|
||||
keyword := strings.Trim(ctx.Query("q"), " ")
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
|
|||
}
|
||||
|
||||
// GogsHooksNewPost response for creating webhook
|
||||
func GogsHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
|
||||
func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["PageIsSettingsHooksNew"] = true
|
||||
|
|
@ -420,7 +420,7 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
|
|||
}
|
||||
|
||||
// GogsHooksEditPost response for editing gogs hook
|
||||
func GogsHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
|
||||
func GogsHooksEditPost(ctx *context.Context, form auth.NewGogshookForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["PageIsSettingsHooksEdit"] = true
|
||||
|
|
|
|||
|
|
@ -126,12 +126,7 @@ func Profile(ctx *context.Context) {
|
|||
orderBy = models.SearchOrderByAlphabetically
|
||||
default:
|
||||
ctx.Data["SortType"] = "recentupdate"
|
||||
orderBy = models.SearchOrderByNewest
|
||||
}
|
||||
|
||||
// set default sort value if sort is empty.
|
||||
if ctx.Query("sort") == "" {
|
||||
ctx.Data["SortType"] = "recentupdate"
|
||||
orderBy = models.SearchOrderByRecentUpdated
|
||||
}
|
||||
|
||||
keyword := strings.Trim(ctx.Query("q"), " ")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<i class="dropdown icon"></i>
|
||||
</span>
|
||||
<div class="menu">
|
||||
<a class="{{if or (eq .SortType "newest") (not .SortType)}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
|
||||
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
|
||||
<a class="{{if eq .SortType "oldest"}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
|
||||
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
|
||||
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user