mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
#13 finish user and repository search
Both are possible on explore and admin panel
This commit is contained in:
parent
df2bdf7ea3
commit
2bf8494332
31 changed files with 636 additions and 463 deletions
|
@ -27,7 +27,7 @@ func CreateOrg(ctx *context.Context, form api.CreateOrgOption) {
|
|||
Website: form.Website,
|
||||
Location: form.Location,
|
||||
IsActive: true,
|
||||
Type: models.ORGANIZATION,
|
||||
Type: models.USER_TYPE_ORGANIZATION,
|
||||
}
|
||||
if err := models.CreateOrganization(org, u); err != nil {
|
||||
if models.IsErrUserAlreadyExist(err) ||
|
||||
|
|
|
@ -21,21 +21,21 @@ import (
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
func Search(ctx *context.Context) {
|
||||
opt := models.SearchOption{
|
||||
Keyword: path.Base(ctx.Query("q")),
|
||||
Uid: com.StrTo(ctx.Query("uid")).MustInt64(),
|
||||
Limit: com.StrTo(ctx.Query("limit")).MustInt(),
|
||||
opts := &models.SearchRepoOptions{
|
||||
Keyword: path.Base(ctx.Query("q")),
|
||||
OwnerID: com.StrTo(ctx.Query("uid")).MustInt64(),
|
||||
PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
|
||||
}
|
||||
if opt.Limit == 0 {
|
||||
opt.Limit = 10
|
||||
if opts.PageSize == 0 {
|
||||
opts.PageSize = 10
|
||||
}
|
||||
|
||||
// Check visibility.
|
||||
if ctx.IsSigned && opt.Uid > 0 {
|
||||
if ctx.User.Id == opt.Uid {
|
||||
opt.Private = true
|
||||
if ctx.IsSigned && opts.OwnerID > 0 {
|
||||
if ctx.User.Id == opts.OwnerID {
|
||||
opts.Private = true
|
||||
} else {
|
||||
u, err := models.GetUserByID(opt.Uid)
|
||||
u, err := models.GetUserByID(opts.OwnerID)
|
||||
if err != nil {
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
|
@ -44,13 +44,13 @@ func Search(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
if u.IsOrganization() && u.IsOwnedBy(ctx.User.Id) {
|
||||
opt.Private = true
|
||||
opts.Private = true
|
||||
}
|
||||
// FIXME: how about collaborators?
|
||||
}
|
||||
}
|
||||
|
||||
repos, err := models.SearchRepositoryByName(opt)
|
||||
repos, _, err := models.SearchRepositoryByName(opts)
|
||||
if err != nil {
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
|
|
|
@ -15,15 +15,16 @@ import (
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users#search-users
|
||||
func Search(ctx *context.Context) {
|
||||
opt := models.SearchOption{
|
||||
Keyword: ctx.Query("q"),
|
||||
Limit: com.StrTo(ctx.Query("limit")).MustInt(),
|
||||
opts := &models.SearchUserOptions{
|
||||
Keyword: ctx.Query("q"),
|
||||
Type: models.USER_TYPE_INDIVIDUAL,
|
||||
PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
|
||||
}
|
||||
if opt.Limit == 0 {
|
||||
opt.Limit = 10
|
||||
if opts.PageSize == 0 {
|
||||
opts.PageSize = 10
|
||||
}
|
||||
|
||||
us, err := models.SearchUserByName(opt)
|
||||
users, _, err := models.SearchUserByName(opts)
|
||||
if err != nil {
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
|
@ -32,16 +33,16 @@ func Search(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
results := make([]*api.User, len(us))
|
||||
for i := range us {
|
||||
results := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
results[i] = &api.User{
|
||||
ID: us[i].Id,
|
||||
UserName: us[i].Name,
|
||||
AvatarUrl: us[i].AvatarLink(),
|
||||
FullName: us[i].FullName,
|
||||
ID: users[i].Id,
|
||||
UserName: users[i].Name,
|
||||
AvatarUrl: users[i].AvatarLink(),
|
||||
FullName: users[i].FullName,
|
||||
}
|
||||
if ctx.IsSigned {
|
||||
results[i].Email = us[i].Email
|
||||
results[i].Email = users[i].Email
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue