diff options
Diffstat (limited to 'app/controllers/admin')
| -rw-r--r-- | app/controllers/admin/blogs_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/admin/comments_controller.rb | 93 | ||||
| -rw-r--r-- | app/controllers/admin/games_controller.rb | 56 | ||||
| -rw-r--r-- | app/controllers/admin/links_controller.rb | 52 | ||||
| -rw-r--r-- | app/controllers/admin/quotes_controller.rb | 54 | ||||
| -rw-r--r-- | app/controllers/admin/streams_controller.rb | 4 | ||||
| -rw-r--r-- | app/controllers/admin/updates_controller.rb | 2 |
7 files changed, 262 insertions, 6 deletions
| diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index 1035c12..35f3514 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb | |||
| @@ -13,7 +13,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 13 | @blog = Blog.find(params[:id]) | 13 | @blog = Blog.find(params[:id]) |
| 14 | 14 | ||
| 15 | if @blog.published | 15 | if @blog.published |
| 16 | redirect_to blog_url(@blog.slug) | 16 | redirect_to @blog |
| 17 | else | 17 | else |
| 18 | render layout: "application" | 18 | render layout: "application" |
| 19 | end | 19 | end |
| @@ -25,6 +25,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 25 | 25 | ||
| 26 | def create | 26 | def create |
| 27 | @blog = Blog.new(blog_params) | 27 | @blog = Blog.new(blog_params) |
| 28 | @blog.user = current_user | ||
| 28 | 29 | ||
| 29 | if @blog.save | 30 | if @blog.save |
| 30 | flash.notice = "Blog created successfully!" | 31 | flash.notice = "Blog created successfully!" |
| @@ -44,7 +45,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 44 | def update | 45 | def update |
| 45 | @blog = Blog.find(params[:id]) | 46 | @blog = Blog.find(params[:id]) |
| 46 | 47 | ||
| 47 | if @blog.update_attributes(blog_params) | 48 | if @blog.update(blog_params) |
| 48 | flash.notice = "Blog updated successfully!" | 49 | flash.notice = "Blog updated successfully!" |
| 49 | else | 50 | else |
| 50 | flash.alert = "Error updating blog." | 51 | flash.alert = "Error updating blog." |
| @@ -56,7 +57,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 56 | private | 57 | private |
| 57 | 58 | ||
| 58 | def blog_params | 59 | def blog_params |
| 59 | params.require(:blog).permit(:title, :body, :slug, :published, records_attributes: [:description, :_destroy]) | 60 | params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, images: [], records_attributes: [:description, :_destroy]) |
| 60 | end | 61 | end |
| 61 | 62 | ||
| 62 | def set_section | 63 | def set_section |
| diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb new file mode 100644 index 0000000..4d9502d --- /dev/null +++ b/app/controllers/admin/comments_controller.rb | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | class Admin::CommentsController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @comments = Comment.where(status: :published).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) | ||
| 6 | end | ||
| 7 | |||
| 8 | def pending | ||
| 9 | @comments = Comment.where(status: :pending).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) | ||
| 10 | end | ||
| 11 | |||
| 12 | def accept | ||
| 13 | @comment = Comment.find(params[:id]) | ||
| 14 | @comment.status = :published | ||
| 15 | @comment.save! | ||
| 16 | |||
| 17 | if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email and @comment.reply_to.email != current_user.email | ||
| 18 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | ||
| 19 | end | ||
| 20 | |||
| 21 | flash.notice = "Comment successfully published." | ||
| 22 | redirect_to pending_admin_comments_url | ||
| 23 | end | ||
| 24 | |||
| 25 | def reject | ||
| 26 | @comment = Comment.find(params[:id]) | ||
| 27 | @comment.status = :rejected | ||
| 28 | @comment.save! | ||
| 29 | |||
| 30 | flash.notice = "Comment successfully rejected." | ||
| 31 | redirect_to pending_admin_comments_url | ||
| 32 | end | ||
| 33 | |||
| 34 | def mark_spam | ||
| 35 | @comment = Comment.find(params[:id]) | ||
| 36 | perform_mark_spam(@comment) | ||
| 37 | |||
| 38 | flash.notice = "Comment successfully marked as spam." | ||
| 39 | redirect_back fallback_location: pending_admin_comments_url | ||
| 40 | end | ||
| 41 | |||
| 42 | def destroy | ||
| 43 | if Comment.destroy(params[:id]) | ||
| 44 | flash.notice = "Comment successfully deleted." | ||
| 45 | else | ||
| 46 | flash.alert = "Could not delete comment." | ||
| 47 | end | ||
| 48 | |||
| 49 | redirect_to admin_comments_url | ||
| 50 | end | ||
| 51 | |||
| 52 | def mass | ||
| 53 | if params[:mass_action] == "Delete" | ||
| 54 | Comment.destroy_by(id: params[:comment_ids]) | ||
| 55 | |||
| 56 | flash.notice = "Comments successfully deleted." | ||
| 57 | elsif params[:mass_action] == "Mark Spam" | ||
| 58 | @comments = Comment.find(params[:comment_ids]) | ||
| 59 | |||
| 60 | @comments.each do |comment| | ||
| 61 | perform_mark_spam(comment) | ||
| 62 | end | ||
| 63 | |||
| 64 | flash.notice = "Comments successfully marked as spam." | ||
| 65 | end | ||
| 66 | |||
| 67 | redirect_back fallback_location: pending_admin_comments_url | ||
| 68 | end | ||
| 69 | |||
| 70 | private | ||
| 71 | |||
| 72 | def set_section | ||
| 73 | @section = "comments" | ||
| 74 | end | ||
| 75 | |||
| 76 | def perform_mark_spam(comment) | ||
| 77 | akismet_params = { | ||
| 78 | type: "comment", | ||
| 79 | text: comment.body, | ||
| 80 | created_at: comment.created_at, | ||
| 81 | author: comment.username, | ||
| 82 | author_email: comment.email, | ||
| 83 | author_url: comment.website, | ||
| 84 | post_url: url_for(comment.blog), | ||
| 85 | post_modified_at: comment.blog.updated_at, | ||
| 86 | referrer: comment.referrer | ||
| 87 | } | ||
| 88 | |||
| 89 | Akismet.spam comment.request_ip, comment.user_agent, akismet_params | ||
| 90 | |||
| 91 | comment.destroy! | ||
| 92 | end | ||
| 93 | end | ||
| diff --git a/app/controllers/admin/games_controller.rb b/app/controllers/admin/games_controller.rb new file mode 100644 index 0000000..2da1e95 --- /dev/null +++ b/app/controllers/admin/games_controller.rb | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | class Admin::GamesController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @games = Game.order(created_at: :desc) | ||
| 6 | end | ||
| 7 | |||
| 8 | def drafts | ||
| 9 | @games = Game.where(created_at: :desc) | ||
| 10 | end | ||
| 11 | |||
| 12 | def new | ||
| 13 | @game = Game.new | ||
| 14 | end | ||
| 15 | |||
| 16 | def create | ||
| 17 | @game = Game.new(game_params) | ||
| 18 | |||
| 19 | if @game.save | ||
| 20 | flash.notice = "Game created successfully!" | ||
| 21 | |||
| 22 | render :edit | ||
| 23 | else | ||
| 24 | flash.alert = "Error creating game." | ||
| 25 | |||
| 26 | render :new | ||
| 27 | end | ||
| 28 | end | ||
| 29 | |||
| 30 | def edit | ||
| 31 | @game = Game.find(params[:id]) | ||
| 32 | end | ||
| 33 | |||
| 34 | def update | ||
| 35 | @game = Game.find(params[:id]) | ||
| 36 | |||
| 37 | if @game.update(game_params) | ||
| 38 | flash.notice = "Game updated successfully!" | ||
| 39 | else | ||
| 40 | flash.alert = "Error updating game." | ||
| 41 | end | ||
| 42 | |||
| 43 | render :edit | ||
| 44 | end | ||
| 45 | |||
| 46 | private | ||
| 47 | |||
| 48 | def game_params | ||
| 49 | params.require(:game).permit(:title, :description, :status, :progress, :score, :started_on, :finished_on) | ||
| 50 | end | ||
| 51 | |||
| 52 | def set_section | ||
| 53 | @section = "games" | ||
| 54 | end | ||
| 55 | |||
| 56 | end | ||
| diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb new file mode 100644 index 0000000..54f245a --- /dev/null +++ b/app/controllers/admin/links_controller.rb | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | class Admin::LinksController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @links = Link.order(created_at: :desc) | ||
| 6 | end | ||
| 7 | |||
| 8 | def new | ||
| 9 | @link = Link.new | ||
| 10 | end | ||
| 11 | |||
| 12 | def create | ||
| 13 | @link = Link.new(link_params) | ||
| 14 | |||
| 15 | if @link.save | ||
| 16 | flash.notice = "Link created successfully!" | ||
| 17 | |||
| 18 | render :edit | ||
| 19 | else | ||
| 20 | flash.alert = "Error creating link." | ||
| 21 | |||
| 22 | render :new | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | def edit | ||
| 27 | @link = Link.find(params[:id]) | ||
| 28 | end | ||
| 29 | |||
| 30 | def update | ||
| 31 | @link = Link.find(params[:id]) | ||
| 32 | |||
| 33 | if @link.update(link_params) | ||
| 34 | flash.notice = "Link updated successfully!" | ||
| 35 | else | ||
| 36 | flash.alert = "Error updating link." | ||
| 37 | end | ||
| 38 | |||
| 39 | render :edit | ||
| 40 | end | ||
| 41 | |||
| 42 | private | ||
| 43 | |||
| 44 | def link_params | ||
| 45 | params.require(:link).permit(:title, :url, :tag_list, records_attributes: [:description, :_destroy]) | ||
| 46 | end | ||
| 47 | |||
| 48 | def set_section | ||
| 49 | @section = "links" | ||
| 50 | end | ||
| 51 | |||
| 52 | end | ||
| diff --git a/app/controllers/admin/quotes_controller.rb b/app/controllers/admin/quotes_controller.rb new file mode 100644 index 0000000..3623463 --- /dev/null +++ b/app/controllers/admin/quotes_controller.rb | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | class Admin::QuotesController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 20) | ||
| 6 | end | ||
| 7 | |||
| 8 | def pending | ||
| 9 | @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20) | ||
| 10 | end | ||
| 11 | |||
| 12 | def edit | ||
| 13 | @quote = Quote.find(params[:id]) | ||
| 14 | end | ||
| 15 | |||
| 16 | def update | ||
| 17 | @quote = Quote.find(params[:id]) | ||
| 18 | |||
| 19 | if @quote.update(quote_params) | ||
| 20 | flash[:notice] = "Quote was successfully updated." | ||
| 21 | else | ||
| 22 | flash[:error] = "Error updating quote." | ||
| 23 | end | ||
| 24 | |||
| 25 | render :edit | ||
| 26 | end | ||
| 27 | |||
| 28 | def accept | ||
| 29 | @quote = Quote.find(params[:id]) | ||
| 30 | @quote.state = :published | ||
| 31 | @quote.save! | ||
| 32 | |||
| 33 | flash.notice = "Quote successfully accepted." | ||
| 34 | redirect_to pending_admin_quotes_url | ||
| 35 | end | ||
| 36 | |||
| 37 | def destroy | ||
| 38 | @quote = Quote.find(params[:id]) | ||
| 39 | @quote.destroy! | ||
| 40 | |||
| 41 | flash.notice = "Quote successfully rejected." | ||
| 42 | redirect_to pending_admin_quotes_url | ||
| 43 | end | ||
| 44 | |||
| 45 | private | ||
| 46 | |||
| 47 | def set_section | ||
| 48 | @section = "quotes" | ||
| 49 | end | ||
| 50 | |||
| 51 | def quote_params | ||
| 52 | params.require(:quote).permit(:content, :state, :notes, :submitter, :tag_list, :audio) | ||
| 53 | end | ||
| 54 | end | ||
| diff --git a/app/controllers/admin/streams_controller.rb b/app/controllers/admin/streams_controller.rb index 86dec06..91ecc31 100644 --- a/app/controllers/admin/streams_controller.rb +++ b/app/controllers/admin/streams_controller.rb | |||
| @@ -30,7 +30,7 @@ class Admin::StreamsController < Admin::AdminController | |||
| 30 | def update | 30 | def update |
| 31 | @stream = Stream.find(params[:id]) | 31 | @stream = Stream.find(params[:id]) |
| 32 | 32 | ||
| 33 | if @stream.update_attributes(stream_params) | 33 | if @stream.update(stream_params) |
| 34 | flash.notice = "Stream updated successfully!" | 34 | flash.notice = "Stream updated successfully!" |
| 35 | else | 35 | else |
| 36 | flash.alert = "Error updating stream." | 36 | flash.alert = "Error updating stream." |
| @@ -42,7 +42,7 @@ class Admin::StreamsController < Admin::AdminController | |||
| 42 | private | 42 | private |
| 43 | 43 | ||
| 44 | def stream_params | 44 | def stream_params |
| 45 | params.require(:stream).permit(:title, :body, :slug, records_attributes: [:description, :_destroy]) | 45 | params.require(:stream).permit(:title, :body, :slug, :tag_list, records_attributes: [:description, :_destroy]) |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | def set_section | 48 | def set_section |
| diff --git a/app/controllers/admin/updates_controller.rb b/app/controllers/admin/updates_controller.rb index 9bf9caf..226daa5 100644 --- a/app/controllers/admin/updates_controller.rb +++ b/app/controllers/admin/updates_controller.rb | |||
| @@ -30,7 +30,7 @@ class Admin::UpdatesController < Admin::AdminController | |||
| 30 | @stream = Stream.find(params[:stream_id]) | 30 | @stream = Stream.find(params[:stream_id]) |
| 31 | @update = Update.find(params[:id]) | 31 | @update = Update.find(params[:id]) |
| 32 | 32 | ||
| 33 | if @update.update_attributes(update_params) | 33 | if @update.update(update_params) |
| 34 | flash.notice = "Update updated successfully!" | 34 | flash.notice = "Update updated successfully!" |
| 35 | else | 35 | else |
| 36 | flash.alert = "Error updating update." | 36 | flash.alert = "Error updating update." |
