Skip to content

Commit

Permalink
CV2-4072: add MeType for user
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Jan 15, 2024
1 parent a2a3be8 commit e7ba300
Show file tree
Hide file tree
Showing 10 changed files with 1,543 additions and 992 deletions.
2 changes: 1 addition & 1 deletion app/graph/mutations/duplicate_team_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DuplicateTeamMutation < Mutations::BaseMutation
argument :custom_slug, GraphQL::Types::String, required: false, camelize: false
argument :custom_name, GraphQL::Types::String, required: false, camelize: false

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

def resolve(team_id:, custom_slug: nil, custom_name: nil)
_type_name, id = CheckGraphql.decode_id(team_id)
Expand Down
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
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, PublicTeamType, null: true
field :team, TeamType, 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
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
2 changes: 1 addition & 1 deletion app/graph/types/team_user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TeamUserType < DefaultObject
field :status, GraphQL::Types::String, null: true
field :role, GraphQL::Types::String, null: true
field :permissions, GraphQL::Types::String, null: true
field :team, PublicTeamType, null: true
field :team, TeamType, null: true
field :user, UserType, null: true
field :invited_by, UserType, null: true

Expand Down
Loading

0 comments on commit e7ba300

Please sign in to comment.