Skip to content

Commit

Permalink
Move a diary to forums
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Mar 21, 2011
1 parent 3bf3c80 commit 018c8ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
23 changes: 20 additions & 3 deletions app/controllers/diaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DiariesController < ApplicationController
before_filter :authenticate_account!, :except => [:index, :show]
before_filter :find_diary, :except => [:index, :new, :create]
after_filter :marked_as_read, :only => [:show], :if => :account_signed_in?
after_filter :expire_cache, :only => [:create, :update, :destroy]
after_filter :expire_cache, :only => [:create, :update, :destroy, :move]
caches_page :index, :if => Proc.new { |c| c.request.format.atom? && !c.request.ssl? }
respond_to :html, :atom

Expand Down Expand Up @@ -49,7 +49,7 @@ def update
enforce_update_permission(@diary)
@diary.attributes = params[:diary]
if !preview_mode && @diary.save
redirect_to [@user, @diary], :notice => "Votre journal a bien été modifié"
redirect_to [@user, @diary], :notice => "Le journal a bien été modifié"
else
flash.now[:alert] = "Impossible d'enregistrer ce journal" if @diary.invalid?
render :edit
Expand All @@ -59,7 +59,24 @@ def update
def destroy
enforce_destroy_permission(@diary)
@diary.mark_as_deleted
redirect_to diaries_url, :notice => "Votre journal a bien été supprimé"
redirect_to diaries_url, :notice => "Le journal a bien été supprimé"
end

def move
enforce_destroy_permission(@diary)
@post = Post.new(params[:post])
@post.title = @diary.title
@post.wiki_body = @diary.wiki_body
if @post.save
node = @post.node
node.attributes = @diary.node.attributes.except("id", "content_id", "content_type")
node.save
@diary.mark_as_deleted
redirect_to diaries_url, :notice => "Le journal a bien été déplacé vers les forums"
else
flash.now[:alert] = "Impossible de déplacer ce journal. Avez-vous bien choisi un forum ?"
render :edit
end
end

protected
Expand Down
7 changes: 7 additions & 0 deletions app/views/diaries/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
= form_for [@diary.owner, @diary] do |form|
= render form

%h2 Modération
= form_for Post.new, :url => move_user_diary_path(:user_id => @diary.owner, :id => @diary) do |form|
%p
= form.label :forum_id, "Forum"
= form.select :forum_id, forums_select_list, { :include_blank => true }, { :required => "required" }
%p
= form.submit "Déplacer vers les forums", :confirm => "Êtes-vous sûr de vouloir déplacer ce journal ?"
= button_to "Supprimer", [@diary.owner, @diary], :method => :delete, :confirm => "Êtes-vous sûr de vouloir supprimer ce journal ?"

= render 'shared/wiki_help'
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

# Diaries & Users
resources :users, :only => [:show] do
resources :journaux, :controller => "diaries", :as => "diaries", :except => [:index, :new, :create]
resources :journaux, :controller => "diaries", :as => "diaries", :except => [:index, :new, :create] do
post :move, :on => :member
end
get :news, :on => :member
get :posts, :on => :member
get :suivi, :on => :member
Expand Down

0 comments on commit 018c8ff

Please sign in to comment.