@@ -4,6 +4,23 @@ module Api
44 class LessonsController < ApiController
55 include RemixSelection
66
7+ LESSON_ATTRIBUTES = %i[
8+ school_id
9+ school_class_id
10+ name
11+ description
12+ visibility
13+ due_date
14+ ] . freeze
15+
16+ PROJECT_ATTRIBUTES = [
17+ :name ,
18+ :project_type ,
19+ :locale ,
20+ { components : %i[ id name extension content index default ] } ,
21+ { scratch_component : { } }
22+ ] . freeze
23+
724 before_action :authorize_user , except : %i[ index show ]
825 before_action :verify_school_class_belongs_to_school , only : :create
926 before_action :verify_can_create_scratch_projects , only : %i[ create create_copy ]
@@ -136,44 +153,15 @@ def update_params
136153 end
137154
138155 def bulk_create_params ( lesson_project )
139- lesson_project . permit (
140- :school_id ,
141- :school_class_id ,
142- :name ,
143- :description ,
144- :visibility ,
145- :due_date ,
146- :origin_identifier ,
147- {
148- project_attributes : [
149- :name ,
150- :project_type ,
151- :locale ,
152- { components : %i[ id name extension content index default ] } ,
153- { scratch_component : { } }
154- ]
155- }
156- ) . merge ( user_id : current_user . id )
156+ permit_lesson_params ( lesson_project , :origin_identifier ) . merge ( user_id : current_user . id )
157157 end
158158
159159 def create_params
160- params . fetch ( :lesson , { } ) . permit (
161- :school_id ,
162- :school_class_id ,
163- :name ,
164- :description ,
165- :visibility ,
166- :due_date ,
167- {
168- project_attributes : [
169- :name ,
170- :project_type ,
171- :locale ,
172- { components : %i[ id name extension content index default ] } ,
173- { scratch_component : { } }
174- ]
175- }
176- ) . merge ( user_id : current_user . id )
160+ permit_lesson_params ( params . fetch ( :lesson , { } ) ) . merge ( user_id : current_user . id )
161+ end
162+
163+ def permit_lesson_params ( source , *extra )
164+ source . permit ( *LESSON_ATTRIBUTES , *extra , project_attributes : PROJECT_ATTRIBUTES )
177165 end
178166
179167 def school_owner?
0 commit comments