Bug fix on organization
This commit is contained in:
parent
50de06056b
commit
9baf2b38d0
12 changed files with 164 additions and 35 deletions
|
@ -225,10 +225,6 @@ func runWeb(*cli.Context) {
|
|||
r.Get("/create", org.Create)
|
||||
r.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost)
|
||||
|
||||
m.Group("/:org", func(r *macaron.Router) {
|
||||
r.Get("", org.Home)
|
||||
}, middleware.OrgAssignment(true))
|
||||
|
||||
m.Group("/:org", func(r *macaron.Router) {
|
||||
r.Get("/dashboard", user.Dashboard)
|
||||
r.Get("/members", org.Members)
|
||||
|
@ -257,6 +253,9 @@ func runWeb(*cli.Context) {
|
|||
r.Route("/invitations/new", "GET,POST", org.Invitation)
|
||||
}, middleware.OrgAssignment(true, true, true))
|
||||
}, reqSignIn)
|
||||
m.Group("/org", func(r *macaron.Router) {
|
||||
r.Get("/:org", org.Home)
|
||||
}, middleware.OrgAssignment(true))
|
||||
|
||||
// Repository routers.
|
||||
m.Group("/repo", func(r *macaron.Router) {
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.4.7.0826 Alpha"
|
||||
const APP_VER = "0.4.7.0827 Alpha"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -337,6 +337,9 @@ func RemoveOrgUser(orgId, uid int64) error {
|
|||
if _, err = sess.Delete(access); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
} else if err = WatchRepo(u.Id, repo.Id, false); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,6 +516,10 @@ func (t *Team) AddRepository(repo *Repository) (err error) {
|
|||
return err
|
||||
}
|
||||
}
|
||||
if err = WatchRepo(u.Id, repo.Id, true); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
@ -564,6 +571,9 @@ func (t *Team) RemoveRepository(repoId int64) error {
|
|||
if _, err = sess.Delete(access); err != nil {
|
||||
sess.Rollback()
|
||||
return fmt.Errorf("fail to delete access: %v", err)
|
||||
} else if err = WatchRepo(u.Id, repo.Id, false); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
} else if auth < t.Authorize {
|
||||
if err = addAccessWithAuthorize(sess, access, AuthorizeToAccessType(auth)); err != nil {
|
||||
|
@ -1029,6 +1039,9 @@ func removeTeamMemberWithSess(orgId, teamId, uid int64, sess *xorm.Session) erro
|
|||
if _, err = sess.Delete(access); err != nil {
|
||||
sess.Rollback()
|
||||
return fmt.Errorf("fail to delete access: %v", err)
|
||||
} else if err = WatchRepo(u.Id, repo.Id, false); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
} else if auth < t.Authorize {
|
||||
// Downgrade authorize level.
|
||||
|
|
126
models/repo.go
126
models/repo.go
|
@ -288,6 +288,16 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
|
|||
|
||||
repoPath := RepoPath(u.Name, name)
|
||||
|
||||
if u.IsOrganization() {
|
||||
t, err := u.GetOwnerTeam()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo.NumWatches = t.NumMembers
|
||||
} else {
|
||||
repo.NumWatches = 1
|
||||
}
|
||||
|
||||
repo.IsBare = false
|
||||
if mirror {
|
||||
if err = MirrorRepository(repo.Id, u.Name, repo.Name, repoPath, url); err != nil {
|
||||
|
@ -559,20 +569,25 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror
|
|||
}
|
||||
|
||||
if u.IsOrganization() {
|
||||
ous, err := GetOrgUsersByOrgId(u.Id)
|
||||
t, err := u.GetOwnerTeam()
|
||||
if err != nil {
|
||||
log.Error(4, "GetOrgUsersByOrgId: %v", err)
|
||||
log.Error(4, "GetOwnerTeam: %v", err)
|
||||
} else {
|
||||
for _, ou := range ous {
|
||||
if err = WatchRepo(ou.Uid, repo.Id, true); err != nil {
|
||||
log.Error(4, "WatchRepo: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = t.GetMembers(); err != nil {
|
||||
log.Error(4, "GetMembers: %v", err)
|
||||
} else {
|
||||
for _, u := range t.Members {
|
||||
if err = WatchRepo(u.Id, repo.Id, true); err != nil {
|
||||
log.Error(4, "WatchRepo2: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err = WatchRepo(u.Id, repo.Id, true); err != nil {
|
||||
log.Error(4, "WatchRepo3: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = NewRepoAction(u, repo); err != nil {
|
||||
log.Error(4, "NewRepoAction: %v", err)
|
||||
|
@ -669,18 +684,61 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
|||
}
|
||||
|
||||
// Update user repository number.
|
||||
rawSql := "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?"
|
||||
if _, err = sess.Exec(rawSql, newUser.Id); err != nil {
|
||||
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", newUser.Id); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
rawSql = "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
|
||||
if _, err = sess.Exec(rawSql, u.Id); err != nil {
|
||||
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", u.Id); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// New owner is organization.
|
||||
if newUser.IsOrganization() {
|
||||
mode := WRITABLE
|
||||
if repo.IsMirror {
|
||||
mode = READABLE
|
||||
}
|
||||
access := &Access{
|
||||
RepoName: path.Join(newUser.LowerName, repo.LowerName),
|
||||
Mode: mode,
|
||||
}
|
||||
|
||||
// Give access to all members in owner team.
|
||||
t, err := newUser.GetOwnerTeam()
|
||||
if err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
if err = t.GetMembers(); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, u := range t.Members {
|
||||
access.Id = 0
|
||||
access.UserName = u.LowerName
|
||||
if _, err = sess.Insert(access); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = sess.Exec(
|
||||
"UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// Update owner team info and count.
|
||||
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
|
||||
t.NumRepos++
|
||||
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Change repository directory name.
|
||||
if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
|
||||
sess.Rollback()
|
||||
|
@ -692,11 +750,14 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
|
|||
}
|
||||
|
||||
// Add watch of new owner to repository.
|
||||
if !IsWatching(newUser.Id, repo.Id) {
|
||||
if !newUser.IsOrganization() {
|
||||
if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
|
||||
return err
|
||||
log.Error(4, "WatchRepo", err)
|
||||
}
|
||||
}
|
||||
if err = WatchRepo(u.Id, repo.Id, false); err != nil {
|
||||
log.Error(4, "WatchRepo2", err)
|
||||
}
|
||||
|
||||
if err = TransferRepoAction(u, newUser, repo); err != nil {
|
||||
return err
|
||||
|
@ -753,8 +814,8 @@ func UpdateRepository(repo *Repository) error {
|
|||
}
|
||||
|
||||
// DeleteRepository deletes a repository for a user or orgnaztion.
|
||||
func DeleteRepository(userId, repoId int64, userName string) error {
|
||||
repo := &Repository{Id: repoId, OwnerId: userId}
|
||||
func DeleteRepository(uid, repoId int64, userName string) error {
|
||||
repo := &Repository{Id: repoId, OwnerId: uid}
|
||||
has, err := x.Get(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -762,6 +823,17 @@ func DeleteRepository(userId, repoId int64, userName string) error {
|
|||
return ErrRepoNotExist
|
||||
}
|
||||
|
||||
// In case is a organization.
|
||||
org, err := GetUserById(uid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if org.IsOrganization() {
|
||||
if err = org.GetTeams(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err = sess.Begin(); err != nil {
|
||||
|
@ -772,10 +844,27 @@ func DeleteRepository(userId, repoId int64, userName string) error {
|
|||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete all access.
|
||||
if _, err := sess.Delete(&Access{RepoName: strings.ToLower(path.Join(userName, repo.Name))}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
if org.IsOrganization() {
|
||||
idStr := "$" + com.ToStr(repoId) + "|"
|
||||
for _, t := range org.Teams {
|
||||
if !strings.Contains(t.RepoIds, idStr) {
|
||||
continue
|
||||
}
|
||||
t.NumRepos--
|
||||
t.RepoIds = strings.Replace(t.RepoIds, idStr, "", 1)
|
||||
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
|
@ -819,8 +908,7 @@ func DeleteRepository(userId, repoId int64, userName string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
|
||||
if _, err = sess.Exec(rawSql, userId); err != nil {
|
||||
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -210,13 +210,19 @@ func (w *FileLogWriter) DoRotate() error {
|
|||
|
||||
func (w *FileLogWriter) deleteOldLog() {
|
||||
dir := filepath.Dir(w.Filename)
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) (returnErr error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
returnErr = fmt.Errorf("Unable to delete old log '%s', error: %+v", path, r)
|
||||
}
|
||||
}()
|
||||
|
||||
if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) {
|
||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) {
|
||||
os.Remove(path)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return returnErr
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,9 @@ func (l *Logger) StartLogger() {
|
|||
select {
|
||||
case bm := <-l.msg:
|
||||
for _, l := range l.outputs {
|
||||
l.WriteMsg(bm.msg, bm.skip, bm.level)
|
||||
if err := l.WriteMsg(bm.msg, bm.skip, bm.level); err != nil {
|
||||
fmt.Println("ERROR, unable to WriteMsg:", err)
|
||||
}
|
||||
}
|
||||
case <-l.quit:
|
||||
return
|
||||
|
@ -247,7 +249,9 @@ func (l *Logger) Close() {
|
|||
if len(l.msg) > 0 {
|
||||
bm := <-l.msg
|
||||
for _, l := range l.outputs {
|
||||
l.WriteMsg(bm.msg, bm.skip, bm.level)
|
||||
if err := l.WriteMsg(bm.msg, bm.skip, bm.level); err != nil {
|
||||
fmt.Println("ERROR, unable to WriteMsg:", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break
|
||||
|
|
|
@ -56,6 +56,9 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler {
|
|||
ctx.Org.IsMember = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fake data.
|
||||
ctx.Data["SignedUser"] = &models.User{}
|
||||
}
|
||||
if (requireMember && !ctx.Org.IsMember) ||
|
||||
(requireOwner && !ctx.Org.IsOwner) {
|
||||
|
|
|
@ -218,6 +218,8 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
|
||||
setting.Cfg.SetValue("", "RUN_MODE", "prod")
|
||||
|
||||
setting.Cfg.SetValue("log", "MODE", "file")
|
||||
|
||||
setting.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
||||
|
||||
os.MkdirAll("custom/conf", os.ModePerm)
|
||||
|
|
|
@ -142,8 +142,9 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
|||
ctx.Data["Title"] = ctx.Tr("new_migrate")
|
||||
|
||||
ctxUser := ctx.User
|
||||
if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 {
|
||||
org, err := models.GetUserById(orgId)
|
||||
// Not equal means current user is an organization.
|
||||
if form.Uid != ctx.User.Id {
|
||||
org, err := models.GetUserById(form.Uid)
|
||||
if err != nil && err != models.ErrUserNotExist {
|
||||
ctx.Handle(500, "GetUserById", err)
|
||||
return
|
||||
|
|
|
@ -119,10 +119,23 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
if ctx.Repo.Repository.Name != form.RepoName {
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil)
|
||||
return
|
||||
} else if !ctx.Repo.Owner.ValidtePassword(ctx.Query("password")) {
|
||||
}
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
if !ctx.Repo.Owner.IsOrgOwner(ctx.User.Id) {
|
||||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
if !ctx.User.ValidtePassword(ctx.Query("password")) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_OPTIONS, nil)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !ctx.Repo.Owner.ValidtePassword(ctx.Query("password")) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_OPTIONS, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(ctx.Repo.Owner.Id, ctx.Repo.Repository.Id, ctx.Repo.Owner.Name); err != nil {
|
||||
ctx.Handle(500, "DeleteRepository", err)
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.4.7.0826 Alpha
|
||||
0.4.7.0827 Alpha
|
|
@ -10,8 +10,8 @@
|
|||
<h2>{{.i18n.Tr "app_desc"}}</h2>
|
||||
<form id="promo-form" action="/user/login" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<input class="ipt ipt-large" id="username" name="uname" type="text" placeholder="{{.i18n.Tr " home.uname_holder "}}"/>
|
||||
<input class="ipt ipt-large" name="password" type="password" placeholder="{{.i18n.Tr " home.password_holder "}}"/>
|
||||
<input class="ipt ipt-large" id="username" name="uname" type="text" placeholder="{{.i18n.Tr "home.uname_holder"}}"/>
|
||||
<input class="ipt ipt-large" name="password" type="password" placeholder="{{.i18n.Tr "home.password_holder"}}"/>
|
||||
<input name="from" type="hidden" value="home">
|
||||
<button class="btn btn-black btn-large">{{.i18n.Tr "sign_in"}}</button>
|
||||
<button class="btn btn-green btn-large" id="register-button">{{.i18n.Tr "register"}}</button>
|
||||
|
|
Loading…
Reference in a new issue