qm-acts-as-generic-controller 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gemspec.email = "marcin@saepia.net"
11
11
  gemspec.homepage = "http://q.saepia.net"
12
12
  gemspec.authors = ["Marcin Lewandowski"]
13
- gemspec.version = "0.1.18"
13
+ gemspec.version = "0.1.19"
14
14
  gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*", "app/views/generic_controller/*" ]
15
15
  gemspec.add_dependency "qui-common-helpers", ">= 0.0.8"
16
16
  gemspec.add_dependency "qui-index-table", ">= 0.0.8"
@@ -18,6 +18,14 @@
18
18
  <%= hidden_field_tag :association_attribute_value, params[:association_attribute_value] %>
19
19
  <%- end -%>
20
20
 
21
+ <%- if klass.respond_to? "document?" and klass.document? and params[:scan_original_id] -%>
22
+ <%= hidden_field_tag :scan_original_id, params[:scan_original_id] %>
23
+
24
+ <%- content_tag :div, :class => "dialog notice" do -%>
25
+ <%= image_tag("actions/document_scan.png", :alt => "") %> Załączono skan dokumentu
26
+ <%- end -%>
27
+ <%- end -%>
28
+
21
29
  <%= f.error_messages %>
22
30
  <%- unless klass.generic_form_fieldsets -%>
23
31
  <fieldset>
@@ -92,72 +92,86 @@ module QM
92
92
  end
93
93
 
94
94
  def create
95
- remove_unprivileged_keys_from_params
95
+ model.transaction do
96
+ if model.respond_to? "document?" and model.document? and params[:scan_original_id]
97
+ document = Document.find(params[:scan_original_id])
98
+ logger.info document.inspect
99
+ end
96
100
 
97
- instance_variable_set(singular_variable, model.new(params[singular_variable(true)])) unless instance_variable_defined?(singular_variable)
98
-
99
- save_creator
100
- save_updator
101
+ remove_unprivileged_keys_from_params
101
102
 
102
- respond_to do |format|
103
- if instance_variable_get(singular_variable).save
104
- flash[:notice] = :savedAsFlash
105
- if defined?(section)
106
- format.html {
107
- if params[:commit_and_create]
108
- if params[:association_attribute_name] and params[:association_attribute_value]
109
- redirect_to polymorphic_url([ "new", section, model.table_name.singularize ], :association_attribute => params[:association_attribute_name], params[:association_attribute_name] => params[:association_attribute_value])
103
+ instance_variable_set(singular_variable, model.new(params[singular_variable(true)])) unless instance_variable_defined?(singular_variable)
104
+
105
+ if document
106
+ document.send("#{model.to_s.tableize.singularize}=", instance_variable_get(singular_variable))
107
+ logger.info document.inspect
108
+ document.save
109
+ end
110
+
111
+ save_creator
112
+ save_updator
113
+
114
+
115
+ respond_to do |format|
116
+ if instance_variable_get(singular_variable).save
117
+ flash[:notice] = :savedAsFlash
118
+ if defined?(section)
119
+ format.html {
120
+ if params[:commit_and_create]
121
+ if params[:association_attribute_name] and params[:association_attribute_value]
122
+ redirect_to polymorphic_url([ "new", section, model.table_name.singularize ], :association_attribute => params[:association_attribute_name], params[:association_attribute_name] => params[:association_attribute_value])
123
+ else
124
+ redirect_to polymorphic_url([ "new", section, model.table_name.singularize ])
125
+
126
+ end
110
127
  else
111
- redirect_to polymorphic_url([ "new", section, model.table_name.singularize ])
112
-
128
+ redirect_to [ section, instance_variable_get(singular_variable) ]
113
129
  end
114
- else
115
- redirect_to [ section, instance_variable_get(singular_variable) ]
116
- end
117
- }
118
-
119
- format.xml { render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => [ section, instance_variable_get(singular_variable) ] }
130
+ }
131
+
132
+ format.xml { render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => [ section, instance_variable_get(singular_variable) ] }
120
133
 
121
134
 
122
- else
123
- format.html {
124
- if params[:commit_and_create]
125
- if params[:association_attribute_name] and params[:association_attribute_value]
126
- redirect_to polymorphic_url([ "new", model.table_name.singularize ], :association_attribute => params[:association_attribute_name], params[:association_attribute_name] => params[:association_attribute_value])
135
+ else
136
+ format.html {
137
+ if params[:commit_and_create]
138
+ if params[:association_attribute_name] and params[:association_attribute_value]
139
+ redirect_to polymorphic_url([ "new", model.table_name.singularize ], :association_attribute => params[:association_attribute_name], params[:association_attribute_name] => params[:association_attribute_value])
140
+ else
141
+ redirect_to polymorphic_url([ "new", model.table_name.singularize ])
142
+ end
143
+
127
144
  else
128
- redirect_to polymorphic_url([ "new", model.table_name.singularize ])
145
+ redirect_to instance_variable_get(singular_variable)
129
146
  end
130
-
131
- else
132
- redirect_to instance_variable_get(singular_variable)
133
- end
134
147
 
135
- }
136
-
148
+ }
149
+
150
+ format.xml {
151
+ if defined?(current_user) and current_user.respond_to? :privileged_attributes
152
+ render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => instance_variable_get(singular_variable)
153
+ else
154
+ render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => instance_variable_get(singular_variable)
155
+ end
156
+ }
157
+ end
158
+ else
159
+ format.html {
160
+ begin
161
+ render :action => "new"
162
+
163
+ rescue ActionView::MissingTemplate
164
+ render :template => "generic_controller/form"
165
+ end
166
+ }
137
167
  format.xml {
138
168
  if defined?(current_user) and current_user.respond_to? :privileged_attributes
139
- render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => instance_variable_get(singular_variable)
169
+ render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :unprocessable_entity
140
170
  else
141
- render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :created, :location => instance_variable_get(singular_variable)
171
+ render :xml => instance_variable_get(singular_variable), :status => :unprocessable_entity
142
172
  end
143
173
  }
144
174
  end
145
- else
146
- format.html {
147
- begin
148
- render :action => "new"
149
-
150
- rescue ActionView::MissingTemplate
151
- render :template => "generic_controller/form"
152
- end
153
- }
154
- format.xml {
155
- if defined?(current_user) and current_user.respond_to? :privileged_attributes
156
- render :xml => instance_variable_get(singular_variable).to_xml(:only => current_user_xml_privileged_attributes), :status => :unprocessable_entity
157
- else
158
- render :xml => instance_variable_get(singular_variable), :status => :unprocessable_entity
159
- end
160
- }
161
175
  end
162
176
  end
163
177
  end
@@ -12,7 +12,15 @@ module QM
12
12
  raise ArgumentError, "You must pass options[:user] to limit_with_security_scheme" unless options.has_key? :user
13
13
 
14
14
  # Return empty set if user has no privileges at all (nor index_any and index_created)
15
- return [] if !options[:user].has_privileges?(:class_name => self, :generic_action => :index_any) && !options[:user].has_privileges?(:class_name => self, :generic_action => :index_created)
15
+ unless options[:user].has_privileges?(:class_name => self, :generic_action => :index_any) or options[:user].has_privileges?(:class_name => self, :generic_action => :index_created)
16
+ # puts ":("
17
+ # puts options[:user].inspect
18
+ # puts self
19
+ # puts options[:user].has_privileges?(:class_name => self, :generic_action => :index_any)
20
+ # puts options[:user].has_privileges?(:class_name => self, :generic_action => :index_created)
21
+ # puts options[:user].has_privileges?(:class_name => self, :generic_action => :index_any) or options[:user].has_privileges?(:class_name => self, :generic_action => :index_created)
22
+ return []
23
+ end
16
24
 
17
25
  creator_column = "creator_#{options[:user].class.to_s.tableize.singularize}_id"
18
26
  should_limit_index_for_created = columns_hash.has_key?(creator_column) && options[:user].respond_to?(:has_privileges?) && !options[:user].has_privileges?(:class_name => self, :generic_action => :index_any) && options[:user].has_privileges?(:class_name => self, :generic_action => :index_created)
@@ -85,6 +93,8 @@ module QM
85
93
  @named_scopes[name.to_sym] = options.dup
86
94
 
87
95
  options.delete(:generic) if options.is_a? Hash
96
+
97
+ options[:block] = block if block
88
98
 
89
99
  super name, options, &block
90
100
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qm-acts-as-generic-controller
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 18
10
- version: 0.1.18
9
+ - 19
10
+ version: 0.1.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcin Lewandowski