From d45ca752c4e6e180bc551a5277710b9e4d4d075f Mon Sep 17 00:00:00 2001 From: yasushiito Date: Wed, 4 Jan 2012 08:38:10 +0900 Subject: [PATCH] speach balloon permission change to admin --- app/controllers/balloon_templates_controller.rb | 74 +---------------------- app/controllers/speach_balloons_controller.rb | 4 +- app/controllers/speach_templates_controller.rb | 74 +---------------------- app/models/admin.rb | 5 +- app/views/speach_balloons/index.html.erb | 7 ++- app/views/system/index.html.erb | 2 +- config/routes.rb | 11 ++-- db/migrate/20111206092734_devise_create_admins.rb | 4 +- db/schema.rb | 2 + 9 files changed, 24 insertions(+), 159 deletions(-) diff --git a/app/controllers/balloon_templates_controller.rb b/app/controllers/balloon_templates_controller.rb index a1ef2512..22728cea 100644 --- a/app/controllers/balloon_templates_controller.rb +++ b/app/controllers/balloon_templates_controller.rb @@ -1,5 +1,5 @@ class BalloonTemplatesController < ApplicationController - before_filter :authenticate_author!, :except => [:index] + before_filter :authenticate_admin!, :except => [:index] # GET /balloon_templates # GET /balloon_templates.json @@ -11,76 +11,4 @@ class BalloonTemplatesController < ApplicationController format.json { render json: @balloon_templates } end end -=begin - # GET /balloon_templates/1 - # GET /balloon_templates/1.json - def show - @balloon_template = BalloonTemplate.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @balloon_template } - end - end - - # GET /balloon_templates/new - # GET /balloon_templates/new.json - def new - @balloon_template = BalloonTemplate.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @balloon_template } - end - end - - # GET /balloon_templates/1/edit - def edit - @balloon_template = BalloonTemplate.find(params[:id]) - end - - # POST /balloon_templates - # POST /balloon_templates.json - def create - @balloon_template = BalloonTemplate.new(params[:balloon_template]) - - respond_to do |format| - if @balloon_template.save - format.html { redirect_to @balloon_template, notice: 'Balloon template was successfully created.' } - format.json { render json: @balloon_template, status: :created, location: @balloon_template } - else - format.html { render action: "new" } - format.json { render json: @balloon_template.errors, status: :unprocessable_entity } - end - end - end - - # PUT /balloon_templates/1 - # PUT /balloon_templates/1.json - def update - @balloon_template = BalloonTemplate.find(params[:id]) - - respond_to do |format| - if @balloon_template.update_attributes(params[:balloon_template]) - format.html { redirect_to @balloon_template, notice: 'Balloon template was successfully updated.' } - format.json { head :ok } - else - format.html { render action: "edit" } - format.json { render json: @balloon_template.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /balloon_templates/1 - # DELETE /balloon_templates/1.json - def destroy - @balloon_template = BalloonTemplate.find(params[:id]) - @balloon_template.destroy - - respond_to do |format| - format.html { redirect_to balloon_templates_url } - format.json { head :ok } - end - end -=end end diff --git a/app/controllers/speach_balloons_controller.rb b/app/controllers/speach_balloons_controller.rb index 32974949..54d0f298 100644 --- a/app/controllers/speach_balloons_controller.rb +++ b/app/controllers/speach_balloons_controller.rb @@ -1,5 +1,6 @@ class SpeachBalloonsController < ApplicationController - before_filter :authenticate_author!, :except => [:index] + before_filter :authenticate_author!, :only => [:index] + before_filter :authenticate_admin!, :except => [:index] private @@ -79,7 +80,6 @@ class SpeachBalloonsController < ApplicationController # POST /speach_balloons.json def create @speach_balloon = SpeachBalloon.new(params[:speach_balloon]) - if em = validate_param(params[:speach_balloon]) respond_to do |format| format.json { render json: em, status: :unprocessable_entity } diff --git a/app/controllers/speach_templates_controller.rb b/app/controllers/speach_templates_controller.rb index 401844dd..d8bb57a9 100644 --- a/app/controllers/speach_templates_controller.rb +++ b/app/controllers/speach_templates_controller.rb @@ -1,5 +1,5 @@ class SpeachTemplatesController < ApplicationController - before_filter :authenticate_author!, :except => [:index] + before_filter :authenticate_admin!, :except => [:index] # GET /speach_templates # GET /speach_templates.json @@ -12,76 +12,4 @@ class SpeachTemplatesController < ApplicationController end end -=begin - # GET /speach_templates/1 - # GET /speach_templates/1.json - def show - @speach_template = SpeachTemplate.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @speach_template } - end - end - - # GET /speach_templates/new - # GET /speach_templates/new.json - def new - @speach_template = SpeachTemplate.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @speach_template } - end - end - - # GET /speach_templates/1/edit - def edit - @speach_template = SpeachTemplate.find(params[:id]) - end - - # POST /speach_templates - # POST /speach_templates.json - def create - @speach_template = SpeachTemplate.new(params[:speach_template]) - - respond_to do |format| - if @speach_template.save - format.html { redirect_to @speach_template, notice: 'Speach template was successfully created.' } - format.json { render json: @speach_template, status: :created, location: @speach_template } - else - format.html { render action: "new" } - format.json { render json: @speach_template.errors, status: :unprocessable_entity } - end - end - end - - # PUT /speach_templates/1 - # PUT /speach_templates/1.json - def update - @speach_template = SpeachTemplate.find(params[:id]) - - respond_to do |format| - if @speach_template.update_attributes(params[:speach_template]) - format.html { redirect_to @speach_template, notice: 'Speach template was successfully updated.' } - format.json { head :ok } - else - format.html { render action: "edit" } - format.json { render json: @speach_template.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /speach_templates/1 - # DELETE /speach_templates/1.json - def destroy - @speach_template = SpeachTemplate.find(params[:id]) - @speach_template.destroy - - respond_to do |format| - format.html { redirect_to speach_templates_url } - format.json { head :ok } - end - end -=end end diff --git a/app/models/admin.rb b/app/models/admin.rb index ca1d7234..eee4ac46 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -1,11 +1,12 @@ class Admin < ActiveRecord::Base # Include default devise modules. Others available are: - # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable + # , :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me + before_save :ensure_authentication_token def self.start(email, passwd) Admin.create! :email => email, :password => passwd, :password_confirmation => passwd, :activate => 1 diff --git a/app/views/speach_balloons/index.html.erb b/app/views/speach_balloons/index.html.erb index 648f9bc2..bb51d37a 100644 --- a/app/views/speach_balloons/index.html.erb +++ b/app/views/speach_balloons/index.html.erb @@ -1,11 +1,11 @@

Listing speach_balloons

- + <% @speach_balloons.each do |speach_balloon| %> @@ -14,6 +14,11 @@ + <% end %>
Name Tail limit Border limit
<%= speach_balloon.tail_limit %> <%= speach_balloon.border_limit %> <%= link_to 'show', speach_balloon %> + <% if admin_signed_in? -%> + <%= link_to 'Destroy', speach_balloon, confirm: 'Are you sure?', method: :delete %> + <% end -%> +
diff --git a/app/views/system/index.html.erb b/app/views/system/index.html.erb index 5c66bd66..3d98020d 100644 --- a/app/views/system/index.html.erb +++ b/app/views/system/index.html.erb @@ -1 +1 @@ - <%# current_admin.authentication_token %> +authentication_token:<%= current_admin.authentication_token %> diff --git a/config/routes.rb b/config/routes.rb index fe47bc6d..2567080b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,11 +31,12 @@ Pettanr::Application.routes.draw do match 'resource_pictures/:subdir/:id(.:format)/' => 'resource_pictures#show' match 'home/(:action)', :controller => 'home' match 'help/(:action)', :controller => 'help' - controller 'system' do - get 'start' - get 'index' -# match 'start', :to => 'system#start' - end + match 'system/(:action)', :controller => 'system' +# controller 'system' do +# get 'start' +# get 'index' +## match 'start', :to => 'system#start' +# end # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase diff --git a/db/migrate/20111206092734_devise_create_admins.rb b/db/migrate/20111206092734_devise_create_admins.rb index e7bb867e..871148e5 100644 --- a/db/migrate/20111206092734_devise_create_admins.rb +++ b/db/migrate/20111206092734_devise_create_admins.rb @@ -9,7 +9,7 @@ class DeviseCreateAdmins < ActiveRecord::Migration # t.encryptable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both - # t.token_authenticatable + t.token_authenticatable t.integer :activate, :null => false, :default => 0 t.timestamps @@ -19,7 +19,7 @@ class DeviseCreateAdmins < ActiveRecord::Migration add_index :admins, :reset_password_token, :unique => true # add_index :admins, :confirmation_token, :unique => true # add_index :admins, :unlock_token, :unique => true - # add_index :admins, :authentication_token, :unique => true + add_index :admins, :authentication_token, :unique => true end end diff --git a/db/schema.rb b/db/schema.rb index b1a4f0bc..c2ba199f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -24,11 +24,13 @@ ActiveRecord::Schema.define(:version => 20120102071851) do t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" + t.string "authentication_token" t.integer "activate", :default => 0, :null => false t.datetime "created_at" t.datetime "updated_at" end + add_index "admins", ["authentication_token"], :name => "index_admins_on_authentication_token", :unique => true add_index "admins", ["email"], :name => "index_admins_on_email", :unique => true add_index "admins", ["reset_password_token"], :name => "index_admins_on_reset_password_token", :unique => true -- 2.11.0