Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3d4a9865fe | ||
![]() |
c191b7a3cf |
135
packages/backend/src/apps/wordpress/actions/create-user/index.js
Normal file
135
packages/backend/src/apps/wordpress/actions/create-user/index.js
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
import isEmpty from 'lodash/isEmpty.js';
|
||||||
|
import omitBy from 'lodash/omitBy.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Create user',
|
||||||
|
key: 'createUser',
|
||||||
|
description: 'Creates a new user.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Email',
|
||||||
|
key: 'email',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Username',
|
||||||
|
key: 'username',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Password',
|
||||||
|
key: 'password',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'First Name',
|
||||||
|
key: 'firstName',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Last Name',
|
||||||
|
key: 'lastName',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Display Name',
|
||||||
|
key: 'displayName',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Nickname',
|
||||||
|
key: 'nickname',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Description',
|
||||||
|
key: 'description',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Website',
|
||||||
|
key: 'website',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Role',
|
||||||
|
key: 'role',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Administrator', value: 'administrator' },
|
||||||
|
{ label: 'Author', value: 'author' },
|
||||||
|
{ label: 'Contributor', value: 'contributor' },
|
||||||
|
{ label: 'Editor', value: 'editor' },
|
||||||
|
{ label: 'Subscriber', value: 'subscriber' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const {
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
displayName,
|
||||||
|
nickname,
|
||||||
|
description,
|
||||||
|
website,
|
||||||
|
role,
|
||||||
|
} = $.step.parameters;
|
||||||
|
|
||||||
|
let body = {
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
first_name: firstName,
|
||||||
|
last_name: lastName,
|
||||||
|
name: displayName,
|
||||||
|
nickname,
|
||||||
|
description,
|
||||||
|
url: website,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (role) {
|
||||||
|
body.roles = [role];
|
||||||
|
}
|
||||||
|
|
||||||
|
body = omitBy(body, isEmpty);
|
||||||
|
|
||||||
|
const response = await $.http.post('?rest_route=/wp/v2/users', body);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: response.data });
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,35 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Find post',
|
||||||
|
key: 'findPost',
|
||||||
|
description: 'Finds a post.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Post ID',
|
||||||
|
key: 'postId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: false,
|
||||||
|
description: 'Choose a post to update.',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listPosts',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const { postId } = $.step.parameters;
|
||||||
|
|
||||||
|
const response = await $.http.get(`?rest_route=/wp/v2/posts/${postId}`);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: response.data });
|
||||||
|
},
|
||||||
|
});
|
@@ -1,4 +1,6 @@
|
|||||||
import createPost from './create-post/index.js';
|
import createPost from './create-post/index.js';
|
||||||
|
import createUser from './create-user/index.js';
|
||||||
|
import findPost from './find-post/index.js';
|
||||||
import updatePost from './update-post/index.js';
|
import updatePost from './update-post/index.js';
|
||||||
|
|
||||||
export default [createPost, updatePost];
|
export default [createPost, createUser, findPost, updatePost];
|
||||||
|
@@ -3,6 +3,10 @@ favicon: /favicons/wordpress.svg
|
|||||||
items:
|
items:
|
||||||
- name: Create post
|
- name: Create post
|
||||||
desc: Creates a new post.
|
desc: Creates a new post.
|
||||||
|
- name: Create user
|
||||||
|
desc: Creates a new user.
|
||||||
|
- name: Find post
|
||||||
|
desc: Finds a post.
|
||||||
- name: Update post
|
- name: Update post
|
||||||
desc: Updates a post.
|
desc: Updates a post.
|
||||||
---
|
---
|
||||||
|
Reference in New Issue
Block a user