mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge remote-tracking branch 'upstream/master' into team-grant-all-repos
# Conflicts: # models/migrations/migrations.go # models/migrations/v90.go # models/repo.go
This commit is contained in:
@@ -5,10 +5,9 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@@ -7,11 +7,11 @@ package org
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||
|
||||
apiMembers := make([]*api.User, len(members))
|
||||
for i, member := range members {
|
||||
apiMembers[i] = member.APIFormat()
|
||||
apiMembers[i] = convert.ToUser(member, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
}
|
||||
ctx.JSON(200, apiMembers)
|
||||
}
|
||||
|
||||
+10
-10
@@ -6,10 +6,9 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
@@ -96,14 +95,15 @@ func Create(ctx *context.APIContext, form api.CreateOrgOption) {
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
Name: form.UserName,
|
||||
FullName: form.FullName,
|
||||
Description: form.Description,
|
||||
Website: form.Website,
|
||||
Location: form.Location,
|
||||
IsActive: true,
|
||||
Type: models.UserTypeOrganization,
|
||||
Visibility: visibility,
|
||||
Name: form.UserName,
|
||||
FullName: form.FullName,
|
||||
Description: form.Description,
|
||||
Website: form.Website,
|
||||
Location: form.Location,
|
||||
IsActive: true,
|
||||
Type: models.UserTypeOrganization,
|
||||
Visibility: visibility,
|
||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||
}
|
||||
if err := models.CreateOrganization(org, ctx.User); err != nil {
|
||||
if models.IsErrUserAlreadyExist(err) ||
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
@@ -259,7 +261,7 @@ func GetTeamMembers(ctx *context.APIContext) {
|
||||
}
|
||||
members := make([]*api.User, len(team.Members))
|
||||
for i, member := range team.Members {
|
||||
members[i] = member.APIFormat()
|
||||
members[i] = convert.ToUser(member, ctx.IsSigned, ctx.User.IsAdmin)
|
||||
}
|
||||
ctx.JSON(200, members)
|
||||
}
|
||||
@@ -290,7 +292,16 @@ func GetTeamMember(ctx *context.APIContext) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, u.APIFormat())
|
||||
teamID := ctx.ParamsInt64("teamid")
|
||||
isTeamMember, err := models.IsUserInTeams(u.ID, []int64{teamID})
|
||||
if err != nil {
|
||||
ctx.Error(500, "IsUserInTeams", err)
|
||||
return
|
||||
} else if !isTeamMember {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
|
||||
}
|
||||
|
||||
// AddTeamMember api for add a member to a team
|
||||
@@ -498,3 +509,83 @@ func RemoveTeamRepository(ctx *context.APIContext) {
|
||||
}
|
||||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// SearchTeam api for searching teams
|
||||
func SearchTeam(ctx *context.APIContext) {
|
||||
// swagger:operation GET /orgs/{org}/teams/search organization teamSearch
|
||||
// ---
|
||||
// summary: Search for teams within an organization
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: org
|
||||
// in: path
|
||||
// description: name of the organization
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: q
|
||||
// in: query
|
||||
// description: keywords to search
|
||||
// type: string
|
||||
// - name: include_desc
|
||||
// in: query
|
||||
// description: include search within team description (defaults to true)
|
||||
// type: boolean
|
||||
// - name: limit
|
||||
// in: query
|
||||
// description: limit size of results
|
||||
// type: integer
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// description: "SearchResults of a successful search"
|
||||
// schema:
|
||||
// type: object
|
||||
// properties:
|
||||
// ok:
|
||||
// type: boolean
|
||||
// data:
|
||||
// type: array
|
||||
// items:
|
||||
// "$ref": "#/definitions/Team"
|
||||
opts := &models.SearchTeamOptions{
|
||||
UserID: ctx.User.ID,
|
||||
Keyword: strings.TrimSpace(ctx.Query("q")),
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")),
|
||||
PageSize: ctx.QueryInt("limit"),
|
||||
Page: ctx.QueryInt("page"),
|
||||
}
|
||||
|
||||
teams, _, err := models.SearchTeam(opts)
|
||||
if err != nil {
|
||||
log.Error("SearchTeam failed: %v", err)
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "SearchTeam internal failure",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
apiTeams := make([]*api.Team, len(teams))
|
||||
for i := range teams {
|
||||
if err := teams[i].GetUnits(); err != nil {
|
||||
log.Error("Team GetUnits failed: %v", err)
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "SearchTeam failed to get units",
|
||||
})
|
||||
return
|
||||
}
|
||||
apiTeams[i] = convert.ToTeam(teams[i])
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"ok": true,
|
||||
"data": apiTeams,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user