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

fix: users unable to access user directory #107

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: FoF User Directory PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF User Directory JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,11 +8,12 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ js/node_modules/
vendor/
composer.lock
js/dist
.phpunit.result.cache
41 changes: 35 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"issues": "https://github.com/FriendsOfFlarum/user-directory/issues",
"source": "https://github.com/FriendsOfFlarum/user-directory",
"forum": "https://discuss.flarum.org/d/5682"
},
"homepage": "https://friendsofflarum.org",
"funding": [
},
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
],
"authors": [
{
"name": "Daniël Klabbers",
Expand Down Expand Up @@ -56,11 +56,40 @@
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/5682"
},
"flarum-cli": {
"modules": {
"githubActions": true,
"backendTesting": true
}
}
},
"autoload": {
"psr-4": {
"FoF\\UserDirectory\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"FoF\\UserDirectory\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"require-dev": {
"flarum/testing": "^1.0.0"
}
}
10 changes: 10 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@

(new Extend\View())
->namespace('fof.user-directory', __DIR__.'/resources/views'),

(new Extend\Settings())
->default('fof-user-directory.admin.settings.link', false)
->default('fof-user-directory.use-small-cards', false)
->default('fof-user-directory.disable-global-search-source', false)
->default('fof-user-directory.default-sort', 'default')
->default('fof-user-directory.link-group-mentions', true)
->serializeToForum('userDirectorySmallCards', 'fof-user-directory.use-small-cards', 'boolVal')
->serializeToForum('userDirectoryDisableGlobalSearchSource', 'fof-user-directory.disable-global-search-source', 'boolVal')
->serializeToForum('userDirectoryLinkGroupMentions', 'fof-user-directory.link-group-mentions', 'boolVal'),
];
12 changes: 9 additions & 3 deletions src/Content/UserDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class UserDirectory
/**
* @var Factory
*/
private $view;
protected $view;

/**
* @var SettingsRepositoryInterface
*/
protected $settings;

/**
* A map of sort query param values to their API sort param.
Expand All @@ -47,10 +52,11 @@ class UserDirectory
'least_discussions' => 'discussionCount',
];

public function __construct(Client $api, Factory $view)
public function __construct(Client $api, Factory $view, SettingsRepositoryInterface $settings)
{
$this->api = $api;
$this->view = $view;
$this->settings = $settings;
}

private function getDocument(User $actor, array $params, Request $request)
Expand All @@ -68,7 +74,7 @@ public function __invoke(Document $document, Request $request): Document
$queryParams = $request->getQueryParams();
$actor = RequestUtil::getActor($request);

$sort = Arr::pull($queryParams, 'sort') ?: resolve(SettingsRepositoryInterface::class)->get('fof-user-directory.default-sort');
$sort = Arr::pull($queryParams, 'sort') ?: $this->settings->get('fof-user-directory.default-sort');
$q = Arr::pull($queryParams, 'q');
$page = Arr::pull($queryParams, 'page', 1);

Expand Down
9 changes: 2 additions & 7 deletions src/PermissionBasedForumSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ public function __construct(SettingsRepositoryInterface $settings)
$this->settings = $settings;
}

public function __invoke(ForumSerializer $serializer): array
public function __invoke(ForumSerializer $serializer, $model, array $attributes): array
{
$attributes = [];

// The link is visible if the user can access the user directory AND the link was enabled in extension settings
$attributes['canSeeUserDirectoryLink'] = $serializer->getActor()->can('seeUserList');
$attributes['userDirectorySmallCards'] = (bool) $this->settings->get('fof-user-directory.use-small-cards');
$attributes['userDirectoryDisableGlobalSearchSource'] = (bool) $this->settings->get('fof-user-directory.disable-global-search-source');
$attributes['canSeeUserDirectoryLink'] = $serializer->getActor()->can('seeUserList') && $this->settings->get('fof-user-directory-link');
$attributes['userDirectoryDefaultSort'] = $this->settings->get('fof-user-directory.default-sort') ?: 'default';
$attributes['userDirectoryLinkGroupMentions'] = (bool) $this->settings->get('fof-user-directory.link-group-mentions');

// Only serialize if the actor has permission
if ($permission = $serializer->getActor()->hasPermission('user.suspend')) {
Expand Down
Empty file added tests/fixtures/.gitkeep
Empty file.
Loading
Loading