This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ISSUE-7985: The topics for the "Company User" mutations have been cre… #8104
Merged
keharper
merged 7 commits into
magento:2.4.2-develop
from
andrewbess:new-topic/graphql/issue-7985-company-user-mutations
Oct 22, 2020
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95f991e
ISSUE-7985: The topics for the "Company User" mutations have been cre…
be51581
ISSUE-7985: The fixes by reviewer recommendations
64ab872
ISSUE-7985: The fixes by reviewer recommendations
a05d0f2
ISSUE-7985: The fixes by reviewer recommendations
22b5d5d
Update create-company-user.md
keharper 0f79a2c
Update create-company-user.md
keharper 698c8db
Merge branch '2.4.2-develop' into new-topic/graphql/issue-7985-compan…
keharper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/guides/v2.4/graphql/mutations/create-company-user.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
--- | ||
group: graphql | ||
title: createCompanyUser mutation | ||
contributor_name: Atwix | ||
contributor_link: https://www.atwix.com/ | ||
b2b_only: true | ||
--- | ||
|
||
The `createCompanyUser` mutation allows an existing company user who is assigned a role that contains the `Magento_Company::users_edit` permission to create a new company user. The specified email address determines how Magento processes the request. | ||
|
||
- If the email address is unique for the website, Magento immediately creates the company user. | ||
|
||
- If the email address belongs to a customer who is not a company user, Magento sends an invitation to join the company organization to the customer. When the customer accepts the invitation, Magento adds the customer to the company organization. | ||
|
||
- If the email address belongs to a customer who is part of any company organization, Magento returns the error "A customer with the same email already assigned to company". | ||
|
||
The `target_id` input attribute allows you to specify which node in the company structure will be the parent node of the company user. If you do not specify a value, the user will be assigned to the top-level (root) node of the company structure. | ||
|
||
You can get the `target_id` and the `role_id` with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query. | ||
|
||
## Syntax | ||
|
||
```graphql | ||
mutation { | ||
createCompanyUser( | ||
input: CompanyUserCreateInput! | ||
) { | ||
CreateCompanyUserOutput | ||
} | ||
} | ||
``` | ||
|
||
## Example usage | ||
|
||
### Create a company user (minimal payload) | ||
|
||
The following example shows the minimal payload to add a company user. Because a `target_id` is not specified, Magento places the new company user at the top node of the company structure. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
createCompanyUser( | ||
input: { | ||
email: "john.doe@example.com" | ||
firstname: "John" | ||
lastname: "Doe" | ||
job_title: "User" | ||
role_id: "MQ==" | ||
status: ACTIVE | ||
telephone: "1234567890" | ||
} | ||
) { | ||
user { | ||
created_at | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"createCompanyUser": { | ||
"user": { | ||
"created_at": "2020-10-15 23:33:49", | ||
"email": "john.doe@example.com" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Create a company user in a specific location in the company structure | ||
|
||
This example creates a new company user of the parent company team specified in the `target_id` field. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
createCompanyUser( | ||
input: { | ||
email: "jane.doe3@example.com" | ||
firstname: "Jane" | ||
lastname: "Doe3" | ||
job_title: "User" | ||
role_id: "NTc=" | ||
status: ACTIVE | ||
telephone: "1234567890" | ||
target_id: "OA==" | ||
} | ||
) { | ||
user { | ||
created_at | ||
firstname | ||
lastname | ||
job_title | ||
role { | ||
id | ||
name | ||
} | ||
team { | ||
id | ||
name | ||
structure_id | ||
} | ||
status | ||
telephone | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"createCompanyUser": { | ||
"user": { | ||
"created_at": "2020-10-15 23:39:11", | ||
"email": "jane.doe@example.com", | ||
"firstname": "Jane", | ||
"lastname": "Doe", | ||
"job_title": "User", | ||
"role": { | ||
"id": "NTc=", | ||
"name": "Default User" | ||
}, | ||
"team": { | ||
"id": "MQ==", | ||
"name": "Test Team", | ||
"structure_id": "Mg==" | ||
}, | ||
"status": "ACTIVE", | ||
"telephone": "1234567890" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Input attributes | ||
|
||
The `CompanyUserCreateInput` input object defines the company user data. | ||
|
||
### CompanyUserCreateInput attributes {#CompanyUserCreateInput} | ||
|
||
The `CompanyUserCreateInput` object contains the following attributes: | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`email` | String! | The company user's email address | ||
`firstname` | String! | The company user's first name | ||
`job_title` | String! | The company user's job title or function | ||
`lastname` | String! | The company user's last name | ||
`role_id` | ID! | The role ID to assign to the company user | ||
`status` | CompanyUserStatusEnum! | Indicates whether the company user is ACTIVE or INACTIVE | ||
`target_id` | ID | The ID of a node within a company's structure. This ID will be the parent of the created company user | ||
`telephone` | String! | The company user's phone number | ||
|
||
## Output attributes | ||
|
||
The `CreateCompanyUserOutput` output object contains the following attribute: | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`user` | Customer! | Contains company user data | ||
|
||
### Customer attributes {#Customer} | ||
|
||
{% include graphql/customer-output-24.md %} | ||
|
||
## Errors | ||
|
||
Error | Description | ||
--- | --- | ||
`Invitation was sent to an existing customer, they will be added to your organization once they accept the invitation.` | The email provided in the `input`.`email` argument belongs to an existing customer. Magento will send an invitation to this customer. When the customer accepts the invitation, the customer will be assigned to the company. | ||
`A customer with the same email already assigned to company.` | The email provided in the `input`.`email` argument belongs to an existing customer, and the customer has already been assigned to the company. | ||
`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format. | ||
`Field "createCompanyUser" argument "input" requires type String!, found xxx.` | The value specified in the one of the `input` arguments has an invalid type. | ||
`Field "xxx" is not defined by type CompanyUserCreateInput.` | The `input`.`xxx` argument is undefined. | ||
`Required parameters are missing: xxx` | The `input`.`xxx` argument was omitted or contains an empty value. | ||
`No such entity with roleId = xxx` | The company role with ID `xxx` doesn't exist. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
group: graphql | ||
title: deleteCompanyUser mutation | ||
contributor_name: Atwix | ||
contributor_link: https://www.atwix.com/ | ||
b2b_only: true | ||
--- | ||
|
||
Use the `deleteCompanyUser` mutation to deactivate the specified company user. | ||
|
||
You can get the user ID with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query. | ||
|
||
## Syntax | ||
|
||
```graphql | ||
mutation { | ||
deleteCompanyUser( | ||
id: ID! | ||
) { | ||
DeleteCompanyUserOutput | ||
} | ||
} | ||
``` | ||
|
||
## Example usage | ||
|
||
The following example deactivates the user specified in the `id` attribute. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
deleteCompanyUser( | ||
id: "Mg==" | ||
) { | ||
success | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"deleteCompanyUser": { | ||
"success": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Input attributes | ||
|
||
The `deleteCompanyUser` mutation requires the following input: | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`id` | ID! | The encoded user ID to deactivate | ||
|
||
## Output attributes | ||
|
||
The `deleteCompanyUser` mutation returns a Boolean value that indicates whether the operation was successful. | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`success` | Boolean! | A value of `true` indicates the company user has been deactivated successfully, otherwise a value returns `false` | ||
|
||
## Errors | ||
|
||
Error | Description | ||
--- | --- | ||
`You do not have authorization to perform this action.` | The user with the ID provided in the `input`.`id` argument is not available to your company, or you do not have the necessary permissions to perform this operation. | ||
`You cannot delete yourself.` | You must specify a company user other than yourself. | ||
`A customer with the same email address already exists in an associated website` | The email provided in the `input`.`email` argument belongs to another user. | ||
`The user XXX is the company admin and cannot be set to inactive. You must set another user as the company admin first.` | The company owner cannot be deactivated. You must set another user as the company admin first. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have information about the default target ID (if not specified explicitly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @rogyar
Thank you for your review.
It is described in the top paragraphs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the preferred method of documenting non-intuitive attributes and objects. The descriptions here should be very similar to the
@description
text in the schema file. Eventually, the GraphQL documentation will be auto-generated, and we don't want to lose critical information.