inboxes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/inboxes/base_controller.rb +4 -0
- data/app/controllers/inboxes/discussions_controller.rb +8 -6
- data/app/controllers/inboxes/messages_controller.rb +11 -5
- data/app/controllers/inboxes/speakers_controller.rb +5 -11
- data/app/views/inboxes/discussions/index.html.haml +0 -2
- data/config/locales/ru.yml +2 -2
- data/inboxes.gemspec +1 -0
- data/lib/inboxes/ability.rb +24 -0
- data/lib/inboxes/engine.rb +5 -0
- data/lib/inboxes/version.rb +1 -1
- metadata +23 -8
@@ -1,6 +1,7 @@
|
|
1
1
|
class Inboxes::DiscussionsController < Inboxes::BaseController
|
2
|
-
|
3
|
-
before_filter :
|
2
|
+
load_and_authorize_resource
|
3
|
+
# before_filter :authenticate_user!
|
4
|
+
# before_filter :init_and_check_permissions, :only => :show
|
4
5
|
before_filter :load_and_check_discussion_recipient, :only => [:create, :new]
|
5
6
|
|
6
7
|
def index
|
@@ -10,6 +11,7 @@ class Inboxes::DiscussionsController < Inboxes::BaseController
|
|
10
11
|
# GET /discussions/1
|
11
12
|
# GET /discussions/1.json
|
12
13
|
def show
|
14
|
+
# @discussion = Discussion.includes(:messages, :speakers).find(params[:id])
|
13
15
|
@discussion.mark_as_read_for(current_user)
|
14
16
|
end
|
15
17
|
|
@@ -40,10 +42,10 @@ class Inboxes::DiscussionsController < Inboxes::BaseController
|
|
40
42
|
|
41
43
|
private
|
42
44
|
|
43
|
-
def init_and_check_permissions
|
44
|
-
|
45
|
-
|
46
|
-
end
|
45
|
+
# def init_and_check_permissions
|
46
|
+
# @discussion = Discussion.includes(:messages, :speakers).find(params[:id])
|
47
|
+
# redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
|
48
|
+
# end
|
47
49
|
|
48
50
|
def load_and_check_discussion_recipient
|
49
51
|
# initializing model fir new and create actions
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class Inboxes::MessagesController < Inboxes::BaseController
|
2
|
+
# before_filter :init_discussion
|
3
|
+
# load_and_authorize_resource
|
4
|
+
load_and_authorize_resource :discussion
|
5
|
+
load_resource :message, :through => :discussion, :shallow => true
|
2
6
|
|
3
7
|
def create
|
4
|
-
@discussion = Discussion.find(params[:discussion_id])
|
5
|
-
redirect_to root_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
|
6
|
-
|
7
|
-
@message = Message.new(params[:message])
|
8
8
|
@message.user = current_user
|
9
9
|
@message.discussion = @discussion
|
10
10
|
@message.save
|
@@ -14,5 +14,11 @@ class Inboxes::MessagesController < Inboxes::BaseController
|
|
14
14
|
format.js
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
# private
|
19
|
+
#
|
20
|
+
# def init_and_check_permissions
|
21
|
+
# @discussion = Discussion.find(params[:discussion_id])
|
22
|
+
# redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
|
23
|
+
# end
|
18
24
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
class Inboxes::SpeakersController < Inboxes::BaseController
|
2
|
-
before_filter :
|
2
|
+
# before_filter :init_discussion
|
3
|
+
load_and_authorize_resource :discussion
|
4
|
+
load_resource :speaker, :through => :discussion, :shallow => true
|
5
|
+
# load_and_authorize_resource
|
3
6
|
|
4
7
|
def create
|
5
|
-
# check permissions
|
6
8
|
raise ActiveRecord::RecordNotFound unless params[:speaker] && params[:speaker][:user_id]
|
7
9
|
@user = User.find(params[:speaker][:user_id])
|
8
|
-
|
9
|
-
flash[:notice] = t("views.speakers.added") if @discussion.add_speaker(@user)
|
10
|
+
flash[:notice] = t("inboxes.speakers.added") if @discussion.add_speaker(@user)
|
10
11
|
redirect_to @discussion
|
11
12
|
end
|
12
13
|
|
@@ -16,11 +17,4 @@ class Inboxes::SpeakersController < Inboxes::BaseController
|
|
16
17
|
flash[:notice] = @speaker.user == current_user ? t("inboxes.discussions.leaved") : t("inboxes.speakers.removed")
|
17
18
|
redirect_to @discussion.speakers.any? && @discussion.can_participate?(current_user) ? @discussion : discussions_url
|
18
19
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def init_and_check_permissions
|
23
|
-
@discussion = Discussion.find(params[:discussion_id])
|
24
|
-
redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
|
25
|
-
end
|
26
20
|
end
|
data/config/locales/ru.yml
CHANGED
@@ -13,5 +13,5 @@ ru:
|
|
13
13
|
can_not_participate: "Вы не состоите в этой дискуссии"
|
14
14
|
choose_at_least_one_recipient: "Укажите хотя бы одного получателя"
|
15
15
|
speakers:
|
16
|
-
added: "
|
17
|
-
removed: "
|
16
|
+
added: "Собеседник успешно добавлен"
|
17
|
+
removed: "Собеседник удален"
|
data/inboxes.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
# s.add_development_dependency "ruby-debug"
|
23
23
|
s.add_runtime_dependency "haml-rails"
|
24
|
+
s.add_runtime_dependency "cancan"
|
24
25
|
# s.add_runtime_dependency "inherited_resources"
|
25
26
|
|
26
27
|
# s.add_development_dependency 'dm-sqlite-adapter', ['>= 1.1.0']
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Inboxes
|
2
|
+
class InboxesAbility
|
3
|
+
include CanCan::Ability
|
4
|
+
|
5
|
+
def initialize(user)
|
6
|
+
# Discussion
|
7
|
+
can [:index, :create], Discussion
|
8
|
+
can :read, Discussion do |discussion|
|
9
|
+
discussion.can_participate?(user)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Message
|
13
|
+
# can :create, Message do |message|
|
14
|
+
# message.discussion.can_participate?(user)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # Speaker
|
18
|
+
# can [:create, :destroy], Speaker do |speaker|
|
19
|
+
# speaker.discussion.can_participate?(user)
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/inboxes/engine.rb
CHANGED
data/lib/inboxes/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inboxes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kir Shatrov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: haml-rails
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: cancan
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
version: "0"
|
46
|
-
type: :
|
46
|
+
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
49
|
+
name: rspec
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
type: :development
|
61
61
|
version_requirements: *id003
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rspec-rails
|
64
64
|
prerelease: false
|
65
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
@@ -73,6 +73,20 @@ dependencies:
|
|
73
73
|
version: "0"
|
74
74
|
type: :development
|
75
75
|
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: database_cleaner
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
76
90
|
description: Messaging system for Rails 3 app
|
77
91
|
email:
|
78
92
|
- razor.psp@gmail.com
|
@@ -109,6 +123,7 @@ files:
|
|
109
123
|
- lib/generators/inboxes/templates/install.rb
|
110
124
|
- lib/generators/inboxes/views_generator.rb
|
111
125
|
- lib/inboxes.rb
|
126
|
+
- lib/inboxes/ability.rb
|
112
127
|
- lib/inboxes/active_record_extension.rb
|
113
128
|
- lib/inboxes/engine.rb
|
114
129
|
- lib/inboxes/railtie.rb
|