lato 0.1.57 → 0.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8124b34e4bbd5bc9858fe5016ac06c7978acf8b0b0106c440cfb8abbaf805735
4
- data.tar.gz: ee86acb19e3d81233fbc1b5adecffda2595005c752eb612a56072d967bd224bd
3
+ metadata.gz: 4cc5abe2007e8028c5de1b2e4f76a4a9b93412e862059cb69b36e4940a37650f
4
+ data.tar.gz: d89a0f0b13c2e994c063f6659f8e4456bbc695e701b0934d5686be005f0ca618
5
5
  SHA512:
6
- metadata.gz: 2e3a0c4e8b55176d77078c17d096a3ea7ba2f9568193594eac3fc1fc0d8c64fe523e1ab778eae9e9dcbdf979baecbd1bd82b8d45b240fe8818f710029bd086f5
7
- data.tar.gz: a423547cef8c1ef0da6ec206305afa3acc34ad8a29bdf404e1c506bc6a63d50212aacdcc31daef0068d4043283acceaf5547ed5af3882afa20313e5188607854
6
+ metadata.gz: 582c91f202e59201d654e1f3582070ee8c8a43797d44ca5c387a2732220b48c34487856175748eb4be480f418f94be3c4ee1abc03e601fbffef2b267f08957bd
7
+ data.tar.gz: e3798419615b5a8ac29ba9e824ca2fa6fa030567902edda06e1ac0d890d36c57db14f878f3da75a498ee6238d32e796d04d43310d1f027f700a62fd2c3bd74e8
@@ -1,5 +1,22 @@
1
1
  /** Import dependencies */
2
2
 
3
+ $primary: #03256c !default;
4
+ $secondary: #1768ac !default;
5
+ $success: #007a34 !default;
6
+ $danger: #f50032 !default;
7
+ $warning: #ffcc00 !default;
8
+ $info: #0017ed !default;
9
+
10
+ $gray-100: #ebeff4 !default;
11
+ $gray-200: #dde3e9 !default;
12
+ $gray-300: #d3dae1 !default;
13
+ $gray-400: #c3ccd5 !default;
14
+ $gray-500: #a4afba !default;
15
+ $gray-600: #66727d !default;
16
+ $gray-700: #454f58 !default;
17
+ $gray-800: #313a42 !default;
18
+ $gray-900: #1f262c !default;
19
+
3
20
  @import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css");
4
21
  @import "bootstrap";
5
22
 
@@ -4,6 +4,7 @@ module Lato
4
4
  include Lato::Layoutable
5
5
  include Lato::Componentable
6
6
 
7
+ before_action :override_request_remote_ip
7
8
  before_action :set_default_locale
8
9
 
9
10
  def index
@@ -19,12 +20,37 @@ module Lato
19
20
 
20
21
  protected
21
22
 
23
+ # This method override the request remote ip with the X-Forwarded-For header if exists.
24
+ # This method is used to get the real ip of the user when the application is behind a proxy.
25
+ # For example if the application is behind a nginx proxy the request.remote_ip will be the ip of the proxy and not the ip of the user.
26
+ def override_request_remote_ip
27
+ request.remote_ip = request.headers['X-Forwarded-For'] if request.headers['X-Forwarded-For']
28
+ end
29
+
30
+ # This method set the default locale for the application.
31
+ # The default locale is the locale of the user if exists, otherwise is the default locale of the application.
22
32
  def set_default_locale
23
33
  return unless @session.valid?
24
34
 
25
35
  I18n.locale = @session.user.locale || I18n.default_locale
26
36
  end
27
37
 
38
+ # This method limit the number of requests for a specific action.
39
+ # Usage: before_action :limit_requests, only: %i[:action_name]
40
+ def limit_requests(limit = 10, time_window = 10.minutes)
41
+ cache_key = "Lato::ApplicationController.limit_requests/#{controller_name}/#{action_name}/#{request.remote_ip}"
42
+ attempts = Rails.cache.read(cache_key) || 0
43
+
44
+ attempts += 1
45
+ Rails.cache.write(cache_key, attempts, expires_in: time_window)
46
+ return unless attempts >= limit
47
+
48
+ respond_to do |format|
49
+ format.html { render plain: "Too many requests, please wait #{time_window.to_i / 60} minutes to retry.", status: :too_many_requests }
50
+ format.json { render json: {}, status: :too_many_requests }
51
+ end
52
+ end
53
+
28
54
  def respond_to_with_not_found
29
55
  respond_to do |format|
30
56
  format.html { render plain: '', status: :not_found }
@@ -1,5 +1,6 @@
1
1
  module Lato
2
2
  class AuthenticationController < ApplicationController
3
+ before_action :limit_requests, only: %i[signin_action signup_action accept_invitation_action recover_password_action update_password_action]
3
4
  before_action :not_authenticate_session, only: %i[signin signin_action signup signup_action accept_invitation accept_invitation_action]
4
5
  before_action :authenticate_session, only: %i[signout signout_action]
5
6
 
@@ -48,7 +49,7 @@ module Lato
48
49
  @user = Lato::User.new(registration_params)
49
50
 
50
51
  respond_to do |format|
51
- if @user.save
52
+ if @user.signup(ip_address: request.remote_ip, user_agent: request.user_agent)
52
53
  session_create(@user.id)
53
54
 
54
55
  format.html { redirect_to lato.root_path }
@@ -5,24 +5,26 @@ module Lato
5
5
 
6
6
  protected
7
7
 
8
+ # This method is used to check if the job is running inside an operation.
8
9
  def operation?
9
10
  !!@operation
10
11
  end
11
12
 
13
+ # This method returns the input file attached to the operation if exists.
12
14
  def operation_input_file_attachment
13
15
  @operation.input_file.attached? ? @operation.input_file : nil
14
16
  end
15
17
 
18
+ # This method can be used to update the percentage of the operation.
16
19
  def update_operation_percentage(percentage)
17
20
  return false unless operation?
18
21
 
19
22
  @operation.update(
20
23
  percentage: percentage
21
24
  )
22
-
23
- true
24
25
  end
25
26
 
27
+ # This method can be used to save a file as output of the operation.
26
28
  def save_operation_output_file(file_path)
27
29
  return false unless operation?
28
30
 
@@ -32,10 +34,9 @@ module Lato
32
34
  io: file,
33
35
  filename: file_name
34
36
  )
35
-
36
- true
37
37
  end
38
38
 
39
+ # This method can be used to save a text message as output of the operation.
39
40
  def save_operation_output_message(message)
40
41
  return false unless operation?
41
42
 
@@ -48,6 +49,7 @@ module Lato
48
49
 
49
50
  private
50
51
 
52
+ # This function is used to manage the operation and manage custom errors.
51
53
  def manage_operation
52
54
  @operation = Lato::Operation.find(arguments.first[:_operation_id]) if arguments.first && arguments.first.is_a?(Hash) && !arguments.first[:_operation_id].blank?
53
55
  @operation&.running
@@ -0,0 +1,15 @@
1
+ module Lato
2
+ class Log::UserSignup < ApplicationRecord
3
+ # Relations
4
+ ##
5
+
6
+ belongs_to :lato_user, class_name: 'Lato::User', foreign_key: :lato_user_id, optional: true
7
+
8
+ # Hooks
9
+ ##
10
+
11
+ before_destroy do
12
+ throw :abort
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Lato
2
2
  module Log
3
3
  def self.table_name_prefix
4
- 'lato_log_'
4
+ "lato_log_"
5
5
  end
6
6
  end
7
7
  end
@@ -10,6 +10,11 @@ module Lato
10
10
  has_one_attached :input_file
11
11
  has_one_attached :output_file
12
12
 
13
+ # Validations
14
+ ##
15
+
16
+ validates :percentage, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }, allow_nil: true
17
+
13
18
  # Relations
14
19
  ##
15
20
 
@@ -28,6 +28,7 @@ module Lato
28
28
  has_many :lato_invitations_as_inviter, class_name: 'Lato::Invitation', foreign_key: :inviter_lato_user_id, dependent: :nullify
29
29
 
30
30
  has_many :lato_log_user_signins, class_name: 'Lato::Log::UserSignin', foreign_key: :lato_user_id, dependent: :nullify
31
+ has_many :lato_log_user_signups, class_name: 'Lato::Log::UserSignup', foreign_key: :lato_user_id, dependent: :nullify
31
32
 
32
33
  # Hooks
33
34
  ##
@@ -67,6 +68,21 @@ module Lato
67
68
  # Operations
68
69
  ##
69
70
 
71
+ def signup(params = {})
72
+ return unless save
73
+
74
+ begin
75
+ lato_log_user_signups.create(
76
+ ip_address: params[:ip_address],
77
+ user_agent: params[:user_agent]
78
+ )
79
+ rescue StandardError => e
80
+ Rails.logger.error(e)
81
+ end
82
+
83
+ true
84
+ end
85
+
70
86
  def signin(params)
71
87
  self.email = params[:email]
72
88
 
@@ -0,0 +1,10 @@
1
+ class CreateLatoLogUserSignups < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :lato_log_user_signups do |t|
4
+ t.string :ip_address
5
+ t.string :user_agent
6
+ t.references :lato_user, index: true, foreign_key: true
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
data/lib/lato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lato
2
- VERSION = "0.1.57"
2
+ VERSION = "0.1.59"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.57
4
+ version: 0.1.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -140,6 +140,7 @@ files:
140
140
  - app/models/lato/invitation.rb
141
141
  - app/models/lato/log.rb
142
142
  - app/models/lato/log/user_signin.rb
143
+ - app/models/lato/log/user_signup.rb
143
144
  - app/models/lato/operation.rb
144
145
  - app/models/lato/session.rb
145
146
  - app/models/lato/user.rb
@@ -199,6 +200,7 @@ files:
199
200
  - db/migrate/20230109054412_create_lato_log_user_signins.rb
200
201
  - db/migrate/20230109061533_create_lato_invitations.rb
201
202
  - db/migrate/20230212211748_add_inviter_lato_user_id_to_invitations.rb
203
+ - db/migrate/20230823165716_create_lato_log_user_signups.rb
202
204
  - lib/lato.rb
203
205
  - lib/lato/btstrap.rb
204
206
  - lib/lato/config.rb