Skip to content

Commit

Permalink
Merge branch 'develop' into cv2-4126-video
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney authored Feb 8, 2024
2 parents 6c77840 + fdbabff commit 2d9d6ad
Show file tree
Hide file tree
Showing 103 changed files with 4,124 additions and 4,655 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ gem 'elasticsearch-persistence', '7.1.1'
gem 'paper_trail', '13.0.0'
gem 'graphiql-rails', git: 'https://github.com/meedan/graphiql-rails.git', ref: '8db0eac'
gem 'graphql-formatter'
gem 'nokogiri', '1.14.3'
gem 'nokogiri', '1.16.2'
gem 'puma'
gem 'rack-attack'
gem 'rack-cors', '1.0.6', require: 'rack/cors'
gem 'sidekiq', '5.2.10'
gem 'sidekiq-cloudwatchmetrics'
Expand Down
13 changes: 8 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ GEM
mime-types-data (3.2022.0105)
mini_magick (4.10.1)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
mini_portile2 (2.8.5)
minitest (5.19.0)
minitest-hooks (1.5.0)
minitest (> 5.3)
Expand All @@ -447,8 +447,8 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.16.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
numerizer (0.1.1)
oauth (0.5.8)
Expand Down Expand Up @@ -635,8 +635,10 @@ GEM
pusher-signature (~> 0.1.8)
pusher-signature (0.1.8)
raabro (1.4.0)
racc (1.7.1)
racc (1.7.3)
rack (2.2.6.4)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-cors (1.0.6)
rack (>= 1.6.0)
rack-protection (2.2.0)
Expand Down Expand Up @@ -939,7 +941,7 @@ DEPENDENCIES
minitest-retry
mocha (~> 2.0)
multi_json (= 1.15.0)
nokogiri (= 1.14.3)
nokogiri (= 1.16.2)
omniauth-facebook
omniauth-google-oauth2!
omniauth-slack
Expand Down Expand Up @@ -983,6 +985,7 @@ DEPENDENCIES
puma
pusher
rack (= 2.2.6.4)
rack-attack
rack-cors (= 1.0.6)
rack-protection (= 2.2.0)
railroady
Expand Down
2 changes: 1 addition & 1 deletion app/graph/mutations/graphql_crud_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.define_returns(obj, parent_names)
ret["#{obj_name}Edge".to_sym] = GraphQL::Relay::Edge.between(
child,
parent
) if !%w[related_to public_team version].include?(parent_name)
) if !%w[related_to public_team version me].include?(parent_name)
ret[parent_name.to_sym] = parent
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/graph/mutations/tipline_message_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Send < Mutations::BaseMutation
field :success, GraphQL::Types::Boolean, null: true

def resolve(in_reply_to_id: nil, message: nil)
request = Annotation.find(in_reply_to_id).load
request = TiplineRequest.find(in_reply_to_id)
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
if Team.current&.id && User.current&.id && ability.can?(:send, TiplineMessage.new(team: Team.current)) && request.team_id == Team.current.id
success = Bot::Smooch.reply_to_request_with_custom_message(request, message)
end
{ success: success }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UserDisconnectLoginAccountMutation < Mutations::BaseMutation
argument :uid, GraphQL::Types::String, required: true

field :success, GraphQL::Types::Boolean, null: true
field :user, UserType, null: true
field :user, MeType, null: true

def resolve(provider:, uid:)
user = User.current
Expand Down
2 changes: 1 addition & 1 deletion app/graph/mutations/user_mutations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module UserMutations
MUTATION_TARGET = 'user'.freeze
PARENTS = [].freeze
PARENTS = ['me'].freeze

module SharedCreateAndUpdateFields
extend ActiveSupport::Concern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserTwoFactorAuthenticationMutation < Mutations::BaseMutation
argument :otp_required, GraphQL::Types::Boolean, required: false, camelize: false

field :success, GraphQL::Types::Boolean, null: true
field :user, UserType, null: true
field :user, MeType, null: true

def resolve(id:, password:, qrcode: nil, otp_required: nil)
user = User.where(id: id).last
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/bot_user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def settings_as_json_schema(team_slug: nil)
object.settings_as_json_schema(false, team_slug)
end

field :team_author, TeamType, null: true
field :team_author, PublicTeamType, null: true

def team_author
RecordLoader.for(Team).load(object.team_author_id.to_i)
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/feed_team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FeedTeamType < DefaultObject
field :dbid, GraphQL::Types::Int, null: true
field :filters, JsonStringType, null: true
field :saved_search_id, GraphQL::Types::Int, null: true
field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :feed, FeedType, null: true
field :team_id, GraphQL::Types::Int, null: true
field :feed_id, GraphQL::Types::Int, null: true
Expand Down
4 changes: 2 additions & 2 deletions app/graph/types/feed_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FeedType < DefaultObject
field :discoverable, GraphQL::Types::Boolean, null: true
field :user, UserType, null: true

field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :saved_search, SavedSearchType, null: true

field :requests, RequestType.connection_type, null: true do
Expand Down Expand Up @@ -50,7 +50,7 @@ def feed_invitations
object.feed_invitations
end

field :teams, TeamType.connection_type, null: false
field :teams, PublicTeamType.connection_type, null: false
field :feed_teams, FeedTeamType.connection_type, null: false
field :data_points, [GraphQL::Types::Int, null: true], null: true
end
157 changes: 157 additions & 0 deletions app/graph/types/me_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
class MeType < DefaultObject
description "Me type"

implements GraphQL::Types::Relay::Node

field :dbid, GraphQL::Types::Int, null: true
field :email, GraphQL::Types::String, null: true
field :unconfirmed_email, GraphQL::Types::String, null: true
field :providers, JsonStringType, null: true
field :uuid, GraphQL::Types::String, null: true
field :profile_image, GraphQL::Types::String, null: true
field :login, GraphQL::Types::String, null: true
field :name, GraphQL::Types::String, null: true
field :current_team_id, GraphQL::Types::Int, null: true
field :permissions, GraphQL::Types::String, null: true
field :jsonsettings, GraphQL::Types::String, null: true
field :number_of_teams, GraphQL::Types::Int, null: true
field :get_send_email_notifications, GraphQL::Types::Boolean, null: true

def get_send_email_notifications
object.get_send_email_notifications
end

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

def get_send_successful_login_notifications
object.get_send_successful_login_notifications
end

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

def get_send_failed_login_notifications
object.get_send_failed_login_notifications
end

field :bot_events, GraphQL::Types::String, null: true
field :is_bot, GraphQL::Types::Boolean, null: true
field :is_active, GraphQL::Types::Boolean, null: true
field :two_factor, JsonStringType, null: true
field :settings, JsonStringType, null: true
field :accepted_terms, GraphQL::Types::Boolean, null: true
field :last_accepted_terms_at, GraphQL::Types::String, null: true
field :team_ids, [GraphQL::Types::Int, null: true], null: true

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

def user_teams
User.current == object ? object.user_teams : {}.to_json
end

field :last_active_at, GraphQL::Types::Int, null: true
field :completed_signup, GraphQL::Types::Boolean, null: true

field :source_id, GraphQL::Types::Int, null: true

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

def token
object.token if object == User.current
end

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

def is_admin
object.is_admin if object == User.current
end

field :current_project, ProjectType, null: true

def current_project
User.current == object ? object.current_project : nil
end

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

def confirmed
object.is_confirmed?
end

field :source, SourceType, null: true

def source
Source.find(object.source_id)
end

field :current_team, TeamType, null: true

def current_team
User.current == object ? object.current_team : nil
end

field :bot, BotUserType, null: true

def bot
object if object.is_bot
end

field :team_user, TeamUserType, null: true do
argument :team_slug, GraphQL::Types::String, required: true, camelize: false
end

def team_user(team_slug:)
tu = TeamUser
.joins(:team)
.where("teams.slug" => team_slug, :user_id => object.id)
.last
tu.nil? ? nil : TeamUser.find_if_can(tu.id, context[:ability])
end

field :teams, TeamType.connection_type, null: true

def teams
return Team.none unless object == User.current
object.teams
end

field :team_users, TeamUserType.connection_type, null: true do
argument :status, GraphQL::Types::String, required: false
end

def team_users(status: nil)
return TeamUser.none unless object == User.current
team_users = object.team_users
team_users = team_users.where(status: status) if status
team_users
end

field :annotations, AnnotationType.connection_type, null: true do
argument :type, GraphQL::Types::String, required: false
end

def annotations(type: nil)
return Annotation.none unless object == User.current
type.blank? ? object.annotations : object.annotations(type)
end

field :assignments, ProjectMediaType.connection_type, null: true do
argument :team_id, GraphQL::Types::Int, required: false, camelize: false
end

def assignments(team_id: nil)
return ProjectMedia.none unless object == User.current
pms = Annotation.project_media_assigned_to_user(object).order("id DESC")
team_id = team_id.to_i
pms = pms.where(team_id: team_id) if team_id > 0
# TODO: remove finished items
# pms.reject { |pm| pm.is_finished? }
pms
end

field :feed_invitations, FeedInvitationType.connection_type, null: false

def feed_invitations
return FeedInvitation.none if object.email.blank? || User.current != object
FeedInvitation.where(email: object.email)
end
end
2 changes: 1 addition & 1 deletion app/graph/types/project_group_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ProjectGroupType < DefaultObject
field :title, GraphQL::Types::String, null: true
field :description, GraphQL::Types::String, null: true
field :team_id, GraphQL::Types::Int, null: true
field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :medias_count, GraphQL::Types::Int, null: true

field :projects, ProjectType.connection_type, null: true
Expand Down
12 changes: 12 additions & 0 deletions app/graph/types/project_media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ def account
field :team, TeamType, null: true

def team
RecordLoader
.for(Team)
.load(object.team_id)
.then do |team|
ability = context[:ability] || Ability.new
team if ability.can?(:read, team)
end
end

field :public_team, PublicTeamType, null: true

def public_team
RecordLoader.for(Team).load(object.team_id)
end

Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/project_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProjectType < DefaultObject
field :search_id, GraphQL::Types::String, null: true
field :url, GraphQL::Types::String, null: true
field :search, CheckSearchType, null: true
field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :project_group_id, GraphQL::Types::Int, null: true
field :project_group, ProjectGroupType, null: true
field :privacy, GraphQL::Types::Int, null: true
Expand Down
6 changes: 6 additions & 0 deletions app/graph/types/public_team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def pusher_channel
Team.find(object.id).pusher_channel
end

field :medias_count, GraphQL::Types::Int, null: true

def medias_count
archived_count(object) ? 0 : object.medias_count
end

field :trash_count, GraphQL::Types::Int, null: true

def trash_count
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def about
end

field :me,
UserType,
MeType,
description: "Information about the current user",
null: true

Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/root_level_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RootLevelType < BaseObject

global_id_field :id

field :current_user, UserType, null: true
field :current_user, MeType, null: true

def current_user
User.current
Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/saved_search_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SavedSearchType < DefaultObject
field :dbid, GraphQL::Types::Int, null: true
field :title, GraphQL::Types::String, null: true
field :team_id, GraphQL::Types::Int, null: true
field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :items_count, GraphQL::Types::Int, null: true
field :filters, GraphQL::Types::String, null: true

Expand Down
2 changes: 1 addition & 1 deletion app/graph/types/team_task_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TeamTaskType < DefaultObject
field :options, JsonStringType, null: true
field :required, GraphQL::Types::Boolean, null: true
field :team_id, GraphQL::Types::Int, null: true
field :team, TeamType, null: true
field :team, PublicTeamType, null: true
field :json_schema, GraphQL::Types::String, null: true
field :order, GraphQL::Types::Int, null: true
field :fieldset, GraphQL::Types::String, null: true
Expand Down
Loading

0 comments on commit 2d9d6ad

Please sign in to comment.