-
Notifications
You must be signed in to change notification settings - Fork 1
/
securesite_post.go
74 lines (58 loc) · 1.94 KB
/
securesite_post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package secureconfig
import (
"github.com/ambientkit/ambient"
"github.com/ambientkit/ambient/pkg/amberror"
)
// SavePost saves a post.
func (ss *SecureSite) SavePost(ID string, post ambient.Post) error {
if !ss.Authorized(ambient.GrantSitePostWrite) {
return amberror.ErrAccessDenied
}
return ss.pluginsystem.SavePost(ID, post)
}
// PostsAndPages returns the list of posts and pages.
func (ss *SecureSite) PostsAndPages(onlyPublished bool) (ambient.PostWithIDList, error) {
if !ss.Authorized(ambient.GrantSitePostRead) {
return nil, amberror.ErrAccessDenied
}
return ss.pluginsystem.PostsAndPages(onlyPublished), nil
}
// PublishedPosts returns the list of published posts.
func (ss *SecureSite) PublishedPosts() ([]ambient.Post, error) {
if !ss.Authorized(ambient.GrantSitePostRead) {
return nil, amberror.ErrAccessDenied
}
return ss.pluginsystem.PublishedPosts(), nil
}
// PublishedPages returns the list of published pages.
func (ss *SecureSite) PublishedPages() ([]ambient.Post, error) {
if !ss.Authorized(ambient.GrantSitePostRead) {
return nil, amberror.ErrAccessDenied
}
return ss.pluginsystem.PublishedPages(), nil
}
// PostBySlug returns the post by slug.
func (ss *SecureSite) PostBySlug(slug string) (ambient.PostWithID, error) {
if !ss.Authorized(ambient.GrantSitePostRead) {
return ambient.PostWithID{}, amberror.ErrAccessDenied
}
post := ss.pluginsystem.PostBySlug(slug)
if post.ID == "" {
return ambient.PostWithID{}, amberror.ErrNotFound
}
return post, nil
}
// PostByID returns the post by ID.
func (ss *SecureSite) PostByID(ID string) (ambient.Post, error) {
if !ss.Authorized(ambient.GrantSitePostRead) {
return ambient.Post{}, amberror.ErrAccessDenied
}
return ss.pluginsystem.PostByID(ID)
}
// DeletePostByID deletes a post.
func (ss *SecureSite) DeletePostByID(ID string) error {
if !ss.Authorized(ambient.GrantSitePostDelete) {
return amberror.ErrAccessDenied
}
return ss.pluginsystem.DeletePostByID(ID)
}