Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Sep 28, 2023
2 parents c8518db + 1ce2528 commit c22ae98
Show file tree
Hide file tree
Showing 58 changed files with 1,993 additions and 624 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
6 changes: 0 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ deploy_qa:
- alias aws='docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION --rm amazon/aws-cli'
- aws ssm get-parameters-by-path --region $AWS_DEFAULT_REGION --path /qa/check-api/ --recursive --with-decryption --output text --query "Parameters[].[Name]" | sed -E 's#/qa/check-api/##' > env.qa.names
- for NAME in `cat env.qa.names`; do echo -n "-s qa-check-api-migration $NAME /qa/check-api/$NAME " >> qa-check-api-migration.env.args; done
- echo -n "-s qa-check-api-migration GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> qa-check-api-migration.env.args
- ecs update qa-check-api-migration --image qa-check-api-migration $ECR_API_BASE_URL/qa/check/api:$CI_COMMIT_SHA --exclusive-env -e qa-check-api-migration APP check-api -e qa-check-api-migration DEPLOY_ENV qa -e qa-check-api-migration AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat qa-check-api-migration.env.args`
- taskArn=$(aws ecs run-task --cluster ecs-qa --task-definition qa-check-api-migration --query 'tasks[].taskArn' --output text)
- echo "Migration task started - $taskArn"
- aws ecs wait tasks-stopped --cluster ecs-qa --tasks $taskArn
- for NAME in `cat env.qa.names`; do echo -n "-s qa-check-api-c $NAME /qa/check-api/$NAME " >> qa-check-api-c.env.args; done
- echo -n "-s qa-check-api-c GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> qa-check-api-c.env.args
- ecs deploy ecs-qa qa-check-api --image qa-check-api-c $ECR_API_BASE_URL/qa/check/api:$CI_COMMIT_SHA --timeout 3600 --exclusive-env -e qa-check-api-c APP check-api -e qa-check-api-c DEPLOY_ENV qa -e qa-check-api-c AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat qa-check-api-c.env.args`
- for NAME in `cat env.qa.names`; do echo -n "-s qa-check-api-background $NAME /qa/check-api/$NAME " >> qa-check-api-background.env.args; done
- echo -n "-s qa-check-api-background GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> qa-check-api-background.env.args
- ecs deploy ecs-qa qa-check-api-background --image qa-check-api-background $ECR_API_BASE_URL/qa/check/api:$CI_COMMIT_SHA --timeout 3600 --exclusive-env -e qa-check-api-background APP check-api -e qa-check-api-background DEPLOY_ENV qa -e qa-check-api-background AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat qa-check-api-background.env.args`
- echo "new Image was deployed $ECR_API_BASE_URL/qa/check/api:$CI_COMMIT_SHA"
only:
Expand Down Expand Up @@ -124,18 +121,15 @@ deploy_live:
- alias aws='docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION --rm amazon/aws-cli'
- aws ssm get-parameters-by-path --region $AWS_DEFAULT_REGION --path /live/check-api/ --recursive --with-decryption --output text --query "Parameters[].[Name]" | sed -E 's#/live/check-api/##' > env.live.names
- for NAME in `cat env.live.names`; do echo -n "-s live-check-api-migration $NAME /live/check-api/$NAME " >> live-check-api-migration.env.args; done
- echo -n "-s live-check-api-migration GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> live-check-api-migration.env.args
- ecs update live-check-api-migration --image live-check-api-migration $ECR_API_BASE_URL/live/check/api:$CI_COMMIT_SHA --exclusive-env -e live-check-api-migration APP check-api -e live-check-api-migration DEPLOY_ENV live -e live-check-api-migration AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat live-check-api-migration.env.args`
- taskArn=$(aws ecs run-task --cluster ecs-live --task-definition live-check-api-migration --query 'tasks[].taskArn' --output text)
- echo "Migration task started - $taskArn"
- aws ecs wait tasks-stopped --cluster ecs-live --tasks $taskArn
- for NAME in `cat env.live.names`; do echo -n "-s live-check-api-c $NAME /live/check-api/$NAME " >> live-check-api-c.env.args; done
- echo -n "-s live-check-api-c GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> live-check-api-c.env.args
- python3 scripts/uptime-maintenance.py on
- ecs deploy ecs-live live-check-api --image live-check-api-c $ECR_API_BASE_URL/live/check/api:$CI_COMMIT_SHA --timeout 3600 --exclusive-env -e live-check-api-c APP check-api -e live-check-api-c DEPLOY_ENV live -e live-check-api-c AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat live-check-api-c.env.args`
- python3 scripts/uptime-maintenance.py off
- for NAME in `cat env.live.names`; do echo -n "-s live-check-api-background $NAME /live/check-api/$NAME " >> live-check-api-background.env.args; done
- echo -n "-s live-check-api-background GITHUB_TOKEN arn:aws:secretsmanager:eu-west-1:848416313321:secret:GithubToken-Plain-BUhwIw" >> live-check-api-background.env.args
- ecs deploy ecs-live live-check-api-background --image live-check-api-background $ECR_API_BASE_URL/live/check/api:$CI_COMMIT_SHA --timeout 3600 --exclusive-env -e live-check-api-background APP check-api -e live-check-api-background DEPLOY_ENV live -e live-check-api-background AWS_REGION $AWS_DEFAULT_REGION --exclusive-secrets `cat live-check-api-background.env.args`
- echo "new Image was deployed $ECR_API_BASE_URL/live/check/api:$CI_COMMIT_SHA"
only:
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @caiosba @melsawy
* @caiosba @melsawy @DGaffney
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
18 changes: 18 additions & 0 deletions app/graph/mutations/tipline_message_mutations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module TiplineMessageMutations
class Send < Mutations::BaseMutation
argument :in_reply_to_id, GraphQL::Types::Int, required: true # Database ID of a tipline request ("smooch" annotation)
argument :message, GraphQL::Types::String, required: true

field :success, GraphQL::Types::Boolean, null: true

def resolve(in_reply_to_id: nil, message: nil)
request = Annotation.find(in_reply_to_id).load
ability = context[:ability] || Ability.new
success = false
if Team.current&.id && User.current&.id && ability.can?(:send, TiplineMessage.new(team: Team.current)) && request.annotated.team_id == Team.current.id
success = Bot::Smooch.reply_to_request_with_custom_message(request, message)
end
{ success: success }
end
end
end
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
1 change: 1 addition & 0 deletions app/graph/types/dynamic_annotation_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DynamicAnnotationFieldType < DefaultObject
field :dbid, GraphQL::Types::Int, null: true
field :value_json, JsonStringType, null: true
field :annotation, AnnotationType, null: true
field :annotation_id, GraphQL::Types::Int, null: true
field :associated_graphql_id, GraphQL::Types::String, null: true
field :smooch_user_slack_channel_url, GraphQL::Types::String, null: true
field :smooch_user_external_identifier, GraphQL::Types::String, null: true
Expand Down
2 changes: 2 additions & 0 deletions app/graph/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ class MutationType < BaseObject
field :createTiplineResource, mutation: TiplineResourceMutations::Create
field :updateTiplineResource, mutation: TiplineResourceMutations::Update
field :destroyTiplineResource, mutation: TiplineResourceMutations::Destroy

field :sendTiplineMessage, mutation: TiplineMessageMutations::Send
end
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
3 changes: 2 additions & 1 deletion app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def me

def team(id: nil, slug: nil, random: nil)
tid = id.to_i
if !slug.blank?
unless slug.blank?
team = Team.where(slug: slug).first
tid = team.id unless team.nil?
end
team.reload if random
tid = Team.current&.id || User.current&.teams&.first&.id if tid === 0
GraphqlCrudOperations.load_if_can(Team, tid.to_i, context)
end
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
8 changes: 8 additions & 0 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,12 @@ def shared_teams
field :feeds, FeedType.connection_type, null: true
field :tipline_newsletters, TiplineNewsletterType.connection_type, null: true
field :tipline_resources, TiplineResourceType.connection_type, null: true

field :tipline_messages, TiplineMessageType.connection_type, null: true do
argument :uid, GraphQL::Types::String, required: true
end

def tipline_messages(uid:)
object.tipline_messages.where(uid: uid).last(100)
end
end
22 changes: 22 additions & 0 deletions app/graph/types/tipline_message_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class TiplineMessageType < DefaultObject
description "TiplineMessage type"

implements GraphQL::Types::Relay::Node

field :dbid, GraphQL::Types::Int, null: true
field :event, GraphQL::Types::String, null: true
field :direction, GraphQL::Types::String, null: true
field :language, GraphQL::Types::String, null: true
field :platform, GraphQL::Types::String, null: true
field :uid, GraphQL::Types::String, null: true
field :external_id, GraphQL::Types::String, null: true
field :payload, JsonStringType, null: true
field :team_id, GraphQL::Types::Int, null: true
field :state, GraphQL::Types::String, null: true
field :team, TeamType, null: true
field :sent_at, GraphQL::Types::String, null: true, camelize: false

def sent_at
object.sent_at.to_i.to_s
end
end
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
Loading

0 comments on commit c22ae98

Please sign in to comment.