]> source.dussan.org Git - gitea.git/commitdiff
Fix #532, add system notice
authorUnknwon <joe2010xtmf@163.com>
Wed, 8 Oct 2014 22:29:18 +0000 (18:29 -0400)
committerUnknwon <joe2010xtmf@163.com>
Wed, 8 Oct 2014 22:29:18 +0000 (18:29 -0400)
12 files changed:
cmd/web.go
conf/locale/locale_en-US.ini
conf/locale/locale_zh-CN.ini
gogs.go
models/admin.go [new file with mode: 0644]
models/models.go
models/repo.go
routers/admin/notice.go [new file with mode: 0644]
routers/admin/users.go
templates/.VERSION
templates/admin/nav.tmpl
templates/admin/notice.tmpl [new file with mode: 0644]

index 201eb48f0e7fcfc42e39004b58d8c58d3c48fca4..9f2ec8b8245a95d12ce7563cc2f624fd5fcb6449 100644 (file)
@@ -243,6 +243,11 @@ func runWeb(*cli.Context) {
                        r.Post("/:authid", bindIgnErr(auth.AuthenticationForm{}), admin.EditAuthSourcePost)
                        r.Post("/:authid/delete", admin.DeleteAuthSource)
                })
+
+               m.Group("/notices", func(r *macaron.Router) {
+                       r.Get("", admin.Notices)
+                       r.Get("/:id:int/delete", admin.DeleteNotice)
+               })
        }, adminReq)
 
        m.Get("/:username", ignSignIn, user.Profile)
index 4fc8c359ff3ef328214db7d222d22af86f9be44c..15262e630fc87a60f6bb620cbf58cbe5e9e381b7 100644 (file)
@@ -416,6 +416,7 @@ organizations = Organizations
 repositories = Repositories
 authentication = Authentications
 config = Configuration
+notices = System Notices
 monitor = Monitoring
 prev = Prev.
 next = Next
@@ -593,6 +594,13 @@ monitor.desc = Description
 monitor.start = Start Time
 monitor.execute_time = Execution Time
 
+notices.system_notice_list = System Notices
+notices.type = Type
+notices.type_1 = Repository
+notices.desc = Description
+notices.op = Op.
+notices.delete_success = System notice has been successfully deleted.
+
 [action]
 create_repo = created repository <a href="%s/%s">%s</a>
 commit_repo = pushed to <a href="%s/%s/src/%s">%s</a> at <a href="%s/%s">%s</a>
index dc4548487baae1fe602adaea6277c138103e64aa..8a343d4c8cd08e8015acb60e0bcf20bd3ef9cd62 100644 (file)
@@ -416,6 +416,7 @@ organizations = 组织管理
 repositories = 仓库管理
 authentication = 授权认证管理
 config = 应用配置管理
+notices = 系统提示管理
 monitor = 应用监控面板
 prev = 上一页
 next = 下一页
@@ -593,6 +594,13 @@ monitor.desc = 进程描述
 monitor.start = 开始时间
 monitor.execute_time = 已执行时间
 
+notices.system_notice_list = 系统提示管理
+notices.type = 提示类型
+notices.type_1 = 仓库
+notices.desc = 描述
+notices.op = 操作
+notices.delete_success = 系统提示删除成功!
+
 [action]
 create_repo = 创建了仓库 <a href="%s/%s">%s</a>
 commit_repo = 推送了 <a href="%s/%s/src/%s">%s</a> 分支的代码到 <a href="%s/%s">%s</a>
diff --git a/gogs.go b/gogs.go
index b1e46096a8056cdedfd70153695be9d7d3d3a162..250333f39a66637c70dea07ab102a8cec6cb980d 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.5.5.1007 Beta"
+const APP_VER = "0.5.5.1008 Beta"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/models/admin.go b/models/admin.go
new file mode 100644 (file)
index 0000000..493cc7a
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright 2014 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 models
+
+import (
+       "time"
+
+       "github.com/Unknwon/com"
+)
+
+type NoticeType int
+
+const (
+       NOTICE_REPOSITORY NoticeType = iota + 1
+)
+
+// Notice represents a system notice for admin.
+type Notice struct {
+       Id          int64
+       Type        NoticeType
+       Description string    `xorm:"TEXT"`
+       Created     time.Time `xorm:"CREATED"`
+}
+
+// TrStr returns a translation format string.
+func (n *Notice) TrStr() string {
+       return "admin.notices.type_" + com.ToStr(n.Type)
+}
+
+// CreateNotice creates new system notice.
+func CreateNotice(tp NoticeType, desc string) error {
+       n := &Notice{
+               Type:        tp,
+               Description: desc,
+       }
+       _, err := x.Insert(n)
+       return err
+}
+
+// CreateRepositoryNotice creates new system notice with type NOTICE_REPOSITORY.
+func CreateRepositoryNotice(desc string) error {
+       return CreateNotice(NOTICE_REPOSITORY, desc)
+}
+
+// CountNotices returns number of notices.
+func CountNotices() int64 {
+       count, _ := x.Count(new(Notice))
+       return count
+}
+
+// GetNotices returns given number of notices with offset.
+func GetNotices(num, offset int) ([]*Notice, error) {
+       notices := make([]*Notice, 0, num)
+       err := x.Limit(num, offset).Desc("id").Find(&notices)
+       return notices, err
+}
+
+// DeleteNotice deletes a system notice by given ID.
+func DeleteNotice(id int64) error {
+       _, err := x.Id(id).Delete(new(Notice))
+       return err
+}
index 570df0c114b99fbb5fe05760b0f97a1e76f955f6..35eb4c9692caa879f2aa6a935e4ee293e0d5c397 100644 (file)
@@ -32,12 +32,12 @@ var (
 )
 
 func init() {
-       tables = append(tables, new(User), new(PublicKey),
+       tables = append(tables, new(User), new(PublicKey), new(Follow), new(Oauth2),
                new(Repository), new(Watch), new(Star), new(Action), new(Access),
-               new(Issue), new(Comment), new(Oauth2), new(Follow),
-               new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
-               new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser),
-               new(UpdateTask), new(Attachment))
+               new(Issue), new(Comment), new(Attachment), new(IssueUser), new(Label), new(Milestone),
+               new(Mirror), new(Release), new(LoginSource), new(Webhook),
+               new(UpdateTask), new(HookTask), new(Team), new(OrgUser), new(TeamUser),
+               new(Notice))
 }
 
 func LoadModelsConfig() {
index 8e29b3357d8222f8acfb244c58b2f03cec51feb4..3a26c88f0385ceb74018df78d8074f39e60fc403 100644 (file)
@@ -934,9 +934,14 @@ func DeleteRepository(uid, repoId int64, userName string) error {
                sess.Rollback()
                return err
        }
+
+       // Remove repository files.
        if err = os.RemoveAll(RepoPath(userName, repo.Name)); err != nil {
-               sess.Rollback()
-               return err
+               desc := fmt.Sprintf("Fail to delete repository files(%s/%s): %v", userName, repo.Name, err)
+               log.Warn(desc)
+               if err = CreateRepositoryNotice(desc); err != nil {
+                       log.Error(4, "Fail to add notice: %v", err)
+               }
        }
        return sess.Commit()
 }
diff --git a/routers/admin/notice.go b/routers/admin/notice.go
new file mode 100644 (file)
index 0000000..b431946
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2014 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 (
+       "github.com/Unknwon/com"
+
+       "github.com/gogits/gogs/models"
+       "github.com/gogits/gogs/modules/base"
+       "github.com/gogits/gogs/modules/log"
+       "github.com/gogits/gogs/modules/middleware"
+)
+
+const (
+       NOTICES base.TplName = "admin/notice"
+)
+
+func Notices(ctx *middleware.Context) {
+       ctx.Data["Title"] = ctx.Tr("admin.notices")
+       ctx.Data["PageIsAdmin"] = true
+       ctx.Data["PageIsAdminNotices"] = true
+
+       pageNum := 50
+       p := pagination(ctx, models.CountNotices(), pageNum)
+
+       notices, err := models.GetNotices(pageNum, (p-1)*pageNum)
+       if err != nil {
+               ctx.Handle(500, "GetNotices", err)
+               return
+       }
+       ctx.Data["Notices"] = notices
+       ctx.HTML(200, NOTICES)
+}
+
+func DeleteNotice(ctx *middleware.Context) {
+       id := com.StrTo(ctx.Params(":id")).MustInt64()
+       if err := models.DeleteNotice(id); err != nil {
+               ctx.Handle(500, "DeleteNotice", err)
+               return
+       }
+       log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id)
+       ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
+       ctx.Redirect("/admin/notices")
+}
index fc3b0cbce07fd7b84d7e6c35c72f779eb0c544c6..e5cd364f3a7d7985e2f14fe08c5a99b077d14e33 100644 (file)
@@ -48,12 +48,12 @@ func Users(ctx *middleware.Context) {
        pageNum := 50
        p := pagination(ctx, models.CountUsers(), pageNum)
 
-       var err error
-       ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum)
+       users, err := models.GetUsers(pageNum, (p-1)*pageNum)
        if err != nil {
                ctx.Handle(500, "GetUsers", err)
                return
        }
+       ctx.Data["Users"] = users
        ctx.HTML(200, USERS)
 }
 
index 999f683bf8c304f9ab45000e51965c3033224cac..194ec58029be56f260a99451a86b7c70288f417c 100644 (file)
@@ -1 +1 @@
-0.5.5.1007 Beta
\ No newline at end of file
+0.5.5.1008 Beta
\ No newline at end of file
index e294cd921c15ccba9649854863009ead2d3cbec1..49c4b72cf09eaa7eb4bc945bbe8504d0ee6c10bb 100644 (file)
@@ -8,6 +8,7 @@
             <li {{if .PageIsAdminRepositories}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/repos">{{.i18n.Tr "admin.repositories"}}</a></li>
             <li {{if .PageIsAdminAuthentications}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/auths">{{.i18n.Tr "admin.authentication"}}</a></li>
             <li {{if .PageIsAdminConfig}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/config">{{.i18n.Tr "admin.config"}}</a></li>
+            <li {{if .PageIsAdminNotices}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/notices">{{.i18n.Tr "admin.notices"}}</a></li>
             <li {{if .PageIsAdminMonitor}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/monitor">{{.i18n.Tr "admin.monitor"}}</a></li>
         </ul>
     </div>
diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl
new file mode 100644 (file)
index 0000000..b3abbb6
--- /dev/null
@@ -0,0 +1,54 @@
+{{template "ng/base/head" .}}
+{{template "ng/base/header" .}}
+<div id="admin-wrapper">
+    <div id="setting-wrapper" class="main-wrapper">
+        <div id="admin-setting" class="container clear">
+            {{template "admin/nav" .}}
+            <div class="grid-4-5 left">
+                <div class="setting-content">
+                    {{template "ng/base/alert" .}}
+                    <div id="setting-content">
+                        <div class="panel panel-radius">
+                            <div class="panel-header">
+                                <strong>{{.i18n.Tr "admin.notices.system_notice_list"}}</strong>
+                            </div>
+                            <div class="panel-body admin-panel">
+                                <div class="admin-table">
+                                                       <table class="table table-striped">
+                                                           <thead>
+                                                               <tr>
+                                                                   <th>Id</th>
+                                                                   <th>{{.i18n.Tr "admin.notices.type"}}</th>
+                                                                   <th>{{.i18n.Tr "admin.notices.desc"}}</th>
+                                                                   <th>{{.i18n.Tr "admin.users.created"}}</th>
+                                                                   <th>{{.i18n.Tr "admin.notices.op"}}</th>
+                                                               </tr>
+                                                           </thead>
+                                                           <tbody>
+                                                               {{range .Notices}}
+                                                               <tr>
+                                                                   <td>{{.Id}}</td>
+                                                                   <td>{{$.i18n.Tr .TrStr}}</td>
+                                                                   <td class="grid-1-2"><span>{{.Description}}</span></td>
+                                                                   <td>{{.Created}}</td>
+                                                                   <td><a href="{{AppSubUrl}}/admin/notices/{{.Id}}/delete"><i class="fa fa-trash-o text-red"></i></a></td>
+                                                               </tr>
+                                                               {{end}}
+                                                           </tbody>
+                                                       </table>
+                                                       {{if or .LastPageNum .NextPageNum}}
+                                                       <ul class="pagination">
+                                                           {{if .LastPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{AppSubUrl}}/admin/users?p={{.LastPageNum}}">&laquo; {{.i18n.Tr "admin.prev"}}</a></li>{{end}}
+                                                           {{if .NextPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{AppSubUrl}}/admin/users?p={{.NextPageNum}}">&raquo; {{.i18n.Tr "admin.next"}}</a></li>{{end}}
+                                                       </ul>
+                                                       {{end}}
+                                               </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+{{template "ng/base/footer" .}}
\ No newline at end of file