diff --git a/app/assets/images/coffee.jpg b/app/assets/images/coffee.jpg new file mode 100644 index 0000000..0c10aec Binary files /dev/null and b/app/assets/images/coffee.jpg differ diff --git a/app/assets/images/github.png b/app/assets/images/github.png new file mode 100644 index 0000000..a20d3ff Binary files /dev/null and b/app/assets/images/github.png differ diff --git a/app/assets/images/hero.jpg b/app/assets/images/hero.jpg new file mode 100644 index 0000000..2a211cc Binary files /dev/null and b/app/assets/images/hero.jpg differ diff --git a/app/assets/images/hero2.jpg b/app/assets/images/hero2.jpg new file mode 100644 index 0000000..33c5fd8 Binary files /dev/null and b/app/assets/images/hero2.jpg differ diff --git a/app/assets/images/linkedin.png b/app/assets/images/linkedin.png new file mode 100644 index 0000000..89f0ce5 Binary files /dev/null and b/app/assets/images/linkedin.png differ diff --git a/app/assets/images/twitter.png b/app/assets/images/twitter.png new file mode 100644 index 0000000..0bc14d9 Binary files /dev/null and b/app/assets/images/twitter.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bce1f1c..2d151d3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,6 +13,7 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap //= require bootstrap-sprockets //= require_tree . diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index afb0cc4..a22f7d5 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -15,6 +15,10 @@ *= @import "bootstrap-sprockets" @import "bootstrap" + @import "font-awesome"; + @import "bootstrap-social.less"; */ @import "bootstrap-sprockets"; @import "bootstrap"; + + diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index e5a51c3..49fad73 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -7,6 +7,8 @@ def index end def show + @articles = policy_scope(Article) + @comments = policy_scope(Comment) @article = Article.friendly.find(params[:id]) redirect_to @article, status: :moved_permanently unless request.path == article_path(@article) end @@ -17,7 +19,6 @@ def new def create @article = Article.new(article_params) - if @article.save redirect_to @article, notice: 'Article was successfully created.' current_user.articles << @article diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 126e7d5..007da95 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,4 +1,7 @@ class CommentsController < ApplicationController + before_action :authorize_comment, only: [:edit, :update] + before_action :set_comment, only: [:show, :edit, :update, :destroy] + def index @article = Article.friendly.find(params[:article_id]) @comments = @article.comments @@ -52,7 +55,15 @@ def destroy private + def set_comment + @comment = Comment.find(params[:id]) + end + + def authorize_comment + authorize Comment + end + def comment_params - params.require(:comment).permit(:commenter_name, :content) + params.require(:comment).permit(:commenter_name, :content, (:approved if current_user.role == "editor")) end end diff --git a/app/models/article.rb b/app/models/article.rb index 1cfefc9..cb5d203 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,5 +1,5 @@ class Article < ActiveRecord::Base - belongs_to :author, class_name: "User" + belongs_to :user #:author, class_name: "User" has_many :comments extend FriendlyId friendly_id :title, use: [:slugged, :history] diff --git a/app/models/user.rb b/app/models/user.rb index c6691a7..11241c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable - enum role: [:null_user, :author, :editor] + enum role: [:null_user, :author, :editor, :twitter_user] after_initialize :set_default_role, if: :new_record? has_many :articles, foreign_key: "author_id" diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 7a9d661..320ba0d 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -56,6 +56,10 @@ def editor? false end + def unauthenticated? + true + end + def author? false end diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 5324e6e..4525e63 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -1,16 +1,23 @@ class CommentPolicy < ApplicationPolicy class Scope < Scope + def initialize(user, scope) + @user = user + @scope = scope + end + def resolve if user.editor? scope.all + elsif !user.nil? + scope.all else - scope.where(published: true) + scope.where(approved: true) end end end def create? - user.editor? || user.author? + !user.unauthenticated? end def update? diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index b36ae0d..41d444b 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -13,18 +13,26 @@
By: <%= @article.author_id %>
<% if @article.published? %> -Status: Published
+Status: Published
<% else %>Status: Unpublished
<% end %> -<%= link_to 'Edit Article', edit_article_path(@article) %> | -<%= link_to 'Delete Article', @article, method: :delete, data: {confirm: 'Are you sure?' } %> | +<% @articles.each do |article| %> + <% if policy(article).update? %> + <%= link_to 'Edit Article', edit_article_path(@article) %> | + <%= link_to 'Delete Article', @article, method: :delete, data: {confirm: 'Are you sure?' } %> | + <% end %> +<% end %> <%= link_to 'Back', articles_path %> -<%=h c.commenter_name %>: <%=h c.content %>
diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index d8db672..a88e2c1 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -6,20 +6,20 @@<%= comment.commenter_name %> <%=comment.content %>
- <%# if policy(comment).update? %> + <% if policy(comment).update? %> <%= link_to 'Edit', edit_article_comment_path(@article, comment) %> - <%# end %> - <%# if policy(comment).destroy? %> + <% end %> + <% if policy(comment).destroy? %> <%= link_to 'Delete', article_comment_path(@article, comment), method: :delete, data: {confirm: 'Are you sure?' } %> - <%# end %> + <% end %> <% end %>
-
+ + Signed in as <%= current_user.name %>. Not you? <%= link_to 'Sign Out', destroy_user_session_path, :method => :delete %> +
+ <% else %> +<%= link_to 'Sign Up', new_user_registration_path %>, <%= link_to 'Sign In', new_user_session_path %>, or <%= link_to 'Sign in with Twitter', user_omniauth_authorize_path(:twitter) %>
+ <% end %> + <% flash.each do |key, value| %> +