bongo 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2bc70af78c51e19b4b5604d0c34c6e07e3cf30a89d60800a0e4c6cf25b03506
4
- data.tar.gz: 02eb299fee060a5b1521c60e34ce38570849a265a5c2a330bfd28340686a125e
3
+ metadata.gz: bfa27b0833100b7eec1515acbaa7a569e69a3887fa8af9c831c1418b68228a8b
4
+ data.tar.gz: 627fa8516da9575c5176b475359a80c5d05bd0fd95895fdc0b97e7ccc1a09609
5
5
  SHA512:
6
- metadata.gz: c3bc88b9d3bea48d39eac422ffd9d5396ee2037347ace140acfd2eec6109ee7c31891eed7aa00eb49f263fe9c8e28bed72412f78d67d2db0720ee12208c007f8
7
- data.tar.gz: 360242447c9b911dad60780486b26739603bd31ee9af8b47aad668b42a9ae671d6fb172ab9f2e17a805d93c1493661916538907b5ca84e7ebd40dd54145014a6
6
+ metadata.gz: d13fe172bca2498ec4291e8b5159b78ad9cb815b0c18ba73c33e171c91a423c54f666b62cef885e3b7a1f99a09ec47e76d4f8a106fd5f5d2f63baba7859f49fd
7
+ data.tar.gz: ff322224d305491093e1aac80fdaf820e73d289217205f2111f31ed9ca9c90c8cd8be7ecaf2a686d1bda66a97cc77f89c9eb2c39a43171cdfaa61602000b36e7
@@ -2,9 +2,3 @@
2
2
  *= require_tree .
3
3
  *= require_self
4
4
  */
5
-
6
-
7
- .trix-content a {
8
- /* https://github.com/basecamp/trix/issues/142 */
9
- font-weight: normal;
10
- }
@@ -1,5 +1,4 @@
1
1
  module Bongo
2
- class ApplicationController < ActionController::Base
3
- protect_from_forgery with: :exception
2
+ class ApplicationController < ApplicationController
4
3
  end
5
4
  end
@@ -7,21 +7,32 @@ module Bongo
7
7
  before_action :set_article, only: [:show, :edit, :update, :destroy]
8
8
 
9
9
  def index
10
- @articles = Article.all.order(publish_at: :desc)
10
+ @articles = policy_scope(Article).order(publish_at: :desc)
11
+ respond_to do |format|
12
+ format.html
13
+ format.rss do
14
+ @articles = @articles.published.order(publish_at: :desc)
15
+ render layout: false
16
+ end
17
+ end
11
18
  end
12
19
 
13
20
  def show
21
+ authorize @article
14
22
  end
15
23
 
16
24
  def new
17
25
  @article = Article.new
26
+ authorize @article
18
27
  end
19
28
 
20
29
  def edit
30
+ authorize @article
21
31
  end
22
32
 
23
33
  def create
24
34
  @article = Article.new(article_params)
35
+ authorize @article
25
36
 
26
37
  if @article.save
27
38
  redirect_to @article, notice: 'Article was successfully created.'
@@ -31,6 +42,8 @@ module Bongo
31
42
  end
32
43
 
33
44
  def update
45
+ authorize @article
46
+
34
47
  if @article.update(article_params)
35
48
  redirect_to @article, notice: 'Article was successfully updated.'
36
49
  else
@@ -39,6 +52,7 @@ module Bongo
39
52
  end
40
53
 
41
54
  def destroy
55
+ authorize @article
42
56
  @article.destroy
43
57
  redirect_to articles_url, notice: 'Article was successfully destroyed.'
44
58
  end
@@ -5,5 +5,7 @@ module Bongo
5
5
  field :title, type: String
6
6
  field :text, type: String
7
7
  field :publish_at, type: Date
8
+
9
+ scope :published, -> { where(:publish_at.lte => Date.today) }
8
10
  end
9
11
  end
@@ -0,0 +1,29 @@
1
+ module Bongo
2
+ class ArticlePolicy < ApplicationPolicy
3
+ class Scope < Scope
4
+ def resolve
5
+ if user&.admin?
6
+ scope.all
7
+ else
8
+ scope.published
9
+ end
10
+ end
11
+ end
12
+
13
+ def show?
14
+ true
15
+ end
16
+
17
+ def create?
18
+ user&.admin?
19
+ end
20
+
21
+ def update?
22
+ user&.admin?
23
+ end
24
+
25
+ def destroy?
26
+ user&.admin?
27
+ end
28
+ end
29
+ end
@@ -24,6 +24,6 @@
24
24
  <button type="submit">Save</button>
25
25
 
26
26
  <%= link_to articles_path do %>
27
- <em>Back</em>
27
+ <em>Cancel</em>
28
28
  <% end %>
29
29
  <% end %>
@@ -1,16 +1,20 @@
1
1
  <% @articles.each do |article| %>
2
2
  <article>
3
- <h2><%= link_to article.title, article %></h2>
4
- <small><%= article.publish_at ? l(article.publish_at, format: :long) : "Unpublished draft"%></small>
5
- <main class="trix-content">
3
+ <header>
4
+ <h2><%= link_to article.title, article %></h2>
5
+ <small><%= article.publish_at ? l(article.publish_at, format: :long) : "Unpublished draft"%></small>
6
+ </header>
7
+ <div class="trix-content">
6
8
  <%= article.text.html_safe %>
7
- </main>
9
+ </div>
8
10
  </article>
9
11
  <br>
10
12
  <% end %>
11
13
 
12
14
  <br>
13
15
 
14
- <%= link_to new_article_path do %>
15
- <b>New Article</b>
16
+ <% if policy(Bongo::Article).create? %>
17
+ <%= link_to new_article_path do %>
18
+ <b>New Article</b>
19
+ <% end %>
16
20
  <% end %>
@@ -0,0 +1,18 @@
1
+ xml.instruct! :xml, version: "1.0"
2
+ xml.rss version: "2.0" do
3
+ xml.channel do
4
+ xml.title (Front.config.name rescue "My Blog")
5
+ xml.description (Front.config.name rescue "A bongo blog")
6
+ xml.link root_url
7
+
8
+ @articles.each do |article|
9
+ xml.item do
10
+ xml.title article.title
11
+ xml.description ActionView::Base.full_sanitizer.sanitize(article.text).truncate(180)
12
+ xml.pubDate article.publish_at.to_s(:rfc822)
13
+ xml.link article_url(article)
14
+ xml.guid article_url(article)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -3,21 +3,25 @@
3
3
  <h2><%= @article.title %></h2>
4
4
  <small><%= @article.publish_at ? l(@article.publish_at, format: :long) : "Unpublished draft"%></small>
5
5
  </header>
6
- <main class="trix-content">
7
- <%= @article.text.html_safe %>
8
- </main>
9
- </article>
10
6
 
11
- <br>
7
+ <div class="trix-content">
8
+ <%= @article.text.html_safe %>
9
+ </div>
12
10
 
13
- <%= link_to edit_article_path(@article) do %>
14
- <b>Edit</b>
15
- <% end %>
11
+ <footer>
12
+ <% if policy(@article).update? %>
13
+ <%= link_to edit_article_path(@article) do %>
14
+ <b>Edit</b>
15
+ <% end %>
16
+ <% end %>
16
17
 
17
- <%= link_to @article, method: :delete, data: {confirm: "Are you sure?"} do %>
18
- <em>Delete</em>
19
- <% end %>
18
+ <% if policy(@article).destroy? %>
19
+ <%= link_to @article, method: :delete, data: {confirm: "Are you sure?"} do %>
20
+ <em>Delete</em>
21
+ <% end %>
22
+ <% end %>
20
23
 
21
- <%= link_to articles_path do %>
22
- <em>Back</em>
23
- <% end %>
24
+ <br>
25
+ <%= link_to 'Back', articles_path %>
26
+ </footer>
27
+ </article>
@@ -2,4 +2,8 @@
2
2
  Blog
3
3
  <% end %>
4
4
 
5
+ <% content_for :head do %>
6
+ <%= auto_discovery_link_tag :rss, articles_url(format: :rss) %>
7
+ <% end %>
8
+
5
9
  <%= render template: "layouts/application" %>
@@ -1,3 +1,3 @@
1
1
  module Bongo
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Hutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-23 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pundit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
55
69
  description: Rails engine for blogging using MongoDB.
56
70
  email:
57
71
  - tohu@tuta.io
@@ -76,10 +90,12 @@ files:
76
90
  - app/jobs/bongo/application_job.rb
77
91
  - app/mailers/bongo/application_mailer.rb
78
92
  - app/models/bongo/article.rb
93
+ - app/policies/bongo/article_policy.rb
79
94
  - app/views/bongo/articles/_form.html.erb
80
95
  - app/views/bongo/articles/_notice.html.erb
81
96
  - app/views/bongo/articles/edit.html.erb
82
97
  - app/views/bongo/articles/index.html.erb
98
+ - app/views/bongo/articles/index.rss.builder
83
99
  - app/views/bongo/articles/new.html.erb
84
100
  - app/views/bongo/articles/show.html.erb
85
101
  - app/views/layouts/bongo/application.html.erb