mirror of
https://github.com/go-gitea/gitea
synced 2024-11-24 17:12:59 +01:00
Add delete repo
This commit is contained in:
parent
18ba149137
commit
27104ac89a
10 changed files with 34 additions and 18 deletions
2
gogs.go
2
gogs.go
|
@ -20,7 +20,7 @@ import (
|
||||||
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
||||||
const go11tag = true
|
const go11tag = true
|
||||||
|
|
||||||
const APP_VER = "0.0.5.0313"
|
const APP_VER = "0.0.6.0313"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -105,7 +105,6 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: RemoveAll may fail due to not root access.
|
|
||||||
access := Access{
|
access := Access{
|
||||||
UserName: user.Name,
|
UserName: user.Name,
|
||||||
RepoName: repo.Name,
|
RepoName: repo.Name,
|
||||||
|
@ -329,13 +328,21 @@ func RepoPath(userName, repoName string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository deletes a repository for a user or orgnaztion.
|
// DeleteRepository deletes a repository for a user or orgnaztion.
|
||||||
func DeleteRepository(user *User, reposName string) (err error) {
|
func DeleteRepository(userId, repoId int64, userName string) (err error) {
|
||||||
|
repo := &Repository{Id: repoId, OwnerId: userId}
|
||||||
|
has, err := orm.Get(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
return ErrRepoNotExist
|
||||||
|
}
|
||||||
|
|
||||||
session := orm.NewSession()
|
session := orm.NewSession()
|
||||||
if _, err = session.Delete(&Repository{OwnerId: user.Id, Name: reposName}); err != nil {
|
if _, err = session.Delete(&Repository{Id: repoId}); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", user.Id); err != nil {
|
if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", userId); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -343,9 +350,9 @@ func DeleteRepository(user *User, reposName string) (err error) {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = os.RemoveAll(RepoPath(user.Name, reposName)); err != nil {
|
if err = os.RemoveAll(RepoPath(userName, repo.Name)); err != nil {
|
||||||
// TODO: log and delete manully
|
// TODO: log and delete manully
|
||||||
log.Error("delete repo %s/%s failed", user.Name, reposName)
|
log.Error("delete repo %s/%s failed", userName, repo.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -56,6 +56,12 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con
|
||||||
validate(errors, data, f)
|
validate(errors, data, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteRepoForm struct {
|
||||||
|
UserId int64 `form:"userId" binding:"Required"`
|
||||||
|
UserName string `form:"userName" binding:"Required"`
|
||||||
|
RepoId int64 `form:"repoId" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
func RepoAssignment(redirect bool) martini.Handler {
|
func RepoAssignment(redirect bool) martini.Handler {
|
||||||
return func(params martini.Params, r render.Render, data base.TmplData, session sessions.Session) {
|
return func(params martini.Params, r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
// assign false first
|
// assign false first
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"github.com/martini-contrib/render"
|
"github.com/martini-contrib/render"
|
||||||
"github.com/martini-contrib/sessions"
|
"github.com/martini-contrib/sessions"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
|
@ -68,7 +68,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b
|
||||||
r.HTML(200, "base/error", data)
|
r.HTML(200, "base/error", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
data["Title"] = "Delete repository"
|
data["Title"] = "Delete repository"
|
||||||
|
|
||||||
if req.Method == "GET" {
|
if req.Method == "GET" {
|
||||||
|
@ -76,13 +76,14 @@ func Delete(req *http.Request, r render.Render, data base.TmplData, session sess
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u := &models.User{}
|
if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
|
||||||
err := models.DeleteRepository(u, "")
|
|
||||||
if err != nil {
|
|
||||||
data["ErrorMsg"] = err
|
data["ErrorMsg"] = err
|
||||||
log.Error("repo.Delete: %v", err)
|
log.Error("repo.Delete: %v", err)
|
||||||
r.HTML(200, "base/error", data)
|
r.HTML(200, "base/error", data)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.Redirect("/", 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
|
|
|
@ -26,6 +26,6 @@
|
||||||
<button type="button" class="btn btn-default"><i class="fa fa-code-fork"></i>Fork {{.Repository.NumForks}}</button>
|
<button type="button" class="btn btn-default"><i class="fa fa-code-fork"></i>Fork {{.Repository.NumForks}}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3><i class="fa fa-book fa-lg"></i><a href="/{{.Owner.Name}}/">{{.Owner.Name}}</a> / {{.Repository.Name}}</h3>
|
<h3><i class="fa fa-book fa-lg"></i><a href="/user/{{.Owner.Name}}">{{.Owner.Name}}</a> / {{.Repository.Name}}</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -22,8 +22,9 @@
|
||||||
<p>This action <strong>CANNOT</strong> be undone. This will delete the repository, wiki, issues, and comments permanently. </p>
|
<p>This action <strong>CANNOT</strong> be undone. This will delete the repository, wiki, issues, and comments permanently. </p>
|
||||||
|
|
||||||
<form action="/repo/delete" method="post">
|
<form action="/repo/delete" method="post">
|
||||||
<input type="hidden" name="reponame" value="{{.Repository.Name}}"/>
|
<input type="hidden" name="userId" value="{{.Owner.Id}}"/>
|
||||||
<input type="hidden" name="username" value="{{.Owner.Name}}"/>
|
<input type="hidden" name="userName" value="{{.Owner.Name}}"/>
|
||||||
|
<input type="hidden" name="repoId" value="{{.Repository.Id}}"/>
|
||||||
<hr/>
|
<hr/>
|
||||||
<button class="btn btn-danger btn-lg">I understand the consequences, delete this repository</button>
|
<button class="btn btn-danger btn-lg">I understand the consequences, delete this repository</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Statics <b class="caret"></b></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Statistic <b class="caret"></b></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#">Graphic</a></li>
|
<li><a href="#">Graphic</a></li>
|
||||||
<li><a href="#">Pulse</a></li>
|
<li><a href="#">Pulse</a></li>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="gogs-body" class="container">
|
<div id="gogs-body" class="container">
|
||||||
|
{{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}}
|
||||||
<div id="gogs-feed-left" class="col-md-8">
|
<div id="gogs-feed-left" class="col-md-8">
|
||||||
Website is still in the progress of building...please come back later! <strong>{{.SignedUserName}}</strong> is logged!
|
Website is still in the progress of building...please come back later! <strong>{{.SignedUserName}}</strong> is logged!
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<li class="list-group-item list-group-item-success"><a href="/user/setting">Account Profile</a></li>
|
<li class="list-group-item list-group-item-success"><a href="/user/setting">Account Profile</a></li>
|
||||||
<li class="list-group-item"><a href="#">Emails and Password</a></li>
|
<li class="list-group-item"><a href="#">Emails and Password</a></li>
|
||||||
<li class="list-group-item"><a href="#">Notifications</a></li>
|
<li class="list-group-item"><a href="#">Notifications</a></li>
|
||||||
<li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
|
<li class="list-group-item"><a href="/user/setting/ssh">SSH Keys</a></li>
|
||||||
<li class="list-group-item"><a href="#">Security</a></li>
|
<li class="list-group-item"><a href="#">Security</a></li>
|
||||||
<li class="list-group-item"><a href="/user/delete">Delete Account</a></li>
|
<li class="list-group-item"><a href="/user/delete">Delete Account</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
2
web.go
2
web.go
|
@ -69,7 +69,7 @@ func runWeb(*cli.Context) {
|
||||||
m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
|
m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
|
||||||
|
|
||||||
m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
|
m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
|
||||||
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)
|
m.Any("/repo/delete", auth.SignInRequire(true), binding.Bind(auth.DeleteRepoForm{}), repo.Delete)
|
||||||
m.Any("/repo/list", auth.SignInRequire(false), repo.List)
|
m.Any("/repo/list", auth.SignInRequire(false), repo.List)
|
||||||
|
|
||||||
m.Get("/:username/:reponame/settings", auth.SignInRequire(false), auth.RepoAssignment(true), repo.Setting)
|
m.Get("/:username/:reponame/settings", auth.SignInRequire(false), auth.RepoAssignment(true), repo.Setting)
|
||||||
|
|
Loading…
Reference in a new issue