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

CV2-4072: Review fields of types TeamType and UserType #1770

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
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/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
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
29 changes: 2 additions & 27 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class TeamType < DefaultObject
field :members_count, GraphQL::Types::Int, null: true
field :projects_count, GraphQL::Types::Int, null: true
field :permissions, GraphQL::Types::String, null: true
field :get_slack_notifications_enabled, GraphQL::Types::String, null: true
field :get_slack_webhook, GraphQL::Types::String, null: true
field :get_embed_whitelist, GraphQL::Types::String, null: true
field :get_report_design_image_template, GraphQL::Types::String, null: true
Expand All @@ -37,20 +36,15 @@ class TeamType < DefaultObject
field :spam_count, GraphQL::Types::Int, null: true
field :trash_count, GraphQL::Types::Int, null: true
field :unconfirmed_count, GraphQL::Types::Int, null: true
field :get_languages, GraphQL::Types::String, null: true
field :get_language, GraphQL::Types::String, null: true
field :get_language_detection, GraphQL::Types::Boolean, null: true
field :get_report, JsonStringType, null: true
field :get_fieldsets, JsonStringType, null: true
field :list_columns, JsonStringType, null: true
field :get_data_report_url, GraphQL::Types::String, null: true
field :url, GraphQL::Types::String, null: true
field :get_tipline_inbox_filters, JsonStringType, null: true
field :get_suggested_matches_filters, JsonStringType, null: true
field :data_report, JsonStringType, null: true
field :available_newsletter_header_types, JsonStringType, null: true # List of header type strings
field :get_outgoing_urls_utm_code, GraphQL::Types::String, null: true
field :get_shorten_outgoing_urls, GraphQL::Types::Boolean, null: true

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

def get_slack_notifications_enabled
object.get_slack_notifications_enabled
Expand Down Expand Up @@ -80,16 +74,6 @@ def get_status_target_turnaround
object.get_status_target_turnaround
end

field :pusher_channel, GraphQL::Types::String, null: true
field :search_id, GraphQL::Types::String, null: true
field :search, CheckSearchType, null: true
field :check_search_trash, CheckSearchType, null: true
field :check_search_unconfirmed, CheckSearchType, null: true
field :check_search_spam, CheckSearchType, null: true
field :trash_size, JsonStringType, null: true
field :public_team_id, GraphQL::Types::String, null: true
field :permissions_info, JsonStringType, null: true
field :dynamic_search_fields_json_schema, JsonStringType, null: true
field :get_slack_notifications, JsonStringType, null: true

def get_slack_notifications
Expand All @@ -102,13 +86,6 @@ def get_rules
object.get_rules
end

field :rules_json_schema, GraphQL::Types::String, null: true
field :slack_notifications_json_schema, GraphQL::Types::String, null: true
field :rules_search_fields_json_schema, JsonStringType, null: true
field :medias_count, GraphQL::Types::Int, null: true
field :spam_count, GraphQL::Types::Int, null: true
field :trash_count, GraphQL::Types::Int, null: true
field :unconfirmed_count, GraphQL::Types::Int, null: true
field :get_languages, GraphQL::Types::String, null: true

def get_languages
Expand Down Expand Up @@ -153,8 +130,6 @@ def get_suggested_matches_filters
object.get_suggested_matches_filters
end

field :data_report, JsonStringType, null: true
field :available_newsletter_header_types, JsonStringType, null: true # List of header type strings
field :get_outgoing_urls_utm_code, GraphQL::Types::String, null: true

def get_outgoing_urls_utm_code
Expand Down
Loading
Loading