Skip to content

Commit

Permalink
Removed passing of token in policies, updated member model can_* mode…
Browse files Browse the repository at this point in the history
…ls to use Current.tokenfor uploader authorization, removed setting of context token from base mutation, resolver, and object
  • Loading branch information
deepsidhu85 committed Jun 5, 2024
1 parent f34461a commit 56f6457
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 32 deletions.
6 changes: 0 additions & 6 deletions app/graphql/mutations/base_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,5 @@ class BaseMutation < GraphQL::Schema::RelayClassicMutation
field_class Types::BaseField
input_object_class Types::BaseInputObject
object_class Types::BaseObject

authorize :token, through: :token

def token
context[:token]
end
end
end
6 changes: 0 additions & 6 deletions app/graphql/resolvers/base_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,5 @@ class BaseResolver < GraphQL::Schema::Resolver
include ActionPolicy::GraphQL::Behaviour

argument_class ::Types::BaseArgument

authorize :token, through: :token

def token
context[:token]
end
end
end
6 changes: 0 additions & 6 deletions app/graphql/types/base_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class BaseObject < GraphQL::Schema::Object
connection_type_class(Types::BaseConnection)
field_class Types::BaseField

authorize :token, through: :token

def token
context[:token]
end

# All graphql fields exposing an id, should expose a global id.
def id
IridaSchema.id_from_object(object)
Expand Down
15 changes: 6 additions & 9 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Member < ApplicationRecord # rubocop:disable Metrics/ClassLength

class << self
DEFAULT_CAN_OPTIONS = {
include_group_links: true,
token: nil
include_group_links: true
}.freeze

def access_levels(member)
Expand Down Expand Up @@ -73,7 +72,7 @@ def can_view?(user, object_namespace, **options)
options = DEFAULT_CAN_OPTIONS.merge(options)
effective_access_level = effective_access_level(object_namespace, user, options[:include_group_links])
if effective_access_level == Member::AccessLevel::UPLOADER &&
(options[:token].nil? || (!options[:token].nil? && !options[:token].active?))
!Current.token&.active?
return false
end

Expand Down Expand Up @@ -152,22 +151,20 @@ def can_create_export?(user, object_namespace)
effective_access_level(object_namespace, user) >= Member::AccessLevel::ANALYST
end

def can_create_sample?(user, object_namespace, **options)
options = DEFAULT_CAN_OPTIONS.merge(options)
def can_create_sample?(user, object_namespace)
effective_access_level = effective_access_level(object_namespace, user)

return true if effective_access_level == Member::AccessLevel::UPLOADER && options[:token]&.active?
return true if (effective_access_level == Member::AccessLevel::UPLOADER) && Current.token&.active?

Member::AccessLevel.manageable.include?(
effective_access_level
)
end

def can_modify_sample?(user, object_namespace, **options)
options = DEFAULT_CAN_OPTIONS.merge(options)
def can_modify_sample?(user, object_namespace)
effective_access_level = effective_access_level(object_namespace, user)

return true if effective_access_level == Member::AccessLevel::UPLOADER && options[:token]&.active?
return true if (effective_access_level == Member::AccessLevel::UPLOADER) && Current.token&.active?

Member::AccessLevel.manageable.include?(
effective_access_level
Expand Down
2 changes: 1 addition & 1 deletion app/policies/group_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def new?
end

def read?
return true if Member.can_view?(user, record, token:) == true
return true if Member.can_view?(user, record) == true

details[:name] = record.name
false
Expand Down
8 changes: 4 additions & 4 deletions app/policies/project_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def new?

def read?
return true if record.namespace.parent.user_namespace? && record.namespace.parent.owner == user
return true if Member.can_view?(user, record.namespace, token:) == true
return true if Member.can_view?(user, record.namespace) == true

details[:name] = record.name
false
Expand Down Expand Up @@ -76,7 +76,7 @@ def sample_listing?

def create_sample?
return true if record.namespace.parent.user_namespace? && record.namespace.parent.owner == user
return true if Member.can_create_sample?(user, record.namespace, token:) == true
return true if Member.can_create_sample?(user, record.namespace) == true

details[:name] = record.name
false
Expand All @@ -92,15 +92,15 @@ def destroy_sample?

def read_sample?
return true if record.namespace.parent.user_namespace? && record.namespace.parent.owner == user
return true if Member.can_view?(user, record.namespace, token:) == true
return true if Member.can_view?(user, record.namespace) == true

details[:name] = record.name
false
end

def update_sample?
return true if record.namespace.parent.user_namespace? && record.namespace.parent.owner == user
return true if Member.can_modify_sample?(user, record.namespace, token:) == true
return true if Member.can_modify_sample?(user, record.namespace) == true

details[:name] = record.name
false
Expand Down

0 comments on commit 56f6457

Please sign in to comment.