Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged

fix #38

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
是否能编辑修改
  • Loading branch information
zhima1234 committed Oct 10, 2017
commit 752b72d5f31c52c29dadb69f2bcab13087a1ad97
22 changes: 18 additions & 4 deletions src/logic/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,26 @@ func CanEdit(me *model.Me, curModel interface{}) bool {
return false
}

if me.IsAdmin {
return true
}

canEditTime := time.Duration(UserSetting["can_edit_time"]) * time.Second

switch entity := curModel.(type) {
case *model.Topic:
if time.Now().Sub(time.Time(entity.Ctime)) > canEditTime {
if me.Uid != entity.Uid && me.IsAdmin {
return true
}

return false
}

if me.Uid == entity.Uid {
return true
}
case *model.Article:
if me.IsAdmin {
return true
}

// 文章的能编辑时间是15天
if time.Now().Sub(time.Time(entity.Ctime)) > 15*86400*time.Second {
return false
Expand All @@ -95,6 +99,10 @@ func CanEdit(me *model.Me, curModel interface{}) bool {
return true
}
case *model.OpenProject:
if me.IsAdmin {
return true
}

// 开源项目的能编辑时间是30天
if time.Now().Sub(time.Time(entity.Ctime)) > 30*86400*time.Second {
return false
Expand All @@ -104,6 +112,9 @@ func CanEdit(me *model.Me, curModel interface{}) bool {
return true
}
case *model.Wiki:
if me.IsAdmin {
return true
}
if time.Now().Sub(time.Time(entity.Ctime)) > canEditTime {
return false
}
Expand All @@ -112,6 +123,9 @@ func CanEdit(me *model.Me, curModel interface{}) bool {
return true
}
case *model.Book:
if me.IsAdmin {
return true
}
if time.Now().Sub(time.Time(entity.CreatedAt)) > canEditTime {
return false
}
Expand Down