Skip to content

Commit

Permalink
Require registration_secret only from users controller
Browse files Browse the repository at this point in the history
  • Loading branch information
just806me committed Sep 30, 2023
1 parent 6f5965a commit 46a23af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def collection
end

def resource_params
params.require(:user).permit(PERMITTED_PARAMS).merge(registration_ips: ip_addresses, device_id: @device_id)
params.require(:user).permit(PERMITTED_PARAMS).merge(registration_ips: ip_addresses, device_id: @device_id,
registration_secret_required: true)

Check notice

Code scanning / Rubocop

Align the arguments of a method call if they span more than one line. Note

Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.
end

def initialize_resource
Expand Down
9 changes: 6 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class User < ApplicationRecord
attr_accessor :registration_secret
attr_accessor :registration_secret, :registration_secret_required

validates :name, :email, :city, :institution, :contest_site, :grade, presence: true
validates :name, :secret, :judge_secret, uniqueness: { scope: :contest }
validates :registration_secret, presence: true, on: :create
validate :registration_secret_must_be_valid, on: :create

with_options if: :registration_secret_required, on: :create do
validates :registration_secret, presence: true
validate :registration_secret_must_be_valid
end

belongs_to :contest, inverse_of: :users
has_many :solutions, inverse_of: :user, dependent: :destroy
Expand Down

0 comments on commit 46a23af

Please sign in to comment.