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

Enhancement/328 Sophi Overrides API Integration #333

Merged
merged 74 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
ed4d474
a new sub block created `sophi/page-list-item`
faisal-alvi Oct 3, 2022
d885cb5
endpoint class added with get sophi posts endpoint
faisal-alvi Oct 3, 2022
abb8706
added InnerBlocks to the Automation block
faisal-alvi Oct 3, 2022
a7a72cd
saving the innerBlocks
faisal-alvi Oct 3, 2022
6761884
remove the ServerSideRender call back and its markup file
faisal-alvi Oct 3, 2022
0aa9d05
popup creation with static add override (no api so far, all static)
faisal-alvi Oct 3, 2022
3d41e13
added override "in" rule endpoint with static data
faisal-alvi Oct 4, 2022
32d7e6b
make an override call when innerblock is updated
faisal-alvi Oct 4, 2022
98690ad
adding `10up/block-components` dependency
faisal-alvi Oct 4, 2022
9891b01
add/update the attributes of the child block
faisal-alvi Oct 4, 2022
ca8552d
update the prop types
faisal-alvi Oct 4, 2022
3b815a9
innerBlock updated with the dynamic override data
faisal-alvi Oct 4, 2022
890f8c6
call the overRide 'in' API
faisal-alvi Oct 4, 2022
59af297
update the override API to accept dyanamic values
faisal-alvi Oct 4, 2022
a6001a6
'add' override loop draft
faisal-alvi Oct 5, 2022
0fa9bce
fixed the display author issue
faisal-alvi Oct 5, 2022
965f212
adding back the ServerSideRender
faisal-alvi Oct 5, 2022
f28a5d6
adding back the markup file to use on front end
faisal-alvi Oct 5, 2022
915d3b7
display the featured image in the innerBlock
faisal-alvi Oct 5, 2022
c38500e
fix cureated posts data issue
faisal-alvi Oct 5, 2022
bd64ef5
remove unnecessary import
faisal-alvi Oct 5, 2022
b0ece45
remove unnecessary condition + use `Link` command
faisal-alvi Oct 5, 2022
3f5e9e5
new settings added for Override API
faisal-alvi Oct 5, 2022
b818402
reset override data before rendering new blocks
faisal-alvi Oct 5, 2022
81c1749
save the overridden item in the db forcefully!
faisal-alvi Oct 5, 2022
ab87513
add an override auth token, auto regenreate on expire
faisal-alvi Oct 6, 2022
98299cf
adding back the Auth class that was removed recently in #310
faisal-alvi Oct 6, 2022
15e5f4a
adding a new prop for location of insertion
faisal-alvi Oct 6, 2022
1d16fe4
intergrating replace/remove/ban actions!
faisal-alvi Oct 6, 2022
1109afc
fixing isset errors and handleing the api results
faisal-alvi Oct 6, 2022
7527f92
endpoint name changes + extra dorpdown removal + label changes
faisal-alvi Oct 7, 2022
e26aa16
remove the last item after adding the new item
faisal-alvi Oct 7, 2022
b37f6ba
use the ServerSideRender callback in Rest End Point!
faisal-alvi Oct 7, 2022
9253577
adding hookdoc for Rest End Points
faisal-alvi Oct 7, 2022
82b0a67
fixing phpcs and eslint errors/warnings
faisal-alvi Oct 7, 2022
c51241e
disabling eslint warnings on alerts
faisal-alvi Oct 7, 2022
1386ea4
Merge branch 'develop' into enhancement/328
faisal-alvi Oct 11, 2022
e384b9f
update REST endpoints hooks
faisal-alvi Oct 12, 2022
c116d3e
fixing vertical alignments
faisal-alvi Oct 12, 2022
008fa06
dont update the local cache suddenly on remove/ban
faisal-alvi Oct 12, 2022
1cce659
translatable strings
faisal-alvi Oct 12, 2022
2f11998
show message(s) when request is sent, also removing alerts
faisal-alvi Oct 13, 2022
5d34dcb
change innerblock icon, remove gear and add 4 buttons
faisal-alvi Oct 19, 2022
ac96479
settings fields & sections replacements
faisal-alvi Oct 19, 2022
2ec5810
Merge branch 'develop' into enhancement/328
faisal-alvi Oct 19, 2022
2d65ddc
using the `useRef` to keep the popup attached with the page item
faisal-alvi Oct 19, 2022
04bedcb
ref added in toolbar buttons
faisal-alvi Oct 19, 2022
1864eff
Trying to reduce the Cognitive Complexity
faisal-alvi Oct 19, 2022
ce3ee2b
fixing `SonarCloud` bugs
faisal-alvi Oct 19, 2022
1dcfeb4
Minor text changes
dkotter Oct 20, 2022
8cd22ad
removing the comment from CSS files
faisal-alvi Oct 25, 2022
e911f6a
en/decryption methods added and used
faisal-alvi Oct 25, 2022
9366ca9
added a method `site_automation_override_permission`
faisal-alvi Oct 25, 2022
66e2ebb
setting permssion to get the curated posts too
faisal-alvi Oct 25, 2022
d7f3bb5
filters docblock changed to reflect in automated hook docs
faisal-alvi Oct 25, 2022
86d6081
using the null coalescing operator
faisal-alvi Oct 25, 2022
5c81350
wrap wtih `wp_json_encode`
faisal-alvi Oct 25, 2022
a6e5c9a
removed the extra tabs
faisal-alvi Oct 25, 2022
2ad9089
`useDebounce` used to delay the API calls by 1s
faisal-alvi Oct 25, 2022
6ee99bb
Merge branch 'develop' into enhancement/328
jeffpaul Oct 25, 2022
a8d94d2
Spacing
dkotter Oct 25, 2022
42e2990
Remove extra spacing
dkotter Oct 25, 2022
dc9a5e5
handling “Unsupported” block by showing the initial popup again when …
faisal-alvi Oct 26, 2022
3786011
use of `forEach` instead of `map`
faisal-alvi Oct 26, 2022
137d0b9
making the code more clear and efficient for rest API
faisal-alvi Oct 26, 2022
e583128
Merge branch 'enhancement/328' of github.com:globeandmail/sophi-for-w…
faisal-alvi Oct 26, 2022
4b54d49
display not found post IDs in the sidebar
faisal-alvi Oct 26, 2022
204959b
send unavailble post IDs to editor
faisal-alvi Oct 26, 2022
dd64eac
the unavilable postIDs sent to editor
faisal-alvi Oct 26, 2022
2551401
updated the not available postIDs' message
faisal-alvi Oct 26, 2022
596e9af
update the button labels
faisal-alvi Oct 26, 2022
08de2f7
At FE: stop if post does not exist
faisal-alvi Oct 26, 2022
19a8476
adding a space
faisal-alvi Oct 26, 2022
b624592
Apply suggestions from code review
dkotter Oct 26, 2022
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
3 changes: 3 additions & 0 deletions hookdocs/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"change-supported-post-types": {
"title": "Change Supported Post Types"
},
"rest-end-points": {
"title": "WP REST Endpoints"
},
"modify-post-data": {
"title": "Modify Post Data"
},
Expand Down
187 changes: 187 additions & 0 deletions hookdocs/rest-end-points.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
The Sophi plugin supports several WP REST Endpoints to perform specific actions on the curated posts.

Right now, there are the following REST Endpoints available in the plugin:

1. Get the Curator Posts
2. Override the curator Posts

### 1. Get the Curator Posts

To get the curators posts from the Sophi API, the following rest endpoint can be used:

### [GET] `/wp-json/sophi/v1/site-automation`

It accepts the following parameters.

|Parameter|Required|Type|Default|
|---|---|---|---|
|pageName|yes|string||
|widgetName|yes|string||
|displayPostExcept|no|string|''|
|displayAuthor|no|string|''|
|displayPostDate|no|string|''|
|displayFeaturedImage|no|string|''|

### Example Request

```text
{WPSiteURL}/wp-json/sophi/v1/site-automation?pageName=test_page&widgetName=test_widget&displayFeaturedImage=true
```

Where `{WPSiteURL}` is a URL of your WordPress site.

### Example Response

```json
[
{
"ID": 5859,
"post_author": "1",
"post_date": "2022-09-20 15:09:39",
"post_date_gmt": "2022-09-20 09:39:39",
"post_content": "<!-- wp:paragraph -->\n<p>Lorem ipsum</p>\n<!-- /wp:paragraph -->",
"post_title": "Test 01",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "open",
"ping_status": "open",
"post_password": "",
"post_name": "test-01",
"to_ping": "",
"pinged": "",
"post_modified": "2022-10-04 15:39:21",
"post_modified_gmt": "2022-10-04 10:09:21",
"post_content_filtered": "",
"post_parent": 0,
"guid": "https://wpne.local/?p=5859",
"menu_order": 0,
"post_type": "post",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"postLink": "https://wpne.local/test-01/",
"featuredImage": "<img width=\"591\" height=\"590\" src=\"https://wpne.local/wp-content/uploads/2022/05/test-01.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" loading=\"lazy\" srcset=\"https://wpne.local/wp-content/uploads/2022/05/test-01.jpg 591w, https://wpne.local/wp-content/uploads/2022/05/test-01-450x450.jpg 450w, https://wpne.local/wp-content/uploads/2022/05/test-01-100x100.jpg 100w, https://wpne.local/wp-content/uploads/2022/05/test-01-300x300.jpg 300w, https://wpne.local/wp-content/uploads/2022/05/test-01-150x150.jpg 150w\" sizes=\"(max-width: 591px) 100vw, 591px\" style=\"width:100%;height:99.83%;max-width:591px;\" />"
},
{
"ID": 5856,
"post_author": "1",
"post_date": "2022-09-20 15:00:48",
"post_date_gmt": "2022-09-20 09:30:48",
"post_content": "<!-- wp:paragraph -->\n<p>Lorem ipsum</p>\n<!-- /wp:paragraph -->",
"post_title": "test-02",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "open",
"ping_status": "open",
"post_password": "",
"post_name": "test-02",
"to_ping": "",
"pinged": "",
"post_modified": "2022-09-20 17:00:51",
"post_modified_gmt": "2022-09-20 11:30:51",
"post_content_filtered": "",
"post_parent": 0,
"guid": "https://wpne.local/?p=5856",
"menu_order": 0,
"post_type": "post",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"postLink": "https://wpne.local/test-02/",
"featuredImage": ""
}
]
```

### 2. Override the curator Posts

To override the curators post, the following rest endpoint can be used:

### [POST] `/wp-json/sophi/v1/site-automation-override`

It accepts the following parameters.

|Parameter|Required|Type|Default|
|---|---|---|---|
|ruleType|yes|string|Default is not set<br>Acceptable values:<br>`in/replace/remove/ban`|
|overridePostID|yes|integer||
|pageName|yes|string||
|widgetName|no|string||
|position|no|integer|1|
|overrideExpiry|no|integer|2|

### Example Request

```text
{WPSiteURL}/wp-json/sophi/v1/site-automation-override?pageName=test_name&widgetName=test_widget&ruleType=ban&overridePostID=123&position=1&overrideExpiry=2
```

Where `{WPSiteURL}` is a URL of your WordPress site.

### Example Response

```json
{
"id": "1085",
"articleId": "123",
"widgetName": null,
"page": "test_name",
"position": null,
"requestedUserName": "admin@gmail.com",
"expirationHour": 2,
"expirationDate": "2022-10-07T15:34:33.712+00:00",
"creationDate": "2022-10-07T13:34:33.712+00:00",
"ruleType": "out",
"replacedArticleId": null,
"tenantId": "10up",
"hostConfigId": "34",
"status": "ACTIVE"
}
```

### A few error response examples:

When a required parameter is missing in the request.

```json
{
"code": "rest_missing_callback_param",
"message": "Missing parameter(s): pageName",
"data": {
"status": 400,
"params": [
"pageName"
]
}
}
```

When invalid credentials provided. An auth token is generated from the credentials details saved in the WordPress settings page. The error response is received when a token is not generated or invalid.

```json
{
"code": 401,
"message": "Invalid API token, please try adding correct credentials on the settings page.",
"data": null
}
```

When WordPress user is not logged in. Basic Authentication is required.

```json
{
"code": 401,
"message": "Unauthorised user, please log in.",
"data": null
}
```

On unauthorised request.

```json
{
"code": 401,
"message": "Unauthorized",
"data": null
}
```
Loading