Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropzone Settings fixes #122

Merged
merged 3 commits into from
Apr 22, 2023
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
30 changes: 16 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.14.0)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
os (1.1.4)
parallel (1.22.1)
parallel (1.23.0)
parallel_tests (4.1.0)
parallel
parser (3.2.0.0)
parser (3.2.2.0)
ast (~> 2.4.1)
pg (1.4.5)
polyglot (0.3.5)
Expand Down Expand Up @@ -342,12 +342,13 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (2.8.4)
redis (4.8.0)
reek (6.1.4)
kwalify (~> 0.7.0)
parser (~> 3.2.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.6.1)
regexp_parser (2.8.0)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
Expand Down Expand Up @@ -383,18 +384,18 @@ GEM
rspec-support (3.12.0)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.43.0)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-graphql (0.18.0)
rubocop (>= 0.87, < 2)
rubocop-performance (1.15.2)
Expand All @@ -408,7 +409,7 @@ GEM
rubocop (~> 1.33)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
Expand All @@ -428,18 +429,19 @@ GEM
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
solargraph (0.48.0)
solargraph (0.49.0)
backport (~> 1.2)
benchmark
bundler (>= 1.17.2)
bundler (~> 2.0)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
reverse_markdown (>= 1.0.5, < 3)
rubocop (>= 0.52)
rbs (~> 2.0)
reverse_markdown (~> 2.0)
rubocop (~> 1.38)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
Expand All @@ -459,7 +461,7 @@ GEM
activerecord (>= 5.1)
state_machines-activemodel (>= 0.8.0)
thor (1.2.1)
tilt (2.0.11)
tilt (2.1.0)
timeout (0.3.1)
trailblazer-option (0.1.2)
treetop (1.6.12)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/setup/equipment/create_rig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def resolve(attributes:)
User.find(attributes[:user_id]).rigs.new
else
Dropzone.find(attributes[:dropzone_id]).rigs.new
end
end

attrs = attributes.to_h.except(:packing_card)

Expand Down
13 changes: 5 additions & 8 deletions app/graphql/mutations/users/update_dropzone_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ class UpdateDropzoneUser < Mutations::BaseMutation
argument :dropzone_user, ID, required: false,
prepare: -> (value, ctx) { DropzoneUser.find_by(id: value) }

def resolve(attributes:, id: nil)
model = DropzoneUser.find(id)

def resolve(dropzone_user:, attributes: nil)
attrs = attributes.to_h
if attrs[:expires_at]
attrs[:expires_at] = Time.at(attributes[:expires_at])
end
model.assign_attributes(attrs)
model.save!
dropzone_user.assign_attributes(attrs)
dropzone_user.save!

{
dropzone_user: model,
Expand Down Expand Up @@ -47,15 +45,14 @@ def resolve(attributes:, id: nil)
}
end

def authorized?(id: nil, attributes: nil)
dropzone_user = DropzoneUser.find(id)
def authorized?(dropzone_user: nil, attributes: nil)
current_dz_user = context[:current_resource].dropzone_users.find_by(
dropzone: dropzone_user.dropzone
)

allowed_to_update_others = current_dz_user.can?(:updateUser)
is_role_changed = attributes[:user_role_id] && attributes[:user_role_id] != dropzone_user.user_role_id
is_allowed_to_change_role = current_dz_user.can?(:grantPermission) && attributes[:user_role_id] < current_dz_user.user_role_id
is_allowed_to_change_role = !is_role_changed || (current_dz_user.can?(:grantPermission) && attributes[:user_role_id] < current_dz_user.user_role_id)

# Check if the user is trying to change the UserRole:
if allowed_to_update_others && is_role_changed && !is_allowed_to_change_role
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/dropzone/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class Types::Dropzone::Settings < Types::Base::Object
description: 'Allow manifest to bypass all rules?'
field :allow_double_manifesting, Boolean, null: true,
description: 'Allow users to double-manifest'
field :require_reserve_in_date, Boolean, null: true,
description: 'When this is enabled, users cannot manifest if their reserve is out of date'
field :require_equipment, Boolean, null: true,
description: 'When this is enabled, users cannot manifest if they have no equipment'
end
7 changes: 7 additions & 0 deletions app/graphql/types/input/dropzone/settings_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ class Types::Input::Dropzone::SettingsInput < Types::Base::Input
description: 'When this is enabled, users can manifest even if they go into negatives'
argument :allow_manifest_bypass, Boolean, required: false,
description: 'Allow manifest to bypass all rules?'

argument :require_reserve_in_date, Boolean, required: false,
description: 'When this is enabled, users cannot manifest if their reserve is out of date'
argument :require_equipment, Boolean, required: false,
description: 'When this is enabled, users cannot manifest if they have no equipment'
argument :allow_double_manifesting, Boolean, required: false,
description: 'Allow users to double-manifest'
end
12 changes: 7 additions & 5 deletions app/interactions/federations/apf_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Federations::ApfSync < ApplicationInteraction
end

def save!
errors.merge!(user_federation.errors) unless user_federation.save
user_federation.save
errors.merge!(user_federation.errors) if user_federation.errors.any?
user_federation
end

Expand Down Expand Up @@ -107,7 +108,7 @@ def assign_qualifications
@qualifications = user_info["Qualifications"].filter_map do |license_or_crest|
next if /Certificate/i.match?(license_or_crest["Qualification"])

UserFederationQualification.find_or_create_by({
attrs = {
qualification: Qualification.find_by(
name: license_or_crest["Qualification"],
federation: user_federation.federation,
Expand All @@ -119,8 +120,9 @@ def assign_qualifications
DateTime.parse(license_or_crest["ExpiryDate"])
else
nil
end
))
end,
)
UserFederationQualification.find_or_create_by(attrs)
end
rescue
nil
Expand All @@ -144,7 +146,7 @@ def assign_license
if license = user_federation.federation.licenses.where(name: @licenses.keys).order(id: :desc).first
user_federation.assign_attributes(
license: license,
license_number: @licenses[license.name]["SerialNumber"]
license_number: @licenses.dig(license.name, "SerialNumber") || ''
)
errors.merge!(user_federation.errors) unless user_federation.save
end
Expand Down
15 changes: 7 additions & 8 deletions app/interactions/federations/assign_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class Federations::AssignUser < ApplicationInteraction
record :federation
record :license, default: nil
record :license, default: -> { federation.licenses.first }
record :user
string :uid, default: nil
string :uid, default: ''
validates :federation, :user, presence: true

steps :assign_user_to_federation,
Expand Down Expand Up @@ -46,25 +46,24 @@ def save!
end

def manually_assign_license
return unless license
@user_federation.assign_attributes(
license: license
license: license || federation.licenses.first,
license_number: ''
)
errors.merge!(@user_federation.errors) unless @user_federation.save
end

def assign_user_to_federation
@user_federation = UserFederation.find_or_initialize_by(
@user_federation ||= UserFederation.find_or_initialize_by(
federation: federation,
user: user
)
end

def assign_user_federation_uid
return if uid.nil?
@user_federation.assign_attributes(
uid: uid
uid: uid || ' '
)
errors.merge!(@user_federation.errors) unless @user_federation.save
end

def synchronize_qualifications
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/dropzones/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def default_settings
allow_manifest_bypass: false,
# Allow double-manifesting?
allow_double_manifesting: false,
# Allow manifesting without equipment?
require_equipment: true,

# Allow manifesting without reserve in date?
require_reserve_in_date: true,
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
workers ENV.fetch("WEB_CONCURRENCY", 2)

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/resolvers/users/dropzone_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Mutations
end

it { expect(subject[:dropzoneUsers][:edges].size).to eq(4) }
it { is_expected.to include_json(dropzoneUsers: { edges: [{ node: { id: fun_jumper.id.to_s }}, { node: { id: instructor.id.to_s }}, { node: { id: student.id.to_s }}, { node: { id: ghost.id.to_s } }] }) }
it { is_expected.to include_json(dropzoneUsers: { edges: [{ node: { id: fun_jumper.id.to_s } }, { node: { id: instructor.id.to_s } }, { node: { id: student.id.to_s } }, { node: { id: ghost.id.to_s } }] }) }
end

create_query(:dropzone_id) do
Expand Down