Private forums (admin only for now)
This commit is contained in:
parent
0f6dd58c54
commit
9db7343370
|
@ -65,12 +65,14 @@ func AddEdit() http.HandlerFunc {
|
||||||
isPrivileged = r.PostFormValue("privileged") == "true"
|
isPrivileged = r.PostFormValue("privileged") == "true"
|
||||||
isPermitPhotos = r.PostFormValue("permit_photos") == "true"
|
isPermitPhotos = r.PostFormValue("permit_photos") == "true"
|
||||||
isInnerCircle = r.PostFormValue("inner_circle") == "true"
|
isInnerCircle = r.PostFormValue("inner_circle") == "true"
|
||||||
|
isPrivate = r.PostFormValue("private") == "true"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sanity check admin-only settings.
|
// Sanity check admin-only settings.
|
||||||
if !currentUser.IsAdmin {
|
if !currentUser.IsAdmin {
|
||||||
isPrivileged = false
|
isPrivileged = false
|
||||||
isPermitPhotos = false
|
isPermitPhotos = false
|
||||||
|
isPrivate = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Were we editing an existing forum?
|
// Were we editing an existing forum?
|
||||||
|
@ -83,6 +85,7 @@ func AddEdit() http.HandlerFunc {
|
||||||
models.NewFieldDiff("Privileged", forum.Privileged, isPrivileged),
|
models.NewFieldDiff("Privileged", forum.Privileged, isPrivileged),
|
||||||
models.NewFieldDiff("PermitPhotos", forum.PermitPhotos, isPermitPhotos),
|
models.NewFieldDiff("PermitPhotos", forum.PermitPhotos, isPermitPhotos),
|
||||||
models.NewFieldDiff("InnerCircle", forum.InnerCircle, isInnerCircle),
|
models.NewFieldDiff("InnerCircle", forum.InnerCircle, isInnerCircle),
|
||||||
|
models.NewFieldDiff("Private", forum.Private, isPrivate),
|
||||||
}
|
}
|
||||||
|
|
||||||
forum.Title = title
|
forum.Title = title
|
||||||
|
@ -92,6 +95,7 @@ func AddEdit() http.HandlerFunc {
|
||||||
forum.Privileged = isPrivileged
|
forum.Privileged = isPrivileged
|
||||||
forum.PermitPhotos = isPermitPhotos
|
forum.PermitPhotos = isPermitPhotos
|
||||||
forum.InnerCircle = isInnerCircle
|
forum.InnerCircle = isInnerCircle
|
||||||
|
forum.Private = isPrivate
|
||||||
|
|
||||||
// Save it.
|
// Save it.
|
||||||
if err := forum.Save(); err == nil {
|
if err := forum.Save(); err == nil {
|
||||||
|
@ -128,6 +132,7 @@ func AddEdit() http.HandlerFunc {
|
||||||
Privileged: isPrivileged,
|
Privileged: isPrivileged,
|
||||||
PermitPhotos: isPermitPhotos,
|
PermitPhotos: isPermitPhotos,
|
||||||
InnerCircle: isInnerCircle,
|
InnerCircle: isInnerCircle,
|
||||||
|
Private: isPrivate,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateForum(forum); err == nil {
|
if err := models.CreateForum(forum); err == nil {
|
||||||
|
@ -144,7 +149,8 @@ func AddEdit() http.HandlerFunc {
|
||||||
"* Explicit: %v\n"+
|
"* Explicit: %v\n"+
|
||||||
"* Privileged: %v\n"+
|
"* Privileged: %v\n"+
|
||||||
"* Photos: %v\n"+
|
"* Photos: %v\n"+
|
||||||
"* Inner Circle: %v",
|
"* Inner Circle: %v\n"+
|
||||||
|
"* Private: %v",
|
||||||
forum.Category,
|
forum.Category,
|
||||||
forum.Title,
|
forum.Title,
|
||||||
forum.Fragment,
|
forum.Fragment,
|
||||||
|
@ -153,6 +159,7 @@ func AddEdit() http.HandlerFunc {
|
||||||
forum.Privileged,
|
forum.Privileged,
|
||||||
forum.PermitPhotos,
|
forum.PermitPhotos,
|
||||||
forum.InnerCircle,
|
forum.InnerCircle,
|
||||||
|
forum.Private,
|
||||||
))
|
))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -41,6 +41,12 @@ func Forum() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is it a private forum?
|
||||||
|
if forum.Private && !currentUser.IsAdmin {
|
||||||
|
templates.NotFoundPage(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get the pinned threads.
|
// Get the pinned threads.
|
||||||
pinned, err := models.PinnedThreads(forum)
|
pinned, err := models.PinnedThreads(forum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,6 +57,12 @@ func Thread() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is it a private forum?
|
||||||
|
if forum.Private && !currentUser.IsAdmin {
|
||||||
|
templates.NotFoundPage(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ping the view count on this thread.
|
// Ping the view count on this thread.
|
||||||
if err := thread.View(currentUser.ID); err != nil {
|
if err := thread.View(currentUser.ID); err != nil {
|
||||||
log.Error("Couldn't ping view count on thread %d: %s", thread.ID, err)
|
log.Error("Couldn't ping view count on thread %d: %s", thread.ID, err)
|
||||||
|
|
|
@ -20,7 +20,8 @@ type Forum struct {
|
||||||
Explicit bool `gorm:"index"`
|
Explicit bool `gorm:"index"`
|
||||||
Privileged bool
|
Privileged bool
|
||||||
PermitPhotos bool
|
PermitPhotos bool
|
||||||
InnerCircle bool
|
InnerCircle bool `gorm:"index"`
|
||||||
|
Private bool `gorm:"index"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
@ -101,6 +102,11 @@ func PaginateForums(user *User, categories []string, pager *Pagination) ([]*Foru
|
||||||
wheres = append(wheres, "inner_circle is not true")
|
wheres = append(wheres, "inner_circle is not true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide private forums except for admins.
|
||||||
|
if !user.IsAdmin {
|
||||||
|
wheres = append(wheres, "private is not true")
|
||||||
|
}
|
||||||
|
|
||||||
// Filters?
|
// Filters?
|
||||||
if len(wheres) > 0 {
|
if len(wheres) > 0 {
|
||||||
query = query.Where(
|
query = query.Where(
|
||||||
|
|
|
@ -52,6 +52,11 @@ func PaginateRecentPosts(user *User, categories []string, allComments bool, page
|
||||||
wheres = append(wheres, "forums.inner_circle is not true")
|
wheres = append(wheres, "forums.inner_circle is not true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private forums.
|
||||||
|
if !user.IsAdmin {
|
||||||
|
wheres = append(wheres, "forums.private is not true")
|
||||||
|
}
|
||||||
|
|
||||||
// Blocked users?
|
// Blocked users?
|
||||||
if len(blockedUserIDs) > 0 {
|
if len(blockedUserIDs) > 0 {
|
||||||
comment_wheres = append(comment_wheres, "comments.user_id NOT IN ?")
|
comment_wheres = append(comment_wheres, "comments.user_id NOT IN ?")
|
||||||
|
|
|
@ -100,6 +100,11 @@ func SearchForum(user *User, search *Search, filters ForumSearchFilters, pager *
|
||||||
wheres = append(wheres, "forums.inner_circle is not true")
|
wheres = append(wheres, "forums.inner_circle is not true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private forums.
|
||||||
|
if !user.IsAdmin {
|
||||||
|
wheres = append(wheres, "forums.private is not true")
|
||||||
|
}
|
||||||
|
|
||||||
// Blocked users?
|
// Blocked users?
|
||||||
if len(blockedUserIDs) > 0 {
|
if len(blockedUserIDs) > 0 {
|
||||||
wheres = append(wheres, "comments.user_id NOT IN ?")
|
wheres = append(wheres, "comments.user_id NOT IN ?")
|
||||||
|
|
|
@ -140,6 +140,19 @@
|
||||||
This forum is only available to inner circle members.
|
This forum is only available to inner circle members.
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if .CurrentUser.IsAdmin}}
|
||||||
|
<label class="checkbox mt-3">
|
||||||
|
<input type="checkbox"
|
||||||
|
name="private"
|
||||||
|
value="true"
|
||||||
|
{{if and .EditForum .EditForum.Private}}checked{{end}}>
|
||||||
|
Private forum
|
||||||
|
</label>
|
||||||
|
<p class="help">
|
||||||
|
This forum is only visible to admins or approved subscribers.
|
||||||
|
</p>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
|
@ -87,10 +87,17 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div class="tag is-light">
|
{{if .PermitPhotos}}
|
||||||
|
<div class="tag is-private is-light">
|
||||||
|
<span class="icon"><i class="fa fa-lock"></i></span>
|
||||||
|
Private
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<div class="tag">
|
||||||
Created {{.CreatedAt.Format "2006-01-02 15:04:05"}}
|
Created {{.CreatedAt.Format "2006-01-02 15:04:05"}}
|
||||||
</div>
|
</div>
|
||||||
<div class="tag is-light">
|
<div class="tag">
|
||||||
Updated {{.UpdatedAt.Format "2006-01-02 15:04:05"}}
|
Updated {{.UpdatedAt.Format "2006-01-02 15:04:05"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -102,6 +102,13 @@
|
||||||
<span>Photos</span>
|
<span>Photos</span>
|
||||||
</span>
|
</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if .Private}}
|
||||||
|
<span class="tag is-private is-light">
|
||||||
|
<span class="icon"><i class="fa fa-lock"></i></span>
|
||||||
|
<span>Private</span>
|
||||||
|
</span>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -116,6 +116,10 @@
|
||||||
{{if .Forum.Explicit}}
|
{{if .Forum.Explicit}}
|
||||||
<small class="has-text-danger fa fa-fire"></small>
|
<small class="has-text-danger fa fa-fire"></small>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if .Forum.Private}}
|
||||||
|
<small class="has-text-private fa fa-lock"></small>
|
||||||
|
{{end}}
|
||||||
</a>
|
</a>
|
||||||
–
|
–
|
||||||
{{SincePrettyCoarse .Thread.Comment.UpdatedAt}} ago
|
{{SincePrettyCoarse .Thread.Comment.UpdatedAt}} ago
|
||||||
|
|
Loading…
Reference in New Issue
Block a user