wordjelly-auth 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/auth/application.js +1 -1
  3. data/app/controllers/auth/application_controller.rb +6 -0
  4. data/app/controllers/auth/concerns/devise_concern.rb +1 -1
  5. data/app/controllers/auth/concerns/work/communication_controller_concern.rb +82 -0
  6. data/app/controllers/auth/concerns/work/instruction_controller_concern.rb +6 -1
  7. data/app/controllers/auth/endpoints_controller.rb +41 -24
  8. data/app/controllers/auth/images_controller.rb +0 -4
  9. data/app/controllers/auth/profiles_controller.rb +2 -13
  10. data/app/controllers/auth/work/communications_controller.rb +18 -0
  11. data/app/controllers/auth/work/work_controller.rb +43 -0
  12. data/app/jobs/notification_job.rb +17 -0
  13. data/app/mailers/auth/send_mail.rb +15 -0
  14. data/app/models/auth/concerns/chief_model_concern.rb +4 -0
  15. data/app/models/auth/concerns/shopping/product_concern.rb +5 -3
  16. data/app/models/auth/concerns/user_concern.rb +2 -6
  17. data/app/models/auth/endpoint.rb +26 -3
  18. data/app/models/auth/image.rb +5 -0
  19. data/app/models/auth/work/communication.rb +109 -0
  20. data/app/models/auth/work/cycle.rb +8 -14
  21. data/app/models/auth/work/instruction.rb +1 -0
  22. data/app/models/auth/work/minute.rb +75 -52
  23. data/app/views/auth/images/_form.html.erb +1 -1
  24. data/app/views/auth/images/_image_concern.html.erb +3 -3
  25. data/app/views/auth/send_mail/send.html.erb +1 -0
  26. data/app/views/auth/shopping/products/show/_summary.html.erb +12 -0
  27. data/app/views/auth/work/communications/_form.html.erb +57 -0
  28. data/app/views/auth/work/instructions/_form.html.erb +7 -1
  29. data/app/views/auth/work/instructions/_image.html.erb +5 -0
  30. data/app/views/auth/work/instructions/new.html.erb +1 -0
  31. data/app/views/auth/work/instructions/show.html.erb +1 -0
  32. data/app/views/layouts/send_mail.html.erb +5 -0
  33. data/lib/auth/engine.rb +34 -4
  34. data/lib/auth/rails/routes.rb +11 -11
  35. data/lib/auth/version.rb +1 -1
  36. data/spec/dummy/app/assets/javascripts/application.js +0 -2
  37. data/spec/dummy/app/assets/javascripts/images.js +9 -19
  38. data/spec/dummy/app/assets/time_hashes.json +1 -1
  39. data/spec/dummy/app/views/layouts/application.html.erb +0 -1
  40. data/spec/dummy/app/views/new/notification.text.erb +1 -1
  41. data/spec/dummy/app/views/worms/new.html.erb +3 -0
  42. data/spec/dummy/config/cloudinary.yml +6 -6
  43. data/spec/dummy/config/initializers/preinitializer.rb +1 -4
  44. data/spec/models/auth/work/minute_spec.rb +43 -34
  45. data/spec/requests/user/amazon_sns_request_spec.rb +34 -2
  46. data/spec/support/work_support.rb +133 -0
  47. metadata +13 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2049e36e29dddee7774021ee9332e67a553b133
4
- data.tar.gz: 64c04b25b55f5db3c2c2a0804816e5c233064ee3
3
+ metadata.gz: c7ab725ad999f3946bd4ab7ba2cee07eb9b8cbd5
4
+ data.tar.gz: 76ba5387d53e18539441f2b3514988b4bb4adb6c
5
5
  SHA512:
6
- metadata.gz: 72c0bbc7998837181644d6a9b5c481e08cb44c350ebff3d28d22056cab595c24c411ec7908d05313c296afafe7d902dba004431663783b080745907896bf2e22
7
- data.tar.gz: 23ab350e94d744fe82603a14634e59b91d5a0306afcdaa2858f96299c5f87e3c8298d69ab420415a182ebf0b0364a80ecf447dfa6bf54afa2d5dd27c177a1445
6
+ metadata.gz: f2e71a5be7e81f2d8ad4006973f2d94306cce5bc5b3d69d42d6c8dfb97a8be775deb68fc177357496c83d92335c13b6963c9ef72fe3a136a4b592f9959d318ce
7
+ data.tar.gz: b363954188740ee6731b712e443950cf6e8e67f1a60e9af94c1ea8ed27d293db0c6ff1cea7da522a85c892e038b9aa9a39e2176899ed97b2c1fedcfc8256386c
@@ -9,7 +9,7 @@
9
9
  //
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
- //
12
+
13
13
 
14
14
  //= require jquery
15
15
  //= require jquery_ujs
@@ -12,6 +12,10 @@ module Auth
12
12
  end
13
13
  end
14
14
 
15
+ rescue_from ActionController::UnknownFormat do |e|
16
+ render status: 404, text: "Not Found"
17
+ end
18
+
15
19
 
16
20
  ######################################################################
17
21
  ##
@@ -39,6 +43,7 @@ module Auth
39
43
 
40
44
  not_found("could not determine class name") unless class_name
41
45
 
46
+ puts "class name: #{class_name}"
42
47
 
43
48
 
44
49
  return class_name
@@ -63,6 +68,7 @@ module Auth
63
68
 
64
69
 
65
70
  def build_model_from_params
71
+ puts "params are: #{params.to_s}"
66
72
  pp = permitted_params
67
73
  puts "the permitted_params are:"
68
74
  puts permitted_params.to_s
@@ -125,7 +125,7 @@ module Auth::Concerns::DeviseConcern
125
125
  ##should block any put action on the user
126
126
  ##and should render an error saying please do this on the server.
127
127
  if is_json_request?
128
- #puts "it is a json request."
128
+
129
129
  if action_name == "otp_verification_result"
130
130
  ##we let this action pass because, we make json ajax requests
131
131
  ##from the web ui to this endpoint, and anyway it does
@@ -0,0 +1,82 @@
1
+ module Auth::Concerns::Work::InstructionControllerConcern
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Auth::Work::Instructions::InstructionsHelper
7
+ end
8
+
9
+ ## at this stage all we will have is instantiations .
10
+ def get_parent_object(parent_object_class,parent_object_id)
11
+
12
+ parent_object = nil
13
+
14
+ begin
15
+ parent_object = parent_object_class.constantize.find(parent_object_id)
16
+ if params[:id]
17
+ @auth_work_communication = parent_object.communications.select{|c|
18
+ c.id.to_s == params[:id]
19
+ }
20
+ @auth_work_communication = @auth_work_communication.size > 0 ? @auth_work_communication[0] : Auth::Work::Communication.new(@auth_work_communication_params)
21
+ else
22
+
23
+ end
24
+ rescue Mongoid::Errors::DocumentNotFound
25
+ parent_object = parent_object_class.constantize.new
26
+ @auth_work_communication = Auth::Work::Communication.new(@auth_work_communication_params)
27
+ end
28
+
29
+ parent_object
30
+
31
+ end
32
+
33
+ def initialize_vars
34
+
35
+ instantiate_work_classes
36
+
37
+ @auth_work_communication_params = permitted_params.fetch(:communication,{})
38
+
39
+ @auth_work_cycle = nil
40
+
41
+ @auth_work_instruction = nil
42
+
43
+ if @auth_work_communication_params[:cycle_id]
44
+ @auth_work_cycle = get_parent_object(@auth_work_cycle_class,@auth_work_communication_params[:cycle_id])
45
+ elsif @auth_work_communication_params[:instruction_id]
46
+ @auth_work_instruction = get_parent_object(@auth_work_instruction_class,@auth_work_communication_params[:instruction_id])
47
+ else
48
+ not_found("please provide a cycle id or an instruction id")
49
+ end
50
+
51
+ end
52
+
53
+ def create
54
+
55
+ end
56
+
57
+ def new
58
+ ## now new has to render this form.
59
+ ## and it has to determine the url and the
60
+ end
61
+
62
+ def index
63
+
64
+ end
65
+
66
+ def update
67
+
68
+ end
69
+
70
+ def show
71
+
72
+ end
73
+
74
+ def destroy
75
+
76
+ end
77
+
78
+ def permitted_params
79
+ pr = params.permit({:communication => [:send_email,:email_template_path,:method_to_determine_recipients,:repeat,:repeat_times,:method_to_determine_communication_timing,:enqueue_at_time]}, :id, :instruction_id,:cycle_id)
80
+ end
81
+
82
+ end
@@ -6,6 +6,7 @@ module Auth::Concerns::Work::InstructionControllerConcern
6
6
  include Auth::Work::Instructions::InstructionsHelper
7
7
  end
8
8
 
9
+
9
10
  def initialize_vars
10
11
  instantiate_work_classes
11
12
  not_found("no product id provided") unless params[:product_id]
@@ -19,13 +20,16 @@ module Auth::Concerns::Work::InstructionControllerConcern
19
20
  if params[:id]
20
21
  @auth_work_instruction = @auth_shopping_product.instructions.select{|c|
21
22
  c.id.to_s == params[:id]
22
- }[0]
23
+ }
24
+ not_found("no such object") if @auth_work_instruction.empty?
25
+ @auth_work_instruction = @auth_work_instruction[0]
23
26
  else
24
27
  @auth_work_instruction = @auth_work_instruction_class.new(@auth_work_instruction_params)
25
28
  end
26
29
  end
27
30
  rescue Mongoid::Errors::DocumentNotFound
28
31
  @auth_shopping_product = @auth_shopping_product_class.new
32
+ @auth_work_instruction = @auth_work_instruction_class.new(@auth_work_instruction_params)
29
33
  end
30
34
 
31
35
  end
@@ -75,6 +79,7 @@ module Auth::Concerns::Work::InstructionControllerConcern
75
79
 
76
80
  def show
77
81
  instantiate_work_classes
82
+ ## so i will have to pass the product id as well.
78
83
  @auth_shopping_product = @auth_shopping_product_class.find(params[:product_id])
79
84
  @auth_work_instruction = @auth_shopping_product.instructions.select{|c| c.id.to_s == params[:id]}[0]
80
85
  end
@@ -2,6 +2,7 @@ class Auth::EndpointsController < Auth::ApplicationController
2
2
 
3
3
  ## responds only to json.
4
4
  ## got to add the thing to subscribe them to a topic as well.
5
+ respond_to :json
5
6
 
6
7
  include Auth::Concerns::DeviseConcern
7
8
 
@@ -12,43 +13,59 @@ class Auth::EndpointsController < Auth::ApplicationController
12
13
  before_filter :build_model_from_params
13
14
  before_filter(:only => [:create]){|c| check_for_create(@model)}
14
15
 
15
- ## all i have to do now is set the routes
16
- ## and this should start saving endpoints automatically as needed.
17
- ## so now lets try to make a new endpoint.
18
- ## question is that what if that token already exists ?
19
- ## so i will do a find_one_and_update.
20
-
21
16
  def create
17
+
18
+
22
19
  or_clause = []
23
20
 
24
21
  or_clause << {
25
- "android_token" => self.android_token
26
- } if self.android_token
22
+ "android_token" => @model.android_token
23
+ } if @model.android_token
27
24
 
28
25
  or_clause << {
29
- "ios_token" => self.ios_token
30
- } if self.ios_token
26
+ "ios_token" => @model.ios_token
27
+ } if @model.ios_token
28
+
29
+ if or_clause.empty?
30
+ returned_document = nil
31
+ else
32
+ returned_document = @model.class.where({
33
+ "$or" => or_clause
34
+ }).find_one_and_update(
35
+ {
36
+ "$setOnInsert" => @model.attributes,
37
+
38
+ },
39
+ {
40
+ :upsert => true,
41
+ :return_document => :after
42
+ }
43
+ )
31
44
 
32
- returned_document = @model.class.where({
33
- "$or" => or_clause
34
- }).find_one_and_update(
35
- {
36
- "$set" => self.attributes,
45
+ if returned_document
46
+ returned_document.set_android_endpoint
47
+ returned_document.set_ios_endpoint
48
+ end
37
49
 
38
- },
39
- {
40
- :return_document => :after
41
- }
42
- )
50
+ end
43
51
 
44
- #respond_to do |format|
45
- # format.json {render json: returned_document.to_json, status: returned_document}
46
- #end
52
+ respond_to do |format|
53
+ if returned_document
54
+ format.json do
55
+ render json: returned_document.to_json, status: 201
56
+ end
57
+ else
58
+ format.json do
59
+ render json: {
60
+ }.to_json, status: 422
61
+ end
62
+ end
63
+ end
47
64
 
48
65
  end
49
66
 
50
67
  def permitted_params
51
- params.require(:endpoint).permit(:android_token,:ios_token)
68
+ params.permit({:endpoint => [:android_token,:ios_token]},:api_key,:current_app_id)
52
69
  end
53
70
 
54
71
  end
@@ -2,9 +2,5 @@ class Auth::ImagesController < Auth::AuthenticatedController
2
2
 
3
3
  include Auth::Images::ImagesHelper
4
4
 
5
-
6
-
7
-
8
-
9
5
 
10
6
  end
@@ -51,19 +51,8 @@ class Auth::ProfilesController < Auth::ApplicationController
51
51
 
52
52
  check_for_update(@profile_resource)
53
53
 
54
- #if @resource_params[:admin]
55
- # @profile_resource.admin = @resource_params[:admin]
56
- #end
57
-
58
- #if @resource_params[:created_by_admin]
59
- # @profile_resource.created_by_admin = @resource_params[:created_by_admin]
60
- #end
61
-
62
- ## so not only this but i need a basic endpoint as well
63
- ## to add endpoints.
64
- ## okay so will need another endpoint model for that purpose.
65
- ## so first let me finish this.
66
-
54
+ puts "going to assing attributes."
55
+ puts "resource params are: #{}"
67
56
  @profile_resource.assign_attributes(@resource_params)
68
57
 
69
58
  @profile_resource.m_client = self.m_client
@@ -0,0 +1,18 @@
1
+ class Auth::Work::CommunicationsController < Auth::Work::WorkController
2
+
3
+ include Auth::Concerns::Work::CommunicationControllerConcern
4
+
5
+ ## only these actions need an authenticated user to be present for them to be executed.
6
+ CONDITIONS_FOR_TOKEN_AUTH = [:create,:update,:destroy,:edit,:new]
7
+
8
+ TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}
9
+ ##this ensures api access to this controller.
10
+ include Auth::Concerns::DeviseConcern
11
+ include Auth::Concerns::TokenConcern
12
+ before_filter :do_before_request , TCONDITIONS
13
+ before_filter :initialize_vars , TCONDITIONS
14
+ before_filter :is_admin_user , :only => [:create,:update,:destroy,:edit]
15
+
16
+
17
+
18
+ end
@@ -38,9 +38,52 @@ class Auth::Work::WorkController < Auth::ApplicationController
38
38
 
39
39
  end
40
40
 
41
+ def instantiate_communication_class
42
+ if @auth_work_communication_class = Auth.configuration.communication_class
43
+ begin
44
+ @auth_work_communication_class = @auth_work_communication_class.constantize
45
+ rescue => e
46
+ puts e.to_s
47
+ not_found("error instatiating class from communication class")
48
+ end
49
+ else
50
+ not_found("communication class not specified in configuration")
51
+ end
52
+ end
53
+
54
+ def instantiate_communication_class
55
+ if @auth_work_communication_class = Auth.configuration.communication_class
56
+ begin
57
+ @auth_work_communication_class = @auth_work_communication_class.constantize
58
+ rescue => e
59
+ puts e.to_s
60
+ not_found("error instatiating class from communication class")
61
+ end
62
+ else
63
+ not_found("communication class not specified in configuration")
64
+ end
65
+ end
66
+
67
+ def instantiate_cycle_class
68
+ if @auth_work_cycle_class = Auth.configuration.cycle_class
69
+ begin
70
+ @auth_work_cycle_class = @auth_work_cycle_class.constantize
71
+ rescue => e
72
+ puts e.to_s
73
+ not_found("error instatiating class from cycle class")
74
+ end
75
+ else
76
+ not_found("cycle class not specified in configuration")
77
+ end
78
+ end
79
+ ## do we have a cycle class / controller, obviously are going to need this eventually.
80
+ ## so let me now add that to the engine, add cycle class to engine.
81
+
41
82
  def instantiate_work_classes
42
83
  instantiate_instruction_class
43
84
  instantiate_bullet_class
44
85
  instantiate_product_class
86
+ instantiate_cycle_class
87
+ instantiate_communication_class
45
88
  end
46
89
  end
@@ -0,0 +1,17 @@
1
+ class NotificationJob < ActiveJob::Base
2
+
3
+ queue_as :default
4
+ self.queue_adapter = :delayed_job
5
+
6
+ ##we currently log all exceptions to redis.
7
+ rescue_from(StandardError) do |exception|
8
+ puts exception.message
9
+ puts exception.backtrace.join("\n")
10
+ end
11
+
12
+ def perform(cart_item,instruction_index,notification_index)
13
+ notification = cart_item.instructions[instruction_index].notifications[notification_index]
14
+ notification.deliver_all
15
+ end
16
+
17
+ end
@@ -0,0 +1,15 @@
1
+ class Auth::SendMail < ActionMailer::Base
2
+ default from: "bhargav.r.raut@gmail.com"
3
+ def send_email(opts)
4
+ @options = opts || {}
5
+ raise "no recipient address" unless @options[:to]
6
+ raise "no subject" unless @options[:to]
7
+ mail(to: @options[:to], subject: @options[:subject]) do |format|
8
+ format.html { render @options[:template] || "send" }
9
+ end
10
+ end
11
+ ## okay so for this, we will pass it to otp job only.
12
+ ## with some arguments.
13
+ ## why not use whatever emailer i was using before ?
14
+ ## okay so the next step is to send this whole notification into a delayed job.
15
+ end
@@ -47,6 +47,10 @@ module Auth::Concerns::ChiefModelConcern
47
47
  ##and add them to an images array.
48
48
  def load_images
49
49
  self.images = Auth::Image.where(:parent_id => self.id.to_s) || []
50
+ self.images.each do |image|
51
+ puts image.attributes.to_s
52
+ end
53
+
50
54
  end
51
55
 
52
56
 
@@ -14,7 +14,7 @@ module Auth::Concerns::Shopping::ProductConcern
14
14
 
15
15
  embeds_many :cycles, :class_name => "Auth::Work::Cycle", :as => :product_cycles
16
16
 
17
-
17
+
18
18
  INDEX_DEFINITION = {
19
19
  index_options: {
20
20
  settings: {
@@ -143,7 +143,9 @@ module Auth::Concerns::Shopping::ProductConcern
143
143
 
144
144
  end
145
145
 
146
- ## minutes : {epoch => minute object}
146
+ ## adds the relevant cycles to the minutes, and returns the hash that came in.
147
+ ## does not save the minutes, after adding the cycles to them.
148
+ ##@return[Hash] {epoch => minute object}
147
149
  def schedule_cycles(minutes,location_id,conditions = {})
148
150
 
149
151
  products = Auth.configuration.product_class.constantize.all if conditions.blank?
@@ -172,7 +174,7 @@ module Auth::Concerns::Shopping::ProductConcern
172
174
  cycle_to_add.cycle_chain = cycle_chain
173
175
  if minutes[epoch_at_which_to_add]
174
176
 
175
- add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)
177
+ #add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)
176
178
 
177
179
 
178
180
  minutes[epoch_at_which_to_add].cycles << cycle_to_add
@@ -821,17 +821,13 @@ module Auth::Concerns::UserConcern
821
821
  ###
822
822
  ####################################################################
823
823
  def refresh_endpoints
824
- puts "called refresh end points."
825
- puts self.android_token
824
+
826
825
  if self.android_token_changed?
827
826
  endpoint = Auth::Endpoint.new
828
827
  endpoint.android_token = self.android_token
829
828
  self.android_endpoint = endpoint.set_android_endpoint
830
829
  end
831
- ## now have to make an endpoints controller.
830
+
832
831
  end
833
832
 
834
- ## after this we have notification dispatch and scheduling logic based on the instructions and cycles.
835
- ## this has to also be finished today.
836
-
837
833
  end
@@ -7,15 +7,18 @@ class Auth::Endpoint
7
7
  field :android_token, type: String
8
8
  field :ios_token, type: String
9
9
 
10
- before_save :set_android_endpoint
11
- before_save :set_ios_endpoint
12
-
13
10
  def set_android_endpoint
11
+
14
12
  return unless self.android_token
13
+
14
+ return if self.android_endpoint
15
+
15
16
  if response = $sns_client.create_platform_endpoint(platform_application_arn: ENV["ANDROID_ARN"], token: self.android_token, attributes: {})
16
17
  self.android_endpoint = response.endpoint_arn
18
+
17
19
  self.android_endpoint
18
20
  else
21
+
19
22
  nil
20
23
  end
21
24
  end
@@ -24,5 +27,25 @@ class Auth::Endpoint
24
27
  return unless self.ios_token
25
28
  end
26
29
 
30
+ ## so i have to do what first ?
31
+ ## notification objects.
32
+ ## and their editing.
33
+
34
+ ## so it comes down to a few simple things
35
+ ## 1. the cart_item has a variables hash.
36
+ ## 2. notiications are assigned to each instruction.
37
+ ## 2a. they will carry an array of outlinks, as well as how the notification is to be sent.
38
+ ## 3a. they will check the time in the variables hash before sending the notification
39
+ ## 4a. they will rewire themselves if the time is later than what is in the notification itself.
40
+ ## 5a. cycles can directly update cart items which they pertain to, chaning these notification variables.
41
+ ## 3. when a cart item is created -> notifications are queued.
42
+ ## 4. the time for queueing is defined based on the variables seen in that variables hash.
43
+ ## but assume that a cart item is queued. and it is a part of several cycles.
44
+ ## in that case, the timings can only be got from those cycles
45
+ ## so the cart item has to build its variables from the cycles.
46
+ ## where is the cycle going to update its images and videos ?
47
+ ## to what ?
48
+ ## and i need a place to edit the bullets, instructions, and notifications, and variables.
49
+ ## and i have 2 days for all this :)
27
50
 
28
51
  end
@@ -103,4 +103,9 @@ class Auth::Image
103
103
  self.signed_request[:signature].to_s
104
104
  end
105
105
 
106
+ def get_url
107
+ Cloudinary::Utils.cloudinary_url(self.id.to_s)
108
+ end
109
+
110
+
106
111
  end
@@ -0,0 +1,109 @@
1
+ class Auth::Work::Communication
2
+ include Auth::Concerns::ChiefModelConcern
3
+
4
+ ## 1. it has been embedded, now let me create the ui to edit the communication, for email fields, and then we proceed to email, for this we will need routes and forms.
5
+ ## so i need to see how the communications were made.
6
+ ## 2. finish the surveys
7
+ ## 3. finish two tradegenie tests
8
+ ## 4. finish booking cycle.
9
+
10
+
11
+ ###################################################################
12
+ ##
13
+ ##
14
+ ## ACCESSORS FOR CYCLE AND PRODUCT IDS.
15
+ ##
16
+ ##
17
+ ###################################################################
18
+
19
+ attr_accessor :cycle_id
20
+ attr_accessor :instruction_id
21
+
22
+ ###################################################################
23
+ ##
24
+ ##
25
+ ## RELATIONS.
26
+ ##
27
+ ##
28
+ ###################################################################
29
+
30
+ ## now give the view to show this
31
+ embedded_in :cycles, :class_name => "Auth::Work::Cycle", :polymorphic => true
32
+
33
+ ## add embedded in products.
34
+ embedded_in :instructions, :class_name => "Auth::Work::Instruction", :polymorphic => true
35
+
36
+ ###################################################################
37
+ ##
38
+ ##
39
+ ## EMAIL
40
+ ##
41
+ ##
42
+ ###################################################################
43
+
44
+ field :send_email, type: Boolean
45
+
46
+ field :email_template_path, type: String
47
+
48
+ ###################################################################
49
+ ##
50
+ ##
51
+ ## RECIPIENT DETERMINATION.
52
+ ##
53
+ ##
54
+ ###################################################################
55
+
56
+ ## this method is called on self.
57
+ ## and the self id is passed as an argument.
58
+ ## eg : self.send("instruction.cart_item.get_recipients",self.id.to_s)
59
+ field :method_to_determine_recipients, type: String
60
+
61
+ ## this is got by calling the above method.
62
+ ## this is not a permitted parameter.
63
+ field :recipients, type: Hash
64
+
65
+ ###################################################################
66
+ ##
67
+ ##
68
+ ## communication REPEATS
69
+ ##
70
+ ##
71
+ ###################################################################
72
+
73
+ ## "daily,weekly,monthly,yearly"
74
+ field :repeat, type: String
75
+
76
+ ## how many times to repeat it.
77
+ field :repeat_times, type: Integer
78
+
79
+ ## this is called to determine when to send this communication.
80
+ field :method_to_determine_communication_timing, type: String
81
+
82
+ ## enqueue_at_time
83
+ ## this is not a permitted parameters.
84
+ field :enqueue_at_time, type: Time
85
+
86
+ def set_recipients
87
+ self.recipients = self.send("#{self.method_to_determine_recipients}",self.id.to_s)
88
+ end
89
+
90
+ def set_enqueue_at_time
91
+ self.enqueue_at_time = self.send("#{self.method_to_determine_communication_timing}",self.id.to_s)
92
+ end
93
+
94
+ def repeat_options
95
+ [
96
+ ["Daily","Daily"],
97
+ ["Weekly","Weekly"],
98
+ ["Monthly","Monthly"],
99
+ ["Yearly","Yearly"],
100
+ ["Half-Monthly","Half-Monthly"],
101
+ ["Saturday","Saturday"],
102
+ ["Sunday","Sunday"],
103
+ ["Monday","Monday"],
104
+ ["Tuesday","Tuesday"],
105
+ ["Wednesday","Wednesday"]
106
+ ]
107
+ end
108
+
109
+ end
@@ -18,8 +18,11 @@ class Auth::Work::Cycle
18
18
 
19
19
  embeds_many :templates, :class_name => "Auth::Work::Template"
20
20
 
21
+ embeds_many :communications, :class_name => "Auth::Work::Communication", :as => :cycle_communications
22
+
21
23
  ## each cycle will have a limit
22
24
  field :capacity, type: Integer, default: 0
25
+ ## so this capacity is what has to be updated.
23
26
 
24
27
  ## there will have to be another field, saying workers who can do it, and entities who can do it.
25
28
  field :workers_available, type: Array
@@ -62,6 +65,10 @@ class Auth::Work::Cycle
62
65
 
63
66
  field :cycle_code, type: String
64
67
 
68
+ ## every cycle should have a type.
69
+ ## we search based on this type.
70
+ field :cycle_type, type: String
71
+
65
72
  ## the ids of the related cycles.
66
73
  field :cycle_chain, type: Array, default: []
67
74
 
@@ -209,20 +216,7 @@ class Auth::Work::Cycle
209
216
  after_book
210
217
  end
211
218
 
212
-
213
- ## so the search criteria is
214
- ## where entity_ids == [n1,n2,n3], or worker_ids= [y1,y2,y3]
215
- ## range is such that
216
- ## if (end time or start time) of any cycle is (from this minute -> time of end of this cycle)
217
- ## or if start time <= this minute, and end time is >= minute of end of this cycle.
218
- ## for any of those cycles -> if priority is applicable, then block, and block all related chains.
219
- ## how to block the related chains ?
220
- ## a cycle has to store all its related chain ids, and also its 30 minute references.
221
- ## so that's it.
222
- ## this is something to execute tomorrow.
223
-
224
- ## so plan for today
225
- ##
219
+
226
220
 
227
221
  end
228
222