Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
class ErrorsController < NonApiApplicationController
def not_found
if request.content_type&.include?("application/json")
render json: {code: 404, error_message: "Not found."}, status: 404
else
render status: 404
end
render_error(404, "Not found.")
end

def internal_server_error
render_error(500, "Internal server error.")
end

private

def render_error(status, message)
if request.content_type&.include?("application/json")
render json: {code: 500, error_message: "Internal server error."}, status: 500
render json: {code: status, error_message: message}, status: status
else
render status: 500
render status: status
end
end
end
10 changes: 7 additions & 3 deletions app/controllers/shopkeeper_auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ def render_destroy_success
end

def render_create_error
render json: {code: 422, error_message: @resource.errors.full_messages.to_sentence}, status: :unprocessable_entity
render_resource_error
end

def render_update_error
render json: {code: 422, error_message: @resource.errors.full_messages.to_sentence}, status: :unprocessable_entity
render_resource_error
end

def render_destroy_error
render json: {code: 422, error_message: @resource.errors.full_messages.to_sentence}, status: :unprocessable_entity
render_resource_error
end

private

def render_resource_error
render json: {code: 422, error_message: @resource.errors.full_messages.to_sentence}, status: :unprocessable_entity
end

def validate_sign_up_params
return if sign_up_params.present?

Expand Down
6 changes: 3 additions & 3 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def reached_limit_shop_count?
end

def limit_count
the_limit_count = ConfigSettings.account.limit_count
return if owner.owned_accounts.count < the_limit_count
limit = ConfigSettings.account.limit_count
return if owner.owned_accounts.count < limit

errors.add :base, :limit_count_account, limit_count: the_limit_count
errors.add :base, :limit_count_account, limit_count: limit
end
end
10 changes: 3 additions & 7 deletions app/models/accounts_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ def to_param
private

def set_token
the_token = nil

loop do
the_token = random_token
break unless AccountsInvitation.exists?(token: the_token)
self.token = loop do
candidate = random_token
break candidate unless AccountsInvitation.exists?(token: candidate)
end

self.token = the_token
end

def random_token
Expand Down
6 changes: 3 additions & 3 deletions app/models/accounts_shopkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def owner_must_be_admin
end

def limit_count
the_limit_count = ConfigSettings.accounts_shopkeeper.limit_count
return if account.accounts_shopkeepers.count < the_limit_count
limit = ConfigSettings.accounts_shopkeeper.limit_count
return if account.accounts_shopkeepers.count < limit

errors.add :base, :limit_count_accounts_shopkeeper, limit_count: the_limit_count
errors.add :base, :limit_count_accounts_shopkeeper, limit_count: limit
end
end
6 changes: 3 additions & 3 deletions app/models/item_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def set_default_position
end

def limit_count
the_limit_count = ConfigSettings.item_tag.limit_count
return if shop.item_tags.count < the_limit_count
limit = ConfigSettings.item_tag.limit_count
return if shop.item_tags.count < limit

errors.add :base, :limit_count_item_tag, limit_count: the_limit_count
errors.add :base, :limit_count_item_tag, limit_count: limit
end
end
6 changes: 3 additions & 3 deletions app/models/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def create_sample_item_tag

def limit_count
ActsAsTenant.without_tenant do
the_limit_count = ConfigSettings.shop.limit_count
return if created_by.created_shops.count < the_limit_count
limit = ConfigSettings.shop.limit_count
return if created_by.created_shops.count < limit

errors.add :base, :limit_count_shop, limit_count: the_limit_count
errors.add :base, :limit_count_shop, limit_count: limit
end
end
end
2 changes: 0 additions & 2 deletions app/models/shopkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def send_confirmation_instructions(opts = {})
opts[:to] = unconfirmed_email if pending_reconfirmation?
opts[:redirect_url] ||= DeviseTokenAuth.default_confirm_success_url

# send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
Shopkeeper::NotificationMailer.with(resource: self, token: @raw_confirmation_token, opts: opts).confirmation_instructions.deliver_later
end

Expand All @@ -45,7 +44,6 @@ def send_reset_password_instructions(opts = {})
# fall back to "default" config name
opts[:client_config] ||= "default"

# send_devise_notification(:reset_password_instructions, token, opts)
Shopkeeper::NotificationMailer.with(resource: self, token: token, opts: opts).reset_password_instructions.deliver_later

token
Expand Down