mirror of
https://github.com/gogs/gogs.git
synced 2026-05-07 16:45:30 +02:00
internal: move packages under this directory (#5836)
* Rename pkg -> internal * Rename routes -> route * Move route -> internal/route * Rename models -> db * Move db -> internal/db * Fix route2 -> route * Move cmd -> internal/cmd * Bump version
This commit is contained in:
17
internal/route/api/v1/admin/org.go
Normal file
17
internal/route/api/v1/admin/org.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
api "github.com/gogs/go-gogs-client"
|
||||
org2 "gogs.io/gogs/internal/route/api/v1/org"
|
||||
user2 "gogs.io/gogs/internal/route/api/v1/user"
|
||||
|
||||
"gogs.io/gogs/internal/context"
|
||||
)
|
||||
|
||||
func CreateOrg(c *context.APIContext, form api.CreateOrgOption) {
|
||||
org2.CreateOrgForUser(c, form, user2.GetUserByParams(c))
|
||||
}
|
||||
46
internal/route/api/v1/admin/org_repo.go
Normal file
46
internal/route/api/v1/admin/org_repo.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"gogs.io/gogs/internal/context"
|
||||
"gogs.io/gogs/internal/db"
|
||||
"gogs.io/gogs/internal/db/errors"
|
||||
)
|
||||
|
||||
func GetRepositoryByParams(c *context.APIContext) *db.Repository {
|
||||
repo, err := db.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
|
||||
if err != nil {
|
||||
c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
||||
return nil
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
func AddTeamRepository(c *context.APIContext) {
|
||||
repo := GetRepositoryByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
if err := c.Org.Team.AddRepository(repo); err != nil {
|
||||
c.ServerError("AddRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.NoContent()
|
||||
}
|
||||
|
||||
func RemoveTeamRepository(c *context.APIContext) {
|
||||
repo := GetRepositoryByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
|
||||
c.ServerError("RemoveRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.NoContent()
|
||||
}
|
||||
62
internal/route/api/v1/admin/org_team.go
Normal file
62
internal/route/api/v1/admin/org_team.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
convert2 "gogs.io/gogs/internal/route/api/v1/convert"
|
||||
user2 "gogs.io/gogs/internal/route/api/v1/user"
|
||||
"net/http"
|
||||
|
||||
api "github.com/gogs/go-gogs-client"
|
||||
|
||||
"gogs.io/gogs/internal/context"
|
||||
"gogs.io/gogs/internal/db"
|
||||
)
|
||||
|
||||
func CreateTeam(c *context.APIContext, form api.CreateTeamOption) {
|
||||
team := &db.Team{
|
||||
OrgID: c.Org.Organization.ID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
Authorize: db.ParseAccessMode(form.Permission),
|
||||
}
|
||||
if err := db.NewTeam(team); err != nil {
|
||||
if db.IsErrTeamAlreadyExist(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("NewTeam", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, convert2.ToTeam(team))
|
||||
}
|
||||
|
||||
func AddTeamMember(c *context.APIContext) {
|
||||
u := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
if err := c.Org.Team.AddMember(u.ID); err != nil {
|
||||
c.ServerError("AddMember", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.NoContent()
|
||||
}
|
||||
|
||||
func RemoveTeamMember(c *context.APIContext) {
|
||||
u := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.Org.Team.RemoveMember(u.ID); err != nil {
|
||||
c.ServerError("RemoveMember", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.NoContent()
|
||||
}
|
||||
22
internal/route/api/v1/admin/repo.go
Normal file
22
internal/route/api/v1/admin/repo.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
api "github.com/gogs/go-gogs-client"
|
||||
repo2 "gogs.io/gogs/internal/route/api/v1/repo"
|
||||
user2 "gogs.io/gogs/internal/route/api/v1/user"
|
||||
|
||||
"gogs.io/gogs/internal/context"
|
||||
)
|
||||
|
||||
func CreateRepo(c *context.APIContext, form api.CreateRepoOption) {
|
||||
owner := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
repo2.CreateUserRepo(c, owner, form)
|
||||
}
|
||||
159
internal/route/api/v1/admin/user.go
Normal file
159
internal/route/api/v1/admin/user.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
user2 "gogs.io/gogs/internal/route/api/v1/user"
|
||||
"net/http"
|
||||
|
||||
log "gopkg.in/clog.v1"
|
||||
|
||||
api "github.com/gogs/go-gogs-client"
|
||||
|
||||
"gogs.io/gogs/internal/context"
|
||||
"gogs.io/gogs/internal/db"
|
||||
"gogs.io/gogs/internal/db/errors"
|
||||
"gogs.io/gogs/internal/mailer"
|
||||
"gogs.io/gogs/internal/setting"
|
||||
)
|
||||
|
||||
func parseLoginSource(c *context.APIContext, u *db.User, sourceID int64, loginName string) {
|
||||
if sourceID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
source, err := db.GetLoginSourceByID(sourceID)
|
||||
if err != nil {
|
||||
if errors.IsLoginSourceNotExist(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("GetLoginSourceByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
u.LoginType = source.Type
|
||||
u.LoginSource = source.ID
|
||||
u.LoginName = loginName
|
||||
}
|
||||
|
||||
func CreateUser(c *context.APIContext, form api.CreateUserOption) {
|
||||
u := &db.User{
|
||||
Name: form.Username,
|
||||
FullName: form.FullName,
|
||||
Email: form.Email,
|
||||
Passwd: form.Password,
|
||||
IsActive: true,
|
||||
LoginType: db.LOGIN_PLAIN,
|
||||
}
|
||||
|
||||
parseLoginSource(c, u, form.SourceID, form.LoginName)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := db.CreateUser(u); err != nil {
|
||||
if db.IsErrUserAlreadyExist(err) ||
|
||||
db.IsErrEmailAlreadyUsed(err) ||
|
||||
db.IsErrNameReserved(err) ||
|
||||
db.IsErrNamePatternNotAllowed(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("CreateUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("Account created by admin %q: %s", c.User.Name, u.Name)
|
||||
|
||||
// Send email notification.
|
||||
if form.SendNotify && setting.MailService != nil {
|
||||
mailer.SendRegisterNotifyMail(c.Context.Context, db.NewMailerUser(u))
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, u.APIFormat())
|
||||
}
|
||||
|
||||
func EditUser(c *context.APIContext, form api.EditUserOption) {
|
||||
u := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
parseLoginSource(c, u, form.SourceID, form.LoginName)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if len(form.Password) > 0 {
|
||||
u.Passwd = form.Password
|
||||
var err error
|
||||
if u.Salt, err = db.GetUserSalt(); err != nil {
|
||||
c.ServerError("GetUserSalt", err)
|
||||
return
|
||||
}
|
||||
u.EncodePasswd()
|
||||
}
|
||||
|
||||
u.LoginName = form.LoginName
|
||||
u.FullName = form.FullName
|
||||
u.Email = form.Email
|
||||
u.Website = form.Website
|
||||
u.Location = form.Location
|
||||
if form.Active != nil {
|
||||
u.IsActive = *form.Active
|
||||
}
|
||||
if form.Admin != nil {
|
||||
u.IsAdmin = *form.Admin
|
||||
}
|
||||
if form.AllowGitHook != nil {
|
||||
u.AllowGitHook = *form.AllowGitHook
|
||||
}
|
||||
if form.AllowImportLocal != nil {
|
||||
u.AllowImportLocal = *form.AllowImportLocal
|
||||
}
|
||||
if form.MaxRepoCreation != nil {
|
||||
u.MaxRepoCreation = *form.MaxRepoCreation
|
||||
}
|
||||
|
||||
if err := db.UpdateUser(u); err != nil {
|
||||
if db.IsErrEmailAlreadyUsed(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("UpdateUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("Account profile updated by admin %q: %s", c.User.Name, u.Name)
|
||||
|
||||
c.JSONSuccess(u.APIFormat())
|
||||
}
|
||||
|
||||
func DeleteUser(c *context.APIContext) {
|
||||
u := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := db.DeleteUser(u); err != nil {
|
||||
if db.IsErrUserOwnRepos(err) ||
|
||||
db.IsErrUserHasOrgs(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("DeleteUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("Account deleted by admin(%s): %s", c.User.Name, u.Name)
|
||||
|
||||
c.NoContent()
|
||||
}
|
||||
|
||||
func CreatePublicKey(c *context.APIContext, form api.CreateKeyOption) {
|
||||
u := user2.GetUserByParams(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
user2.CreateUserPublicKey(c, form, u.ID)
|
||||
}
|
||||
Reference in New Issue
Block a user