Skip to content

Commit

Permalink
Adding missing tests and fixing related functionality
Browse files Browse the repository at this point in the history
Reference: CV2-3765.
  • Loading branch information
caiosba authored Sep 23, 2023
1 parent 7039a67 commit 697e058
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ plugins:
config:
languages:
ruby:
mass_threshold: 30
mass_threshold: 36
bundler-audit:
enabled: true
exclude_patterns:
Expand Down
2 changes: 2 additions & 0 deletions app/graph/mutations/destroy_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def define_behavior(subclass, mutation_target, parents_mapping)
subclass.define_method :resolve do |**inputs|
::GraphqlCrudOperations.destroy(inputs, context, parents_mapping)
end

type_class
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/graph/mutations/duplicate_team_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def resolve(team_id:, custom_slug: nil, custom_name: nil)
user = User.current
ability = Ability.new(user)
team = GraphqlCrudOperations.load_if_can(Team, id, context)
if ability.cannot?(:duplicate, team)
raise I18n.t("team_clone.user_not_authorized")
end
raise I18n.t("team_clone.user_not_authorized") if ability.cannot?(:duplicate, team)
new_team =
Team.duplicate(
team,
Expand Down
6 changes: 2 additions & 4 deletions app/graph/mutations/graphql_crud_operations.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class GraphqlCrudOperations
def self.safe_save(obj, attrs, parent_names = [])
if User.current.nil? && ApiKey.current.nil?
raise "This operation must be done by a signed-in user"
end
raise 'This operation must be done by a signed-in user' if User.current.nil? && ApiKey.current.nil?
attrs.each do |key, value|
method = key == "clientMutationId" ? "client_mutation_id=" : "#{key}="
obj.send(method, value) if obj.respond_to?(method)
Expand Down Expand Up @@ -96,7 +94,7 @@ def self.create(type, inputs, ctx, parents_mapping = {})
self.safe_save(obj, attrs, parents_mapping.keys)
end

def self.update_from_single_id(graphql_id, obj, inputs, ctx, parent_names)
def self.update_from_single_id(_graphql_id, obj, inputs, ctx, parent_names)
obj.file = ctx[:file] unless ctx[:file].blank?

attrs = inputs.keys.inject({}) do |memo, key|
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/default_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def inherited(subclass)
subclass.global_id_field :id
end
end

field :permissions, GraphQL::Types::String, null: true

def permissions
Expand Down
22 changes: 14 additions & 8 deletions app/graph/types/project_media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def log(event_types: nil, field_names: nil, annotation_types: nil, who_dunnit: n
object.get_versions_log(event_types, field_names, annotation_types, who_dunnit, include_related)
end

field :flags, FlagType.connection_type, null: true

def flags
object.get_annotations('flag').map(&:load)
end

field :tags, TagType.connection_type, null: true

def tags
Expand Down Expand Up @@ -254,18 +260,18 @@ def assignments(user_id:, annotation_type:)
end

DynamicAnnotation::AnnotationType.pluck(:annotation_type).each do |type|
field "dynamic_annotations_#{type}".to_sym, DynamicType.connection_type, null: true
field "dynamic_annotations_#{type}".to_sym, DynamicType.connection_type, null: true

define_method("dynamic_annotations_#{type}".to_sym) do |**_inputs|
object.get_annotations(type)
end
define_method("dynamic_annotations_#{type}".to_sym) do |**_inputs|
object.get_annotations(type)
end

field "dynamic_annotation_#{type}".to_sym, DynamicType, null: true
field "dynamic_annotation_#{type}".to_sym, DynamicType, null: true

define_method("dynamic_annotation_#{type}".to_sym) do |**_inputs|
object.get_dynamic_annotation(type)
end
define_method("dynamic_annotation_#{type}".to_sym) do |**_inputs|
object.get_dynamic_annotation(type)
end
end

field :suggested_similar_relationships, RelationshipType.connection_type, null: true

Expand Down
10 changes: 1 addition & 9 deletions app/graph/types/public_team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ def spam_count
private

def archived_count(team)
team.private &&
(!User.current ||
(!User.current.is_admin &&
TeamUser
.where(team_id: team.id, user_id: User.current.id)
.last
.nil?
)
)
team.private && (!User.current || (!User.current.is_admin && TeamUser.where(team_id: team.id, user_id: User.current.id).last.nil?))
end
end
2 changes: 1 addition & 1 deletion app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def me
argument :random, GraphQL::Types::String, required: false
end

def team(id: nil, slug: nil, random: nil)
def team(id: nil, slug: nil, _random: nil)
tid = id.to_i
if !slug.blank?
team = Team.where(slug: slug).first
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/source_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def account_sources
field :medias, ProjectMediaType.connection_type, null: true

def medias
object.media
object.medias
end

field :medias_count, GraphQL::Types::Int, null: true
Expand Down
18 changes: 9 additions & 9 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def get_from_and_to_values(values, tz)
if ['less_than', 'more_than'].include?(condition_type)
period = values.dig('period').to_i
period_date = case values.dig('period_type').downcase
when 'd'
Time.now - period.day
when 'w'
Time.now - period.week
when 'm'
Time.now - period.month
when 'y'
Time.now - period.year
end
when 'd'
Time.now - period.day
when 'w'
Time.now - period.week
when 'm'
Time.now - period.month
when 'y'
Time.now - period.year
end
condition_date = period_date.blank? ? nil : format_time_with_timezone(period_date.to_s, tz)
if condition_type == 'less_than'
from = condition_date
Expand Down
57 changes: 57 additions & 0 deletions lib/relay.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8532,6 +8532,42 @@ type Flag implements Node {
version: Version
}

"""
The connection type for Flag.
"""
type FlagConnection {
"""
A list of edges.
"""
edges: [FlagEdge]

"""
A list of nodes.
"""
nodes: [Flag]

"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
totalCount: Int
}

"""
An edge in a connection.
"""
type FlagEdge {
"""
A cursor for use in pagination.
"""
cursor: String!

"""
The item at the end of the edge.
"""
node: Flag
}

"""
Autogenerated input type of GenerateTwoFactorBackupCodes
"""
Expand Down Expand Up @@ -11100,6 +11136,27 @@ type ProjectMedia implements Node {
): DynamicConnection
feed_columns_values: JsonStringType
field_value(annotation_type_field_name: String!): String
flags(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Returns the elements in the list that come before the specified cursor.
"""
before: String

"""
Returns the first _n_ elements from the list.
"""
first: Int

"""
Returns the last _n_ elements from the list.
"""
last: Int
): FlagConnection
full_url: String
id: ID!
is_confirmed: Boolean
Expand Down
Loading

0 comments on commit 697e058

Please sign in to comment.