Skip to content

Commit

Permalink
fix(package-manager): bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Jan 6, 2024
1 parent 7fb0e08 commit 56b2b3b
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export default class AuthMethodModal<CustomAttrs extends IAuthMethodModalAttrs =
oninput={(e: InputEvent) => this.token((e.target as HTMLTextAreaElement).value)}
rows="6"
placeholder={
this.token() === '***'
this.token().startsWith('unchanged:')
? extractText(app.translator.trans('flarum-package-manager.admin.auth_config.add_modal.unchanged_token_placeholder'))
: ''
}
>
{this.token() === '***' ? '' : this.token()}
{this.token().startsWith('unchanged:') ? '' : this.token()}
</textarea>
</div>
<div className="Form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {

content(): Mithril.Children {
const authSettings = Object.keys(this.settings);
const hasAuthSettings =
authSettings.length &&
authSettings.every((type) => {
const data = this.settings[type]();

return Array.isArray(data) ? data.length : Object.keys(data).length;
});

return (
<div className="SettingsGroups-content">
{authSettings.length ? (
{hasAuthSettings ? (
authSettings.map((type) => {
const hosts = this.settings[type]();

Expand All @@ -42,7 +49,7 @@ export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {
type,
host,
token: data,
onsubmit: this.onchange.bind(this),
onsubmit: this.onchange.bind(this, host),
})
}
>
Expand Down Expand Up @@ -88,7 +95,7 @@ export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {
loading={this.loading}
onclick={() =>
app.modal.show(AuthMethodModal, {
onsubmit: this.onchange.bind(this),
onsubmit: this.onchange.bind(this, null),
})
}
>
Expand All @@ -99,7 +106,15 @@ export default class ConfigureAuth extends ConfigureJson<IConfigureJson> {
return items;
}

onchange(type: string, host: string, token: string) {
this.setting(type)({ ...this.setting(type)(), [host]: token });
onchange(oldHost: string | null, type: string, host: string, token: string) {
const data = { ...this.setting(type)() };

if (oldHost) {
delete data[oldHost];
}

data[host] = token;

this.setting(type)(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export default class ConfigureComposer extends ConfigureJson<IConfigureJson> {
app.modal.show(RepositoryModal, {
name,
repository,
onsubmit: this.onchange.bind(this),
onsubmit: (repository: Repository, newName: string) => {
const repositories = this.setting('repositories')();
delete repositories[name];

this.setting('repositories')(repositories);

this.onchange(repository, newName);
},
})
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class Pagination extends Component<PaginationAttrs> {
return (
<nav className="Pagination UserListPage-gridPagination">
<Button
disabled={!this.attrs.list.hasPrev()}
disabled={!this.attrs.list.hasPrev() || app.packageManager.control.isLoading()}
title={app.translator.trans('core.admin.users.pagination.back_button')}
onclick={() => this.attrs.list.prev()}
icon="fas fa-chevron-left"
Expand All @@ -28,7 +28,7 @@ export default class Pagination extends Component<PaginationAttrs> {
})}
</span>
<Button
disabled={!this.attrs.list.hasNext()}
disabled={!this.attrs.list.hasNext() || app.packageManager.control.isLoading()}
title={app.translator.trans('core.admin.users.pagination.next_button')}
onclick={() => this.attrs.list.next()}
icon="fas fa-chevron-right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class QueueSection extends Component<{}> {
icon="fas fa-sync-alt"
onclick={() => app.packageManager.queue.load()}
aria-label={app.translator.trans('flarum-package-manager.admin.sections.queue.refresh')}
disabled={app.packageManager.control.isLoading()}
/>
</div>
</div>
Expand Down Expand Up @@ -147,6 +148,7 @@ export default class QueueSection extends Component<{}> {
// @todo fix in core
// @ts-ignore
onclick={() => app.modal.show(TaskOutputModal, { task })}
disabled={['pending', 'running'].includes(task.status())}
/>
),
className: 'Table-controls',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export default class TaskOutputModal<CustomAttrs extends TaskOutputModalAttrs =
return (
<div className="Modal-body">
<div className="TaskOutputModal-data">
<div className="Form-group">
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.guessed_cause')}</label>
<div className="FormControl TaskOutputModal-data-guessed-cause">
{(this.attrs.task.guessedCause() &&
app.translator.trans('flarum-package-manager.admin.exceptions.guessed_cause.' + this.attrs.task.guessedCause())) ||
app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.cause_unknown')}
{this.attrs.task.status() === 'failure' && (
<div className="Form-group">
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.guessed_cause')}</label>
<div className="FormControl TaskOutputModal-data-guessed-cause">
{(this.attrs.task.guessedCause() &&
app.translator.trans('flarum-package-manager.admin.exceptions.guessed_cause.' + this.attrs.task.guessedCause())) ||
app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.cause_unknown')}
</div>
</div>
</div>
)}

<div className="Form-group">
<label>{app.translator.trans('flarum-package-manager.admin.sections.queue.output_modal.command')}</label>
Expand Down
2 changes: 2 additions & 0 deletions extensions/package-manager/js/src/admin/states/QueueState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class QueueState {

// Refresh the page
window.location.reload();
} else if (app.packageManager.control.isLoading()) {
app.packageManager.control.setLoading(null);
}

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -102,6 +103,14 @@ protected function composerConfig(ServerRequestInterface $request): array
$this->composerJson->set($composerJson);
}

$default = [
'minimum-stability' => 'stable',
];

foreach ($this->configurable as $key) {
$composerJson[$key] = Arr::get($composerJson, $key, Arr::get($default, $key));
}

return Arr::only($composerJson, $this->configurable);
}

Expand All @@ -125,9 +134,23 @@ protected function authConfig(ServerRequestInterface $request): array
continue;
}

$data[$type][$host] = $token === '***'
? $authJson[$type][$host]
: $token;
if (str_starts_with($token, 'unchanged:')) {
$old = Str::of($token)->explode(':')->skip(1)->values()->all();

if (count($old) !== 2) {
continue;
}

[$oldType, $oldHost] = $old;

if (! isset($authJson[$oldType][$oldHost])) {
continue;
}

$data[$type][$host] = $authJson[$oldType][$oldHost];
} else {
$data[$type][$host] = $token;
}
}
}

Expand All @@ -138,7 +161,7 @@ protected function authConfig(ServerRequestInterface $request): array
// Remove tokens from response.
foreach ($authJson as $type => $hosts) {
foreach ($hosts as $host => $token) {
$authJson[$type][$host] = '***';
$authJson[$type][$host] = "unchanged:$type:$host";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function data(ServerRequestInterface $request, Document $document)
$offset = $this->extractOffset($request);

$results = Task::query()
->latest()
->latest('id')
->offset($offset)
->limit($limit)
->get();
Expand Down
20 changes: 14 additions & 6 deletions extensions/package-manager/src/Composer/ComposerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ComposerAdapter
*/
private $paths;

/**
* @var BufferedOutput|null
*/
private $output = null;

public function __construct(Application $application, OutputLogger $logger, Paths $paths)
{
$this->application = $application;
Expand All @@ -49,24 +54,27 @@ public function run(InputInterface $input, ?Task $task = null): ComposerOutput
{
$this->application->resetComposer();

$output = new BufferedOutput();
$this->output = $this->output ?? new BufferedOutput();

// This hack is necessary so that relative path repositories are resolved properly.
$currDir = getcwd();
chdir($this->paths->base);
$exitCode = $this->application->run($input, $output);
$exitCode = $this->application->run($input, $this->output);
chdir($currDir);

$command = Util::readableConsoleInput($input);
$output = $output->fetch();
$outputContent = $this->output->fetch();

if ($task) {
$task->update(compact('command', 'output'));
$task->update([
'command' => $command,
'output' => $outputContent,
]);
} else {
$this->logger->log($command, $output, $exitCode);
$this->logger->log($command, $outputContent, $exitCode);
}

return new ComposerOutput($exitCode, $output);
return new ComposerOutput($exitCode, $outputContent);
}

public static function setPhpVersion(string $phpVersion)
Expand Down
2 changes: 1 addition & 1 deletion extensions/package-manager/src/Job/ComposerCommandJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(Dispatcher $bus)

public function abort(Throwable $exception)
{
if (! $this->command->task->output) {
if (empty($this->command->task->output)) {
$this->command->task->output = $exception->getMessage();
}

Expand Down

0 comments on commit 56b2b3b

Please sign in to comment.