Skip to content

Commit 8c84cdf

Browse files
committed
项目组权限设置
1 parent 8d62f6d commit 8c84cdf

File tree

6 files changed

+69
-67
lines changed

6 files changed

+69
-67
lines changed

change.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
- [x] 使用`Cache-Control`实现API缓存设置
4343
- [x] 如果只有作者才能写作,则如果项目创建者不是作者,已创建了项目的,不允许私有转公有、不允许私密分享
4444
- [ ] 项目成员PC端无法访问和编辑项目的问题处理
45+
- [ ] 管理员和创始人可以设置书籍信息以及生成电子书
46+
- [ ] 编辑者以上权限可以克隆、上传等对项目进行编辑操作
4547
- [ ] 管理后台,增加一个环境监测,用于检测网站各项依赖是否正常
4648

4749

controllers/DocumentController.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func isReadable(identify, token string, this *DocumentController) *models.BookRe
9999
if this.Member != nil {
100100
rel, err := models.NewRelationship().FindByBookIdAndMemberId(bookResult.BookId, this.Member.MemberId)
101101
if err == nil {
102-
bookResult.MemberId = rel.MemberId
102+
bookResult.MemberId = book.MemberId
103103
bookResult.RoleId = rel.RoleId
104104
bookResult.RelationshipId = rel.RelationshipId
105105
}
@@ -1057,13 +1057,14 @@ func (this *DocumentController) Content() {
10571057
//如果启用了文档历史,则添加历史文档
10581058
if this.EnableDocumentHistory > 0 {
10591059
if len(strings.TrimSpace(ds.Markdown)) > 0 { //空内容不存储版本
1060+
now := time.Now().Unix()
10601061
history := models.NewDocumentHistory()
10611062
history.DocumentId = docId
10621063
history.DocumentName = doc.DocumentName
1063-
history.ModifyAt = this.Member.MemberId
1064-
history.MemberId = doc.MemberId
1064+
history.ModifyAt = int(now)
1065+
history.MemberId = this.Member.MemberId
10651066
history.ParentId = doc.ParentId
1066-
history.Version = time.Now().Unix()
1067+
history.Version = now
10671068
history.Action = "modify"
10681069
history.ActionName = actionName
10691070
_, err = history.InsertOrUpdate()

models/book.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (m *Book) FindToPager(pageIndex, pageSize, memberId int, PrivatelyOwned ...
191191

192192
offset := (pageIndex - 1) * pageSize
193193
sql2 := "SELECT book.*,rel.member_id,rel.role_id,m.account as create_name FROM " + m.TableNameWithPrefix() + " AS book" +
194-
" LEFT JOIN " + relationship.TableNameWithPrefix() + " AS rel ON book.book_id=rel.book_id AND rel.member_id = ? AND rel.role_id=0" +
194+
" LEFT JOIN " + relationship.TableNameWithPrefix() + " AS rel ON book.book_id=rel.book_id AND rel.member_id = ? " +
195195
" LEFT JOIN " + NewMember().TableNameWithPrefix() + " AS m ON rel.member_id=m.member_id " +
196196
" WHERE rel.relationship_id > 0 %v ORDER BY book.book_id DESC LIMIT " + fmt.Sprintf("%d,%d", offset, pageSize)
197197

@@ -218,13 +218,13 @@ func (m *Book) FindToPager(pageIndex, pageSize, memberId int, PrivatelyOwned ...
218218
books[index].LastModifyText = text.Account + " 于 " + text.ModifyTime.Format("2006-01-02 15:04:05")
219219
}
220220

221-
if book.RoleId == 0 {
221+
if book.RoleId == conf.BookFounder {
222222
book.RoleName = "创始人"
223-
} else if book.RoleId == 1 {
223+
} else if book.RoleId == conf.BookAdmin {
224224
book.RoleName = "管理员"
225-
} else if book.RoleId == 2 {
225+
} else if book.RoleId == conf.BookEditor {
226226
book.RoleName = "编辑者"
227-
} else if book.RoleId == 3 {
227+
} else if book.RoleId == conf.BookObserver {
228228
book.RoleName = "观察者"
229229
}
230230
}

models/document_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package models
22

3-
import "github.com/astaxie/beego/orm"
3+
import (
4+
"github.com/astaxie/beego/orm"
5+
)
46

57
var TableDocumentStore = "md_document_store"
68

views/book/index.html

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -97,65 +97,62 @@
9797

9898
<div class="btns">
9999
<a :href="'{{urlfor "DocumentController.Index" ":key" ""}}' + item.identify" title="查看文档" class="btn btn-default btn-sm" data-toggle="tooltip" target="_blank"><i class="fa fa-eye"></i> 查看<span class="hidden-xs">文档</span></a>
100+
<a v-if="item.role_id < 2" :href="'/book/' + item.identify + '/setting'" title="项目设置" class="btn btn-default btn-sm" data-toggle="tooltip" target="_blank"><i class="fa fa-cogs"></i> <span class="hidden-xs">项目</span>设置</a>
101+
<a v-if="item.role_id < 2" :href="'/book/'+ item.identify +'/generate'" class="btn btn-default btn-sm ajax-get confirm" :data-identify="item.identify">
102+
<i class="fa fa-book"></i> 生成下载文档
103+
</a>
104+
100105
<template v-if="item.role_id != 3">
101106
<a :href="'/api/' + item.identify + '/edit'" title="编辑文档" data-toggle="tooltip" class="btn btn-default btn-sm"><i class="fa fa-edit" aria-hidden="true"></i> 编辑<span class="hidden-xs">文档</span></a>
107+
108+
109+
<!-- Split button -->
110+
<div class="btn-group">
111+
<button type="button" class="btn btn-default"><i class="fa fa-cloud-upload"></i> 导入项目</button>
112+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
113+
<span class="caret"></span>
114+
<span class="sr-only">Toggle Dropdown</span>
115+
</button>
116+
<ul class="dropdown-menu">
117+
<li>
118+
<a href="javascript:void(0);" class="btn-upload-epub" data-toggle="tooltip" :data-identify="item.identify" title="支持epub格式电子书导入。">
119+
<i class="fa fa-cloud-upload"></i> EPUB 上传导入
120+
</a>
121+
</li>
122+
<li>
123+
<a href="javascript:void(0);" class="btn-upload-zip" data-toggle="tooltip" :data-identify="item.identify" title="支持任意zip压缩的markdown项目导入。">
124+
<i class="fa fa-cloud-upload"></i> ZIP 上传导入
125+
</a>
126+
</li>
127+
<li>
128+
<a href="javascript:void(0);" class="btn-pull-by-zip" data-toggle="tooltip" :data-identify="item.identify" title="从任意源拉取zip压缩的markdown项目">
129+
<i class="fa fa-link"></i> ZIP 拉取导入
130+
</a>
131+
</li>
132+
<li>
133+
<a href="javascript:void(0);" class="btn-pull-by-git" data-toggle="tooltip" :data-identify="item.identify" title="从Git仓库导入markdown项目">
134+
<i class="fa fa-git"></i> Git Clone 导入
135+
</a>
136+
</li>
137+
</ul>
138+
</div>
102139
</template>
103-
<a :href="'/book/' + item.identify + '/setting'" title="项目设置" class="btn btn-default btn-sm" data-toggle="tooltip" target="_blank"><i class="fa fa-cogs"></i> <span class="hidden-xs">项目</span>设置</a>
104-
{{if lt $.Member.Role 2}}
105-
{{/*<a href="javascript:void(0);" class="btn btn-default btn-upload-zip btn-sm" data-toggle="tooltip" :data-identify="item.identify" title="支持任意zip压缩的markdown项目导入。">*/}}
106-
{{/*<i class="fa fa-cloud-upload"></i> 导入<span class="hidden-xs">项目</span>*/}}
107-
{{/*</a>*/}}
108-
{{/*<a href="javascript:void(0);" class="btn btn-default btn-pull-project-by-zip btn-sm" data-toggle="tooltip" :data-identify="item.identify" title="从任意源拉取zip压缩的markdown项目">*/}}
109-
{{/*<i class="fa fa-link"></i> 拉取<span class="hidden-xs">项目</span>*/}}
110-
{{/*</a>*/}}
111-
112-
{{end}}
113-
<a :href="'/book/'+ item.identify +'/generate'" class="btn btn-default btn-sm ajax-get confirm" :data-identify="item.identify">
114-
<i class="fa fa-book"></i> 生成下载文档
115-
</a>
116-
<!-- Split button -->
117-
<div class="btn-group">
118-
<button type="button" class="btn btn-default"><i class="fa fa-cloud-upload"></i> 导入项目</button>
119-
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
120-
<span class="caret"></span>
121-
<span class="sr-only">Toggle Dropdown</span>
122-
</button>
123-
<ul class="dropdown-menu">
124-
<li>
125-
<a href="javascript:void(0);" class="btn-upload-epub" data-toggle="tooltip" :data-identify="item.identify" title="支持epub格式电子书导入。">
126-
<i class="fa fa-cloud-upload"></i> EPUB 上传导入
127-
</a>
128-
</li>
129-
<li>
130-
<a href="javascript:void(0);" class="btn-upload-zip" data-toggle="tooltip" :data-identify="item.identify" title="支持任意zip压缩的markdown项目导入。">
131-
<i class="fa fa-cloud-upload"></i> ZIP 上传导入
132-
</a>
133-
</li>
134-
<li>
135-
<a href="javascript:void(0);" class="btn-pull-by-zip" data-toggle="tooltip" :data-identify="item.identify" title="从任意源拉取zip压缩的markdown项目">
136-
<i class="fa fa-link"></i> ZIP 拉取导入
137-
</a>
138-
</li>
139-
<li>
140-
<a href="javascript:void(0);" class="btn-pull-by-git" data-toggle="tooltip" :data-identify="item.identify" title="从Git仓库导入markdown项目">
141-
<i class="fa fa-git"></i> Git Clone 导入
142-
</a>
143-
</li>
144-
</ul>
145-
</div>
146-
<!-- Split button -->
147-
<div class="btn-group btn-group-download">
148-
<button type="button" class="btn btn-default"><i class="fa fa-cloud-download"></i> 导出项目</button>
149-
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
150-
<span class="caret"></span>
151-
<span class="sr-only">Toggle Dropdown</span>
152-
</button>
153-
<ul class="dropdown-menu">
154-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=pdf'">导出 PDF</a></li>
155-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=mobi'">导出 MOBI</a></li>
156-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=epub'">导出 EPUB</a></li>
157-
</ul>
158-
</div>
140+
<template v-if="item.role_id == 0">
141+
<!-- Split button -->
142+
<div class="btn-group btn-group-download">
143+
<button type="button" class="btn btn-default"><i class="fa fa-cloud-download"></i> 导出项目</button>
144+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
145+
<span class="caret"></span>
146+
<span class="sr-only">Toggle Dropdown</span>
147+
</button>
148+
<ul class="dropdown-menu">
149+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=pdf'">导出 PDF</a></li>
150+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=mobi'">导出 MOBI</a></li>
151+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=epub'">导出 EPUB</a></li>
152+
</ul>
153+
</div>
154+
</template>
155+
159156
</div>
160157
</div>
161158

views/document/intro.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="row bookstack-info">
1414
<div class="col-xs-12">
1515
<h1>{{.Book.BookName}}
16-
{{if eq $.Member.MemberId $.Book.MemberId}}
16+
{{if and (eq $.Member.MemberId $.Book.MemberId) (ne $.Book.RoleId 3)}}
1717
<a href="{{urlfor "DocumentController.Edit" ":key" .Book.Identify ":id" ""}}" class="tooltips" title="编辑文档"> &nbsp;<small><i class="fa fa-edit"></i></small> </a>
1818
<a href="{{urlfor "BookController.Setting" ":key" .Book.Identify}}" class="tooltips" title="项目设置"> &nbsp;<small><i class="fa fa-cog"></i></small> </a>
1919
{{end}}

0 commit comments

Comments
 (0)