diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d5731bc..47dbbd9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,7 +5,15 @@ class UsersController < ApplicationController # GET /users # GET /users.json def index - @users = User.all + if logged_in? + if current_user.admin + @users = User.all + else + redirect_to home_path + end + else + redirect_to home_path + end end # GET /users/1 @@ -52,11 +60,20 @@ def update # DELETE /users/1 # DELETE /users/1.json def destroy - @user.destroy - respond_to do |format| - format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } - format.json { head :no_content } + if logged_in? + if current_user.admin + @user.destroy + respond_to do |format| + format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + format.json { head :no_content } + end + else + redirect_to home_path + end + else + redirect_to home_path end + end private diff --git a/app/views/people/approve_comments.html.erb b/app/views/people/approve_comments.html.erb index cabb9f5..c9649d0 100644 --- a/app/views/people/approve_comments.html.erb +++ b/app/views/people/approve_comments.html.erb @@ -1,9 +1,18 @@ -<% @comments.each do |comment| %> -
- <%= comment.name %> - <%= comment.body %> - <%= comment.approved %> - <%= button_to "Destroy", person_comment_path(comment.person_id, comment.id), method: :delete, data: { confirm: 'Are you sure?' } %> - <%= button_to "Approve", person_comment_approve_path(comment.person_id, comment.id), method: :put %> -
-<% end %> +<% if current_user.person_id == @person.id %> + <% if @comments.count != 0 %> + <% @comments.each do |comment| %> ++ <%= comment.name %> + <%= comment.body %> + <%= comment.approved %> + <%= button_to "Destroy", person_comment_path(comment.person_id, comment.id), method: :delete, data: { confirm: 'Are you sure?' } %> + <%= button_to "Approve", person_comment_approve_path(comment.person_id, comment.id), method: :put %> +
+ <% end %> + <% else %> +No new comments. + <%= link_to "Back", 'javascript:history.go(-1);' %> +
+ + <% end %> +<%end%> diff --git a/app/views/people/show.html.erb b/app/views/people/show.html.erb index 0ccd369..5e71348 100644 --- a/app/views/people/show.html.erb +++ b/app/views/people/show.html.erb @@ -4,9 +4,13 @@ <%= @person.bio %> <%= @person.link%> <%= image_tag @person.image.url(:thumb) %> - <%= link_to 'Edit Profile', edit_person_path(@person) %> - <%= link_to 'Destroy', @person, method: :delete, data: { confirm: 'Are you sure?' } %> - <%= link_to 'Back', home_path %> + <% if !current_user.nil? && current_user.person_id == @person.id %> + <%= link_to 'Edit Profile', edit_person_path(@person) %> + <%= link_to 'Destroy', @person, method: :delete, data: { confirm: 'Are you sure?' } %> + <%= link_to "Approve Comments", approve_the_comments_path(@person) %> + <% end %> + + <%= link_to 'Back', 'javascript:history.go(-1);' %> <% @comments.each do |comment| %>diff --git a/config/routes.rb b/config/routes.rb index 09ee021..304cf93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,11 @@ Rails.application.routes.draw do - root :to => 'users#index' + root :to => 'static_pages#home' resources :user_sessions resources :users get 'login' => 'user_sessions#new', :as => :login post 'logout' => 'user_sessions#destroy', :as => :logout - get '/people/:person_id/approve_comments' => 'people#approve_comments' + get '/people/:person_id/approve_comments' => 'people#approve_comments', :as => 'approve_the_comments' get 'home' => 'static_pages#home' diff --git a/db/migrate/20150924005047_add_admin_column_to_users.rb b/db/migrate/20150924005047_add_admin_column_to_users.rb new file mode 100644 index 0000000..0625adb --- /dev/null +++ b/db/migrate/20150924005047_add_admin_column_to_users.rb @@ -0,0 +1,5 @@ +class AddAdminColumnToUsers < ActiveRecord::Migration + def change + add_column :users, :admin, :boolean, :default =>false + end +end diff --git a/db/schema.rb b/db/schema.rb index 85918c8..746ea3e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150924000916) do +ActiveRecord::Schema.define(version: 20150924005047) do create_table "comments", force: :cascade do |t| t.string "name" @@ -36,13 +36,14 @@ end create_table "users", force: :cascade do |t| - t.string "email", null: false + t.string "email", null: false t.string "crypted_password" t.string "salt" t.datetime "created_at" t.datetime "updated_at" t.integer "person_id" t.integer "sessions", default: 0 + t.boolean "admin", default: false end add_index "users", ["email"], name: "index_users_on_email", unique: true diff --git a/public/system/people/images/000/000/002/medium/working.jpg b/public/system/people/images/000/000/002/medium/working.jpg new file mode 100644 index 0000000..4fb9fc7 Binary files /dev/null and b/public/system/people/images/000/000/002/medium/working.jpg differ diff --git a/public/system/people/images/000/000/002/original/working.jpg b/public/system/people/images/000/000/002/original/working.jpg new file mode 100644 index 0000000..015fc69 Binary files /dev/null and b/public/system/people/images/000/000/002/original/working.jpg differ diff --git a/public/system/people/images/000/000/002/thumb/working.jpg b/public/system/people/images/000/000/002/thumb/working.jpg new file mode 100644 index 0000000..9dc82f7 Binary files /dev/null and b/public/system/people/images/000/000/002/thumb/working.jpg differ