aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/discussions_controller.rb
diff options
context:
space:
mode:
authorKir2011-10-31 21:43:34 +0400
committerKir2011-10-31 21:43:34 +0400
commit48c144ed34e2d5977bb8e5af8a9c7e8dfc253361 (patch)
treea672937fb96b955f3c2d4364195926b3b14d01cb /app/controllers/discussions_controller.rb
parent3ddd221f5f235e34afb9d4bbc7a4fc05228f73a4 (diff)
downloadinboxes-48c144ed34e2d5977bb8e5af8a9c7e8dfc253361.tar.bz2
Small changed
Diffstat (limited to 'app/controllers/discussions_controller.rb')
-rw-r--r--app/controllers/discussions_controller.rb42
1 files changed, 19 insertions, 23 deletions
diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb
index 7d5d8ca..8ea6459 100644
--- a/app/controllers/discussions_controller.rb
+++ b/app/controllers/discussions_controller.rb
@@ -1,6 +1,8 @@
class DiscussionsController < ApplicationController
- # load_and_authorize_resource
- # before_filter :load_and_check_discussion_recipient, :only => [:create, :new]
+ before_filter :authenticate_user!
+ before_filter :check_permissions, :only => :show
+
+ before_filter :load_and_check_discussion_recipient, :only => [:create, :new]
def index
# показываем дискуссии юзера, и те куда его присоеденили
@@ -17,53 +19,46 @@ class DiscussionsController < ApplicationController
# GET /discussions/1.json
def show
@discussion = Discussion.includes(:messages, :speakers).find(params[:id])
- # @discussion.mark_as_read_for(current_user) # сделаем прочтенной для пользователя
+ redirect_to root_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
- # члены дискуссии - приглашенные в нее + ее создатель
- @message = Message.new
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render :json => @discussion }
- end
+ @discussion.mark_as_read_for(current_user) # сделаем прочтенной для пользователя
end
# GET /discussions/new
# GET /discussions/new.json
def new
- @discussion = Discussion.new
+ # @discussion = Discussion.new
@discussion.messages.build
end
# POST /discussions
# POST /discussions.json
def create
- @discussion = Discussion.new(params[:discussion])
+ # @discussion = Discussion.new(params[:discussion])
+ @discussion.add_recipient_token current_user.id
+
@discussion.messages.each do |m|
m.discussion = @discussion
m.user = current_user
end
- @discussion.add_recipient_token current_user.id
- respond_to do |format|
- if @discussion.save
- format.html { redirect_to @discussion, :notice => 'Дискуссия начата.' }
- # format.json { render :json => @discussion, :status => :created, :location => @discussion }
- else
- format.html { render :action => "new" }
- # format.json { render :json => @discussion.errors, :status => :unprocessable_entity }
- end
+
+ if @discussion.save
+ redirect_to @discussion, :notice => t("views.discussions.started")
+ else
+ render :action => "new"
end
end
def leave
@discussion.remove_speaker(current_user)
- redirect_to discussions_url, :notice => "Вы успешно покинули дискуссию."
+ redirect_to discussions_url, :notice => t("views.discussions.leaved")
end
private
def load_and_check_discussion_recipient
+ @discussion = Discussion.new((params[:discussion] ? params[:discussion] : {}))
@discussion.recipient_tokens = params[:recipients] if params[:recipients]
# проверка, существует ли уже дискуссия с этим человеком
@@ -76,9 +71,10 @@ class DiscussionsController < ApplicationController
Message.create!(:discussion => discussion, :user => current_user, :body => m.body) if m.body
end
# перекидываем на нее
- redirect_to discussion_url(discussion), :notice => "Переписка между вами уже существует."
+ redirect_to discussion_url(discussion), :notice => t("views.discussions.exists", :user => user[Inboxes::config.user_name])
end
end
end
+
end