diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-07-29 23:59:53 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-07-29 23:59:53 -0400 |
commit | 183cc31c0b5f812c0f0fcd8a292e378a9695417f (patch) | |
tree | 555258b76a046e3bcaca313877668ca6e3a20654 /src | |
parent | 7d0f835f1da22ae6a0afcbae0db2bebe72ec1426 (diff) | |
download | guff-183cc31c0b5f812c0f0fcd8a292e378a9695417f.tar.bz2 guff-183cc31c0b5f812c0f0fcd8a292e378a9695417f.zip |
add backend for project tag prefix and hook secret, remove expires_at
Diffstat (limited to 'src')
-rw-r--r-- | src/guff/apis.cr | 11 | ||||
-rw-r--r-- | src/guff/models/blog.cr | 17 | ||||
-rw-r--r-- | src/guff/models/page.cr | 17 | ||||
-rw-r--r-- | src/guff/models/post.cr | 16 | ||||
-rw-r--r-- | src/guff/models/project.cr | 45 |
5 files changed, 39 insertions, 67 deletions
diff --git a/src/guff/apis.cr b/src/guff/apis.cr index 874f354..5d87af2 100644 --- a/src/guff/apis.cr +++ b/src/guff/apis.cr @@ -32,9 +32,6 @@ module Guff::APIs have_posted_at: !!params["posted_at"]?, posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil, - have_expires_at: !!params["expires_at"]?, - expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil, - slug: params["slug"]?, slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil, @@ -78,9 +75,6 @@ module Guff::APIs have_posted_at: !!params["posted_at"]?, posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil, - have_expires_at: !!params["expires_at"]?, - expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil, - slug: params["slug"]?, slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil, @@ -88,6 +82,8 @@ module Guff::APIs body: params["body"]?, repo_url: params["repo_url"]?, + tag_prefix: params["tag_prefix"]?, + hook_secret: params["hook_secret"]?, ) nil @@ -127,9 +123,6 @@ module Guff::APIs have_posted_at: !!params["posted_at"]?, posted_at: params["posted_at"]? ? ISO8601.parse(params["posted_at"]) : nil, - have_expires_at: !!params["expires_at"]?, - expires_at: params["expires_at"]? ? ISO8601.parse(params["expires_at"]) : nil, - slug: params["slug"]?, slug_lock: params["slug_lock"]? ? (params["slug_lock"] == "t") : nil, diff --git a/src/guff/models/blog.cr b/src/guff/models/blog.cr index 15a3188..bb35401 100644 --- a/src/guff/models/blog.cr +++ b/src/guff/models/blog.cr @@ -17,9 +17,8 @@ class Guff::Models::BlogModel < Guff::Models::Model WHERE a.site_id = ? AND d.state = 'public' - AND (0 + strftime('%%s')) - BETWEEN (0 + strftime('%%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%%s')) >= + (0 + strftime('%%s', COALESCE(b.posted_at, 'now'))) AND %s ", @@ -46,9 +45,8 @@ class Guff::Models::BlogModel < Guff::Models::Model WHERE a.site_id = ? AND d.state = 'public' - AND (0 + strftime('%%s')) - BETWEEN (0 + strftime('%%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%%s')) >= + (0 + strftime('%%s', COALESCE(b.posted_at, 'now'))) AND %s ORDER BY COALESCE(b.posted_at, b.created_at) DESC @@ -61,7 +59,6 @@ class Guff::Models::BlogModel < Guff::Models::Model a.site_id, c.state, a.posted_at, - a.expires_at, a.slug, a.slug_lock, a.name, @@ -195,9 +192,6 @@ class Guff::Models::BlogModel < Guff::Models::Model have_posted_at : Bool = false, posted_at : Time? = nil, - have_expires_at : Bool = false, - expires_at : Time? = nil, - slug : String? = nil, slug_lock : Bool? = nil, @@ -215,9 +209,6 @@ class Guff::Models::BlogModel < Guff::Models::Model have_posted_at: have_posted_at, posted_at: posted_at, - have_expires_at: have_expires_at, - expires_at: expires_at, - slug: slug, slug_lock: slug_lock, diff --git a/src/guff/models/page.cr b/src/guff/models/page.cr index 6cca2be..b7043a4 100644 --- a/src/guff/models/page.cr +++ b/src/guff/models/page.cr @@ -18,9 +18,8 @@ class Guff::Models::PageModel < Guff::Models::Model WHERE a.site_id = ? AND b.slug = ? AND d.state = 'public' - AND (0 + strftime('%s')) - BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%s')) >= + (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) ", find: " @@ -53,9 +52,8 @@ class Guff::Models::PageModel < Guff::Models::Model WHERE a.site_id = ? AND b.slug = ? AND d.state = 'public' - AND (0 + strftime('%s')) - BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%s')) >= + (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) ORDER BY b.posted_at DESC @@ -84,7 +82,6 @@ class Guff::Models::PageModel < Guff::Models::Model a.site_id, c.state, a.posted_at, - a.expires_at, a.slug, a.slug_lock, a.name, @@ -186,9 +183,6 @@ class Guff::Models::PageModel < Guff::Models::Model have_posted_at : Bool = false, posted_at : Time? = nil, - have_expires_at : Bool = false, - expires_at : Time? = nil, - slug : String? = nil, slug_lock : Bool? = nil, @@ -210,9 +204,6 @@ class Guff::Models::PageModel < Guff::Models::Model have_posted_at: have_posted_at, posted_at: posted_at, - have_expires_at: have_expires_at, - expires_at: expires_at, - slug: slug, slug_lock: slug_lock, diff --git a/src/guff/models/post.cr b/src/guff/models/post.cr index 5c94d04..782cb31 100644 --- a/src/guff/models/post.cr +++ b/src/guff/models/post.cr @@ -60,10 +60,6 @@ class Guff::Models::PostModel < Guff::Models::Model date(a.posted_at) AS posted_at_text, datetime(a.posted_at) AS posted_at_text_full, - a.expires_at, - date(a.expires_at) AS expires_at_text, - datetime(a.expires_at) AS expires_at_text_full, - a.slug, a.slug_lock, a.name, @@ -141,9 +137,6 @@ class Guff::Models::PostModel < Guff::Models::Model have_posted_at : Bool = false, posted_at : Time? = nil, - have_expires_at : Bool = false, - expires_at : Time? = nil, - slug : String? = nil, slug_lock : Bool? = nil, @@ -179,15 +172,6 @@ class Guff::Models::PostModel < Guff::Models::Model end end - if have_expires_at - if expires_at - sets << "expires_at = ?" - args << ISO8601.format(expires_at) - else - sets << "expires_at = NULL" - end - end - if slug sets << "slug = ?" args << slug diff --git a/src/guff/models/project.cr b/src/guff/models/project.cr index 2aa08ae..996ce7b 100644 --- a/src/guff/models/project.cr +++ b/src/guff/models/project.cr @@ -18,9 +18,8 @@ class Guff::Models::ProjectModel < Guff::Models::Model WHERE a.site_id = ? AND b.slug = ? AND d.state = 'public' - AND (0 + strftime('%s')) - BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%s')) >= + (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) ", find: " @@ -51,9 +50,8 @@ class Guff::Models::ProjectModel < Guff::Models::Model WHERE a.site_id = ? AND b.slug = ? AND d.state = 'public' - AND (0 + strftime('%s')) - BETWEEN (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) - AND (0 + strftime('%s', COALESCE(b.expires_at,'now'))) + AND (0 + strftime('%s')) >= + (0 + strftime('%s', COALESCE(b.posted_at, 'now'))) ORDER BY b.created_at DESC @@ -66,7 +64,7 @@ class Guff::Models::ProjectModel < Guff::Models::Model set: " UPDATE projects - SET repo_url = ? + SET %s WHERE post_id = ? ", @@ -75,12 +73,13 @@ class Guff::Models::ProjectModel < Guff::Models::Model a.site_id, c.state, a.posted_at, - a.expires_at, a.slug, a.slug_lock, a.name, a.body, b.repo_url, + b.tag_prefix, + b.hook_secret, d.theme_id, e.theme_slug @@ -162,9 +161,6 @@ class Guff::Models::ProjectModel < Guff::Models::Model have_posted_at : Bool = false, posted_at : Time? = nil, - have_expires_at : Bool = false, - expires_at : Time? = nil, - slug : String? = nil, slug_lock : Bool? = nil, @@ -172,10 +168,15 @@ class Guff::Models::ProjectModel < Guff::Models::Model body : String? = nil, repo_url : String? = nil, + tag_prefix : String? = nil, + hook_secret : String? = nil, ) db = @context.dbs.rw db.transaction do + sql = [] of String + args = [] of String + @context.models.post.set( post_id: post_id, @@ -185,9 +186,6 @@ class Guff::Models::ProjectModel < Guff::Models::Model have_posted_at: have_posted_at, posted_at: posted_at, - have_expires_at: have_expires_at, - expires_at: expires_at, - slug: slug, slug_lock: slug_lock, @@ -195,9 +193,24 @@ class Guff::Models::ProjectModel < Guff::Models::Model body: body, ) - # puts "DEBUG: repo_url = #{repo_url}, post_id = #{post_id}" if repo_url - db.query(SQL[:set], [repo_url.to_s, post_id.to_s]) + sql << "repo_url = ?" + args << repo_url.to_s + end + + if tag_prefix + sql << "tag_prefix = ?" + args << tag_prefix.to_s + end + + if hook_secret + sql << "hook_secret = ?" + args << hook_secret.to_s + end + + if sql.size > 0 + args << post_id.to_s + db.query(SQL[:set] % sql.join(","), args) end end end |