diff --git a/app/graph/mutations/team_user_mutations.rb b/app/graph/mutations/team_user_mutations.rb index 34aa04b246..77951364ae 100644 --- a/app/graph/mutations/team_user_mutations.rb +++ b/app/graph/mutations/team_user_mutations.rb @@ -2,28 +2,8 @@ module TeamUserMutations MUTATION_TARGET = 'team_user'.freeze PARENTS = ['user','team'].freeze - module SharedCreateAndUpdateFields - extend ActiveSupport::Concern - - included do - argument :role, GraphQL::Types::String, required: false - end - end - - class Create < Mutations::CreateMutation - include SharedCreateAndUpdateFields - - argument :user_id, GraphQL::Types::Int, required: true, camelize: false - argument :team_id, GraphQL::Types::Int, required: true, camelize: false - argument :status, GraphQL::Types::String, required: true - end - class Update < Mutations::UpdateMutation - include SharedCreateAndUpdateFields - - argument :user_id, GraphQL::Types::Int, required: false, camelize: false - argument :team_id, GraphQL::Types::Int, required: false, camelize: false - argument :status, GraphQL::Types::String, required: false + argument :role, GraphQL::Types::String, required: false end class Destroy < Mutations::DestroyMutation; end diff --git a/app/graph/mutations/user_invitation_mutation.rb b/app/graph/mutations/user_invitation_mutation.rb index 8f44db07f3..50c7e065f5 100644 --- a/app/graph/mutations/user_invitation_mutation.rb +++ b/app/graph/mutations/user_invitation_mutation.rb @@ -8,7 +8,8 @@ class UserInvitationMutation < Mutations::BaseMutation field :team, TeamType, null: true def resolve(invitation: nil, members:) + team = Team.find_if_can(Team.current.id, context[:ability]) messages = User.send_user_invitation(members, invitation) - { errors: messages, team: Team.current } + { errors: messages, team: team } end end diff --git a/app/graph/types/mutation_type.rb b/app/graph/types/mutation_type.rb index 353cdbf0f9..e3a7c1201e 100644 --- a/app/graph/types/mutation_type.rb +++ b/app/graph/types/mutation_type.rb @@ -14,7 +14,6 @@ class MutationType < BaseObject field :updateSource, mutation: SourceMutations::Update field :destroySource, mutation: SourceMutations::Destroy - field :createTeamUser, mutation: TeamUserMutations::Create field :updateTeamUser, mutation: TeamUserMutations::Update field :destroyTeamUser, mutation: TeamUserMutations::Destroy diff --git a/app/graph/types/user_type.rb b/app/graph/types/user_type.rb index 31d4f31d9f..25deb17e53 100644 --- a/app/graph/types/user_type.rb +++ b/app/graph/types/user_type.rb @@ -41,7 +41,13 @@ def get_send_failed_login_notifications 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 @@ -61,6 +67,10 @@ def is_admin 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 @@ -75,6 +85,10 @@ def source field :current_team, TeamType, null: true + def current_team + User.current == object ? object.current_team : nil + end + field :bot, BotUserType, null: true def bot @@ -86,19 +100,26 @@ def bot end def team_user(team_slug:) - TeamUser + tu = TeamUser .joins(:team) .where("teams.slug" => team_slug, :user_id => object.id) .last + 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 @@ -109,6 +130,7 @@ def team_users(status: nil) end def annotations(type: nil) + return Annotation.none unless object == User.current type.blank? ? object.annotations : object.annotations(type) end @@ -117,6 +139,7 @@ def annotations(type: nil) 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 @@ -128,7 +151,7 @@ def assignments(team_id: nil) field :feed_invitations, FeedInvitationType.connection_type, null: false def feed_invitations - return FeedInvitation.none if object.email.blank? + return FeedInvitation.none if object.email.blank? || User.current != object FeedInvitation.where(email: object.email) end end diff --git a/app/models/user.rb b/app/models/user.rb index c1430ec4d2..6384fac4aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -158,7 +158,7 @@ def current_team end def current_project - Project.where(id: self.current_project_id).last unless self.current_project_id.blank? + Project.where(id: self.current_project_id, team_id: self.current_team_id).last unless self.current_project_id.blank? end def user_teams diff --git a/lib/relay.idl b/lib/relay.idl index d5556a348c..58c0fbe74c 100644 --- a/lib/relay.idl +++ b/lib/relay.idl @@ -2860,34 +2860,6 @@ type CreateTeamTaskPayload { team_taskEdge: TeamTaskEdge } -""" -Autogenerated input type of CreateTeamUser -""" -input CreateTeamUserInput { - """ - A unique identifier for the client performing the mutation. - """ - clientMutationId: String - role: String - status: String! - team_id: Int! - user_id: Int! -} - -""" -Autogenerated return type of CreateTeamUser -""" -type CreateTeamUserPayload { - """ - A unique identifier for the client performing the mutation. - """ - clientMutationId: String - team: Team - team_user: TeamUser - team_userEdge: TeamUserEdge - user: User -} - """ Autogenerated input type of CreateTiplineNewsletter """ @@ -9348,12 +9320,6 @@ type MutationType { """ input: CreateTeamTaskInput! ): CreateTeamTaskPayload - createTeamUser( - """ - Parameters for CreateTeamUser - """ - input: CreateTeamUserInput! - ): CreateTeamUserPayload createTiplineNewsletter( """ Parameters for CreateTiplineNewsletter @@ -16004,9 +15970,6 @@ input UpdateTeamUserInput { clientMutationId: String id: ID role: String - status: String - team_id: Int - user_id: Int } """ diff --git a/public/relay.json b/public/relay.json index ebd37659d2..b95fac1beb 100644 --- a/public/relay.json +++ b/public/relay.json @@ -17559,172 +17559,6 @@ "enumValues": null, "possibleTypes": null }, - { - "kind": "INPUT_OBJECT", - "name": "CreateTeamUserInput", - "description": "Autogenerated input type of CreateTeamUser", - "fields": null, - "inputFields": [ - { - "name": "role", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "user_id", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - } - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "team_id", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - } - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "status", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "clientMutationId", - "description": "A unique identifier for the client performing the mutation.", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - } - ], - "interfaces": null, - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "OBJECT", - "name": "CreateTeamUserPayload", - "description": "Autogenerated return type of CreateTeamUser", - "fields": [ - { - "name": "clientMutationId", - "description": "A unique identifier for the client performing the mutation.", - "args": [ - - ], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "team", - "description": null, - "args": [ - - ], - "type": { - "kind": "OBJECT", - "name": "Team", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "team_user", - "description": null, - "args": [ - - ], - "type": { - "kind": "OBJECT", - "name": "TeamUser", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "team_userEdge", - "description": null, - "args": [ - - ], - "type": { - "kind": "OBJECT", - "name": "TeamUserEdge", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "user", - "description": null, - "args": [ - - ], - "type": { - "kind": "OBJECT", - "name": "User", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [ - - ], - "enumValues": null, - "possibleTypes": null - }, { "kind": "INPUT_OBJECT", "name": "CreateTiplineNewsletterInput", @@ -50450,35 +50284,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "createTeamUser", - "description": null, - "args": [ - { - "name": "input", - "description": "Parameters for CreateTeamUser", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "INPUT_OBJECT", - "name": "CreateTeamUserInput", - "ofType": null - } - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - } - ], - "type": { - "kind": "OBJECT", - "name": "CreateTeamUserPayload", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "createTiplineNewsletter", "description": null, @@ -87656,42 +87461,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "user_id", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "team_id", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "status", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "clientMutationId", "description": "A unique identifier for the client performing the mutation.", diff --git a/test/controllers/graphql_controller_10_test.rb b/test/controllers/graphql_controller_10_test.rb index ee659a048d..b053b06e5c 100644 --- a/test/controllers/graphql_controller_10_test.rb +++ b/test/controllers/graphql_controller_10_test.rb @@ -159,7 +159,7 @@ def setup tk2.assign_user(u.id) authenticate_with_user(u) - post :create, params: { query: "query { me { assignments(first: 10000) { edges { node { dbid } } } } }", team: t1.slug } + post :create, params: { query: "query { me { current_project { id }, current_team { id }, user_teams, teams(first: 10) { edges { node { id } } }, assignments(first: 10000) { edges { node { dbid } } } } }", team: t1.slug } assert_response :success data = JSON.parse(@response.body)['data']['me']['assignments']['edges'] assert_equal 2, data.size diff --git a/test/controllers/graphql_controller_8_test.rb b/test/controllers/graphql_controller_8_test.rb index e3220e1b1b..08b81ba667 100644 --- a/test/controllers/graphql_controller_8_test.rb +++ b/test/controllers/graphql_controller_8_test.rb @@ -54,8 +54,11 @@ def setup test "should get team user from user" do u = create_user + u2 = create_user t = create_team + t2 = create_team tu = create_team_user user: u, team: t + tu2 = create_team_user user: u2, team: t2 authenticate_with_user(u) query = 'query { me { team_user(team_slug: "' + t.slug + '") { dbid } } }' @@ -65,8 +68,7 @@ def setup query = 'query { me { team_user(team_slug: "' + random_string + '") { dbid } } }' post :create, params: { query: query } - assert_response :success - assert_nil JSON.parse(@response.body)['data']['me']['team_user'] + assert_response 400 end test "should define team languages settings" do diff --git a/test/controllers/graphql_controller_test.rb b/test/controllers/graphql_controller_test.rb index 9d60020cf6..21a3ef0b8d 100644 --- a/test/controllers/graphql_controller_test.rb +++ b/test/controllers/graphql_controller_test.rb @@ -269,16 +269,6 @@ def setup assert_graphql_destroy('team') end - test "should create team user" do - u = create_user - assert_graphql_create('team_user', { team_id: @team.id, user_id: u.id, status: 'member' }) - end - - test "should update team user" do - t = create_team - assert_graphql_update('team_user', :team_id, t.id, @team.id) - end - test "should update user" do assert_graphql_update('user', :name, 'Foo', 'Bar') end