diff --git a/app/controllers/forum/forum_categories_controller.rb b/app/controllers/forum/forum_categories_controller.rb index 96b6909..c58c937 100644 --- a/app/controllers/forum/forum_categories_controller.rb +++ b/app/controllers/forum/forum_categories_controller.rb @@ -3,6 +3,9 @@ class Forum::ForumCategoriesController < ApplicationController before_filter :auth_fuser + def index + @categories = ForumCategory.all + end def show @@ -25,7 +28,7 @@ class Forum::ForumCategoriesController < ApplicationController @category = ForumCategory.new(params.require(:forum_category).permit!) if @category.save - redirect_to forum_forum_path(@category.forum) + redirect_to forum_forum_categories_path else render :action => "new" @@ -36,7 +39,7 @@ class Forum::ForumCategoriesController < ApplicationController @category = ForumCategory.find(params[:id]) if @category.update_attributes(params.require(:forum_category).permit!) - redirect_to forum_forum_path(@category.forum) + redirect_to forum_forum_categories_path else render :action => "edit" @@ -49,7 +52,7 @@ class Forum::ForumCategoriesController < ApplicationController def destroy @category = ForumCategory.find(params[:id]) @category.destroy - redirect_to forum_forum_path(@category.forum) + redirect_to forum_forum_categories_path end diff --git a/app/controllers/forum/forum_messages_controller.rb b/app/controllers/forum/forum_messages_controller.rb index b22a922..fe9e0b5 100644 --- a/app/controllers/forum/forum_messages_controller.rb +++ b/app/controllers/forum/forum_messages_controller.rb @@ -34,8 +34,11 @@ class Forum::ForumMessagesController < ApplicationController end def update - - @message = ForumMessage.find(params[:id]) + if moderator? + @message = ForumMessage.find(params[:id]) + else + @message = current_fuser.messages.find(params[:id]) + end if @message.update_attributes(params.require(:forum_message).permit!) redirect_to forum_forum_topic_path(@message.forum_topic_id, :anchor => "forum_message_#{@message.id}") @@ -49,9 +52,11 @@ class Forum::ForumMessagesController < ApplicationController def destroy - @message = ForumMessage.find(params[:id]) - @message.destroy - redirect_to forum_forum_topic_path(@message.forum_topic_id) + if moderator? + @message = ForumMessage.find(params[:id]) + @message.destroy + redirect_to forum_forum_topic_path(@message.forum_topic_id) + end end diff --git a/app/controllers/forum/forum_topics_controller.rb b/app/controllers/forum/forum_topics_controller.rb index 20528f9..ae0b4a3 100644 --- a/app/controllers/forum/forum_topics_controller.rb +++ b/app/controllers/forum/forum_topics_controller.rb @@ -38,7 +38,11 @@ class Forum::ForumTopicsController < ApplicationController end def update - @topic = ForumTopic.find(params[:id]) + if moderator? + @topic = ForumTopic.find(params[:id]) + else + @topic = current_fuser.topics.find(params[:id]) + end if @topic.update_attributes(params.require(:forum_topic).permit!) redirect_to forum_forum_category_path(@topic.category) @@ -52,9 +56,11 @@ class Forum::ForumTopicsController < ApplicationController def destroy - @topic = ForumTopic.find(params[:id]) - @topic.destroy - redirect_to forum_forum_topics_path() + if moderator? + @topic = ForumTopic.find(params[:id]) + @topic.destroy + redirect_to forum_forum_topics_path() + end end diff --git a/app/controllers/forum/forum_users_controller.rb b/app/controllers/forum/forum_users_controller.rb index 6b4897e..085dc8f 100644 --- a/app/controllers/forum/forum_users_controller.rb +++ b/app/controllers/forum/forum_users_controller.rb @@ -42,23 +42,27 @@ class Forum::ForumUsersController < ApplicationController end def update - @user = ForumUser.find(params[:id]) + @user = ForumUser.find(params[:id]) + if @user == current_fuser or moderator? + - if @user.update_attributes(params.require(:forum_user).permit!) - redirect_to forum_forum_user_path(@user) + if @user.update_attributes(params.require(:forum_user).permit!) + redirect_to forum_forum_user_path(@user) - else - render :action => "edit" - end - + else + render :action => "edit" + end + end end def destroy - @user = ForumUser.find(params[:id]) - @user.destroy - redirect_to forum_forum_users_path + if moderator? + @user = ForumUser.find(params[:id]) + @user.destroy + redirect_to forum_forum_users_path + end end diff --git a/app/models/forum_user.rb b/app/models/forum_user.rb index ad50497..0b689e1 100644 --- a/app/models/forum_user.rb +++ b/app/models/forum_user.rb @@ -31,6 +31,8 @@ class ForumUser < ActiveRecord::Base end + elsif self.id + else errors.add :sheet_number, "Vous devez saisir votre numéro adhérent (présent en bas de chaque mails)." end diff --git a/app/views/forum/forum_categories/_forum_category.haml b/app/views/forum/forum_categories/_forum_category.haml index e2a10a6..405a707 100644 --- a/app/views/forum/forum_categories/_forum_category.haml +++ b/app/views/forum/forum_categories/_forum_category.haml @@ -1,15 +1,13 @@ %tr.category - - - - %td - %h2=link_to forum_category.title, [:forum, forum_category] - =markdown forum_category.description - %td - =forum_category.forum_topics.count - - -if moderator? - %td - =link_to "modifier", edit_forum_forum_category_path(forum_category) - =link_to "supprimer", [:forum, forum_category], :confirm => "Supprimer cette catégorie ?", :method => :delete - \ No newline at end of file + + + + %td + =link_to forum_category.title, [:forum, forum_category] + + + -if moderator? + %td + =link_to i(:pencil), edit_forum_forum_category_path(forum_category) + =link_to i(:"trash-o"), [:forum, forum_category], :confirm => "Supprimer cette catégorie ?", :method => :delete + \ No newline at end of file diff --git a/app/views/forum/forum_categories/index.haml b/app/views/forum/forum_categories/index.haml new file mode 100644 index 0000000..7c1680b --- /dev/null +++ b/app/views/forum/forum_categories/index.haml @@ -0,0 +1,12 @@ +=link_to "nouvel catégorie", new_forum_forum_category_path, :class => "btn btn-primary", :style => "margin:1em 0em;float:right" if moderator? + +%h1 Liste des catégories + +%table.table.table-hover.table-striped + %tr + + %th Nom + + -if moderator? + %th Actions + =render @categories \ No newline at end of file diff --git a/app/views/layouts/forum.haml b/app/views/layouts/forum.haml index baecd2e..778526b 100644 --- a/app/views/layouts/forum.haml +++ b/app/views/layouts/forum.haml @@ -45,6 +45,7 @@ %ul.nav %li=link_to "Fils de discussion", forum_forum_topics_path %li=link_to "Utilisateurs", forum_forum_users_path + %li=link_to "Catégories", forum_forum_categories_path if moderator? %ul.nav.pull-right