summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-12-06 15:08:22 -0800
committerSteve Manuel <nilslice@gmail.com>2016-12-06 15:08:22 -0800
commit650b67e118c6672c65f1b0fab684695284127e9b (patch)
treedebc6a1d90a38e80f839643ce35f98ec89498dd8
parent054f01662788fb3bb7fd2808980e59c3a918e9e3 (diff)
substituting "_{specifier}" => "__{specifier}" so users can add their own types with "_" as a separator and not face conflicts
-rw-r--r--system/admin/handlers.go28
-rw-r--r--system/api/analytics/init.go2
-rw-r--r--system/api/external.go2
-rw-r--r--system/api/handlers.go2
-rw-r--r--system/db/config.go4
-rw-r--r--system/db/content.go20
-rw-r--r--system/db/init.go8
-rw-r--r--system/db/user.go14
8 files changed, 40 insertions, 40 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index 87e5fda..c91db79 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -823,7 +823,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
Order: order,
}
- total, posts := db.Query(t+"_sorted", opts)
+ total, posts := db.Query(t+"__sorted", opts)
b := &bytes.Buffer{}
html := `<div class="col s9 card">
@@ -909,8 +909,8 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
}
case "pending":
- // get _pending posts of type t from the db
- _, posts = db.Query(t+"_pending", opts)
+ // get __pending posts of type t from the db
+ _, posts = db.Query(t+"__pending", opts)
html += `<div class="row externalable">
<span class="description">Status:</span>
@@ -1039,7 +1039,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
// adminPostListItem is a helper to create the li containing a post.
// p is the asserted post as an Editable, t is the Type of the post.
-// specifier is passed to append a name to a namespace like _pending
+// specifier is passed to append a name to a namespace like __pending
func adminPostListItem(e editor.Editable, typeName, status string) []byte {
s, ok := e.(editor.Sortable)
if !ok {
@@ -1067,12 +1067,12 @@ func adminPostListItem(e editor.Editable, typeName, status string) []byte {
case "public", "":
status = ""
default:
- status = "_" + status
+ status = "__" + status
}
post := `
<li class="col s12">
- <a href="/admin/edit?type=` + typeName + `&status=` + strings.TrimPrefix(status, "_") + `&id=` + cid + `">` + i.String() + `</a>
+ <a href="/admin/edit?type=` + typeName + `&status=` + strings.TrimPrefix(status, "__") + `&id=` + cid + `">` + i.String() + `</a>
<span class="post-detail">Updated: ` + updatedTime + `</span>
<span class="publish-date right">` + publishTime + `</span>
@@ -1111,8 +1111,8 @@ func approveContentHandler(res http.ResponseWriter, req *http.Request) {
}
t := req.FormValue("type")
- if strings.Contains(t, "_") {
- t = strings.Split(t, "_")[0]
+ if strings.Contains(t, "__") {
+ t = strings.Split(t, "__")[0]
}
post := content.Types[t]()
@@ -1257,7 +1257,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
if i != "" {
if status == "pending" {
- t = t + "_pending"
+ t = t + "__pending"
}
data, err := db.Content(t + ":" + i)
@@ -1396,8 +1396,8 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
req.PostForm.Del(discardKey)
}
- if strings.Contains(t, "_") {
- t = strings.Split(t, "_")[0]
+ if strings.Contains(t, "__") {
+ t = strings.Split(t, "__")[0]
}
p, ok := content.Types[t]
@@ -1506,8 +1506,8 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) {
}
// catch specifier suffix from delete form value
- if strings.Contains(t, "_") {
- spec := strings.Split(t, "_")
+ if strings.Contains(t, "__") {
+ spec := strings.Split(t, "__")
ct = spec[0]
}
@@ -1637,7 +1637,7 @@ func searchHandler(res http.ResponseWriter, req *http.Request) {
}
if status == "pending" {
- specifier = "_" + status
+ specifier = "__" + status
}
posts := db.ContentAll(t + specifier)
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index 41c24c7..7cb35af 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -66,7 +66,7 @@ func Init() {
}
err = store.Update(func(tx *bolt.Tx) error {
- _, err := tx.CreateBucketIfNotExists([]byte("requests"))
+ _, err := tx.CreateBucketIfNotExists([]byte("__requests"))
if err != nil {
return err
}
diff --git a/system/api/external.go b/system/api/external.go
index 2e9597e..0d1ea03 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -132,7 +132,7 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
} else {
- spec = "_pending"
+ spec = "__pending"
}
_, err = db.SetContent(t+spec+":-1", req.PostForm)
diff --git a/system/api/handlers.go b/system/api/handlers.go
index f31a1eb..8a1517b 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -72,7 +72,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) {
Order: order,
}
- _, bb := db.Query(t+"_sorted", opts)
+ _, bb := db.Query(t+"__sorted", opts)
var result = []json.RawMessage{}
for i := range bb {
result = append(result, bb[i])
diff --git a/system/db/config.go b/system/db/config.go
index 6855081..ab1c720 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -24,7 +24,7 @@ func init() {
// SetConfig sets key:value pairs in the db for configuration settings
func SetConfig(data url.Values) error {
err := store.Update(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
// check for any multi-value fields (ex. checkbox fields)
// and correctly format for db storage. Essentially, we need
@@ -108,7 +108,7 @@ func Config(key string) ([]byte, error) {
func ConfigAll() ([]byte, error) {
val := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
val.Write(b.Get([]byte("settings")))
return nil
diff --git a/system/db/content.go b/system/db/content.go
index ef74091..74a77ec 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -39,11 +39,11 @@ func SetContent(target string, data url.Values) (int, error) {
}
func update(ns, id string, data url.Values) (int, error) {
- var specifier string // i.e. _pending, _sorted, etc.
- if strings.Contains(ns, "_") {
- spec := strings.Split(ns, "_")
+ var specifier string // i.e. __pending, __sorted, etc.
+ if strings.Contains(ns, "__") {
+ spec := strings.Split(ns, "__")
ns = spec[0]
- specifier = "_" + spec[1]
+ specifier = "__" + spec[1]
}
cid, err := strconv.Atoi(id)
@@ -82,11 +82,11 @@ func update(ns, id string, data url.Values) (int, error) {
func insert(ns string, data url.Values) (int, error) {
var effectedID int
- var specifier string // i.e. _pending, _sorted, etc.
- if strings.Contains(ns, "_") {
- spec := strings.Split(ns, "_")
+ var specifier string // i.e. __pending, __sorted, etc.
+ if strings.Contains(ns, "__") {
+ spec := strings.Split(ns, "__")
ns = spec[0]
- specifier = "_" + spec[1]
+ specifier = "__" + spec[1]
}
err := store.Update(func(tx *bolt.Tx) error {
@@ -328,7 +328,7 @@ func Query(namespace string, opts QueryOptions) (int, [][]byte) {
// Should be called from a goroutine after SetContent is successful
func SortContent(namespace string) {
// only sort main content types i.e. Post
- if strings.Contains(namespace, "_") {
+ if strings.Contains(namespace, "__") {
return
}
@@ -354,7 +354,7 @@ func SortContent(namespace string) {
// store in <namespace>_sorted bucket, first delete existing
err := store.Update(func(tx *bolt.Tx) error {
- bname := []byte(namespace + "_sorted")
+ bname := []byte(namespace + "__sorted")
err := tx.DeleteBucket(bname)
if err != nil {
return err
diff --git a/system/db/init.go b/system/db/init.go
index 63804e1..967eed1 100644
--- a/system/db/init.go
+++ b/system/db/init.go
@@ -38,14 +38,14 @@ func Init() {
return err
}
- _, err = tx.CreateBucketIfNotExists([]byte(t + "_sorted"))
+ _, err = tx.CreateBucketIfNotExists([]byte(t + "__sorted"))
if err != nil {
return err
}
}
// init db with other buckets as needed
- buckets := []string{"_config", "_users"}
+ buckets := []string{"__config", "__users"}
for _, name := range buckets {
_, err := tx.CreateBucketIfNotExists([]byte(name))
if err != nil {
@@ -54,7 +54,7 @@ func Init() {
}
// seed db with configs structure if not present
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
if b.Get([]byte("settings")) == nil {
j, err := json.Marshal(&config.Config{})
if err != nil {
@@ -93,7 +93,7 @@ func SystemInitComplete() bool {
complete := false
err := store.View(func(tx *bolt.Tx) error {
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
err := users.ForEach(func(k, v []byte) error {
complete = true
diff --git a/system/db/user.go b/system/db/user.go
index a133890..b92a62a 100644
--- a/system/db/user.go
+++ b/system/db/user.go
@@ -24,7 +24,7 @@ var ErrNoUserExists = errors.New("Error. No user exists.")
func SetUser(usr *user.User) (int, error) {
err := store.Update(func(tx *bolt.Tx) error {
email := []byte(usr.Email)
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
// check if user is found by email, fail if nil
exists := users.Get(email)
@@ -67,7 +67,7 @@ func UpdateUser(usr, updatedUsr *user.User) error {
}
err := store.Update(func(tx *bolt.Tx) error {
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
// check if user is found by email, fail if nil
exists := users.Get([]byte(usr.Email))
@@ -108,7 +108,7 @@ func UpdateUser(usr, updatedUsr *user.User) error {
// DeleteUser deletes a user from the db by email
func DeleteUser(email string) error {
err := store.Update(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
err := b.Delete([]byte(email))
if err != nil {
return err
@@ -127,7 +127,7 @@ func DeleteUser(email string) error {
func User(email string) ([]byte, error) {
val := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
usr := b.Get([]byte(email))
_, err := val.Write(usr)
@@ -152,7 +152,7 @@ func User(email string) ([]byte, error) {
func UserAll() ([][]byte, error) {
var users [][]byte
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
err := b.ForEach(func(k, v []byte) error {
users = append(users, v)
return nil
@@ -201,7 +201,7 @@ func SetRecoveryKey(email string) (string, error) {
key := fmt.Sprintf("%d", rand.Int63())
err := store.Update(func(tx *bolt.Tx) error {
- b, err := tx.CreateBucketIfNotExists([]byte("_recoveryKeys"))
+ b, err := tx.CreateBucketIfNotExists([]byte("__recoveryKeys"))
if err != nil {
return err
}
@@ -226,7 +226,7 @@ func RecoveryKey(email string) (string, error) {
key := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_recoveryKeys"))
+ b := tx.Bucket([]byte("__recoveryKeys"))
if b == nil {
return errors.New("No database found for checking keys.")
}