Skip to content

Commit

Permalink
fixed pending/and review components, added ability for admin to manua…
Browse files Browse the repository at this point in the history
…lly publish
  • Loading branch information
roncodes committed Oct 10, 2024
1 parent 4be8e24 commit 5b0f116
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 3 deletions.
10 changes: 10 additions & 0 deletions addon/components/extension-pending-publish-viewer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
</div>
</button>
<div class="space-y-2 mt-3">
{{#unless (eq extension.status "published")}}
<Button
@type="magic"
@size="sm"
@icon="rocket"
@text={{t "registry-bridge.component.extension-pending-publish-viewer.publish"}}
@onClick={{perform this.publishExtension extension}}
class="w-full"
/>
{{/unless}}
<Button
@size="sm"
@icon="clipboard-list"
Expand Down
10 changes: 9 additions & 1 deletion addon/components/extension-pending-publish-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class ExtensionPendingPublishViewerComponent extends Component {
}

@task *getExtensionsPendingPublish() {
this.extensions = yield this.store.query('registry-extension', { status: 'approved' });
this.extensions = yield this.store.query('registry-extension', { status: 'approved', admin: 1 });
}

@task *downloadBundle(extension) {
Expand All @@ -27,6 +27,14 @@ export default class ExtensionPendingPublishViewerComponent extends Component {
}
}

@task *publishExtension(extension) {
try {
yield extension.publish();
} catch (error) {
this.notifications.error(error.message);
}
}

@action focusExtension(extension) {
this.focusedExtension = extension;
}
Expand Down
2 changes: 1 addition & 1 deletion addon/components/extension-reviewer-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ExtensionReviewerControlComponent extends Component {
}

@task *getExtensionsPendingReview() {
this.extensions = yield this.store.query('registry-extension', { status: 'awaiting_review' });
this.extensions = yield this.store.query('registry-extension', { status: 'awaiting_review', admin: 1 });
}

@task *downloadBundle(extension) {
Expand Down
13 changes: 13 additions & 0 deletions addon/models/registry-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ export default class RegistryExtensionModel extends Model {
return fetch.post('registry-extensions/approve', { id: this.id, ...params }, { namespace: '~registry/v1', normalizeToEmberData: true, modelType: 'registry-extension' });
}

/**
* Submits the registry extension to be manually published.
*
* @return {Promise<RegistryExtensionModel>}
* @memberof RegistryExtensionModel
*/
@action publish(params = {}) {
const owner = getOwner(this);
const fetch = owner.lookup('service:fetch');

return fetch.post('registry-extensions/publish', { id: this.id, ...params }, { namespace: '~registry/v1', normalizeToEmberData: true, modelType: 'registry-extension' });
}

/**
* Submits the registry extension for rejection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ public function approve(RegistryExtensionActionRequest $request)
return ['registryExtension' => new $this->resource($extension)];
}

/**
* Mannually publishes a specific extension by its ID.
*
* This function locates a `RegistryExtension` using the provided ID and sets its status to 'published'.
* If the extension is successfully found and updated, it returns the extension resource. If the extension
* cannot be found, it returns an error response indicating the inability to locate the extension.
*
* @param RegistryExtensionActionRequest $request the validated request object
*
* @return \Illuminate\Http\Response|array returns an array containing the extension resource if successful,
* or an error response if the extension cannot be found
*/
public function manualPublish(RegistryExtensionActionRequest $request)
{
$id = $request->input('id');
$extension = RegistryExtension::find($id);
if ($extension) {
$extension->update(['status' => 'published', 'current_bundle_uuid' => $extension->next_bundle_uuid]);
$extension->nextBundle()->update(['status' => 'published']);
} else {
return response()->error('Unable to find extension to publish.');
}

return ['registryExtension' => new $this->resource($extension)];
}

/**
* Rejects a specific extension by its ID.
*
Expand Down
10 changes: 9 additions & 1 deletion server/src/Http/Filter/RegistryExtensionFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RegistryExtensionFilter extends Filter
{
public function queryForInternal()
{
if ($this->request->boolean('explore')) {
if ($this->request->boolean('explore') || $this->request->boolean('admin')) {
return;
}
$this->builder->where('company_uuid', $this->session->get('company'));
Expand All @@ -21,6 +21,14 @@ public function queryForPublic()
$this->builder->where('company_uuid', $this->session->get('company'));
}

public function admin()
{
$user = $this->request->user();
if ($user && $user->isNotAdmin()) {
$this->builder->where('company_uuid', $this->session->get('company'));
}
}

public function query(?string $searchQuery)
{
$this->builder->search($searchQuery);
Expand Down
1 change: 1 addition & 0 deletions server/src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function ($router) {
$router->post('{id}/submit', $controller('submit'));
$router->post('approve', $controller('approve'));
$router->post('reject', $controller('reject'));
$router->post('publish', $controller('manualPublish'));
$router->get('download-bundle', $controller('downloadBundle'));
$router->get('analytics', $controller('analytics'));
$router->get('installed', $controller('installed'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]);
Expand Down
2 changes: 2 additions & 0 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ registry-bridge:
approve: Approve
reject: Reject
details: Details
publish: Publish
about: About
about-extension: About {extensionName}
component:
Expand All @@ -26,6 +27,7 @@ registry-bridge:
{extensionName} Details
download-bundle: Download Bundle
view-details: View Details
publish: Publish
no-extensions-awaiting-publish: No extensions awaiting publish
extension-reviewer-control:
content-panel-title: Extensions Awaiting Review
Expand Down

0 comments on commit 5b0f116

Please sign in to comment.