diff --git a/cmd/web.go b/cmd/web.go index 000525a33..a810e44cd 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -304,6 +304,10 @@ func runWeb(c *cli.Context) error { m.Get("/stars", user.Stars) }) + m.Group("/:username/labels", func() { + m.Get("/:labelID", user.Profile) + }) + m.Get("/attachments/:uuid", func(c *context.Context) { attach, err := models.GetAttachmentByUUID(c.Params(":uuid")) if err != nil { diff --git a/models/repo.go b/models/repo.go index 94b2f96f0..811c54c5e 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1595,6 +1595,7 @@ func GetRepositoryByID(id int64) (*Repository, error) { type UserRepoOptions struct { UserID int64 Private bool + LabelID int64 Page int PageSize int } @@ -1605,6 +1606,9 @@ func GetUserRepositories(opts *UserRepoOptions) ([]*Repository, error) { if !opts.Private { sess.And("is_private=?", false) } + if opts.LabelID != 0 { + sess.Join("INNER", "repository_repo_label", "repository_repo_label.repository_id=repository.id AND repository_repo_label.label_id=?", opts.LabelID) + } if opts.Page <= 0 { opts.Page = 1 @@ -1665,10 +1669,16 @@ func (l *RepositoryLabel) ForegroundColor() template.CSS { return template.CSS("#000") } -func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) { - if !owner.CanCreateRepo() { - return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()} +func (l *RepositoryLabel) GetOwner() *User { + if l.Owner == nil { + if owner, err := GetUserByID(l.OwnerID); err == nil { + l.Owner = owner + } } + return l.Owner +} + +func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) { if !labelColorPattern.MatchString(opts.Color) { return nil, fmt.Errorf("bad HTML color code %s", opts.Color) } @@ -1695,9 +1705,6 @@ func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *Reposi } func UpdateRepositoryLabel(id int64, owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) { - if !owner.CanCreateRepo() { - return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()} - } if !labelColorPattern.MatchString(opts.Color) { return nil, fmt.Errorf("bad HTML color code %s", opts.Color) } diff --git a/routes/user/profile.go b/routes/user/profile.go index f3ac35308..37c043994 100644 --- a/routes/user/profile.go +++ b/routes/user/profile.go @@ -95,11 +95,20 @@ func Profile(c *context.Context) { page = 1 } + labelID := c.ParamsInt64(":labelID") showPrivate := c.IsLogged && (ctxUser.ID == c.User.ID || c.User.IsAdmin) + if labelID != 0 { + label, err := models.GetRepositoryLabelById(labelID) + if err != nil || (label.IsPrivate && !showPrivate) { + c.NotFound() + return + } + } repositories, err := models.GetUserRepositories(&models.UserRepoOptions{ UserID: ctxUser.ID, Private: showPrivate, Page: page, + LabelID: labelID, PageSize: setting.UI.User.RepoPagingNum, }) if err != nil { diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 69d21058c..aaaf77d56 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -17,8 +17,8 @@
- {{range index $.LabelsByRepoId .ID}} - {{.Name}} + {{$currentOwner:=.Owner}}{{range index $.LabelsByRepoId .ID}} + {{.Name}} {{end}}
{{if .Description}}

{{.Description | Str2html}}

{{end}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index c6657b1ef..631a44a07 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -46,7 +46,7 @@
{{range $.RepositoryLabels}} -
{{.Name}}
+ {{.Name}} {{end}}