diff --git a/README.md b/README.md index 39afbe2..34d476c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ By default these providers are included: - LinkedIn - Twitter +### Permissions + +This extension provides the ability to view the status of linked OAuth providers (intended for admin and/or moderator use). In order for this to function correctly, you must also set the permission `Moderate Access Tokens` to at least the same group as you require for `Moderate user's linked accounts`. + ### Additional providers Additional OAuth providers are available for this extension. Here's a handy list of known extensions, let us know if you know of any more and we'll get them added! diff --git a/extend.php b/extend.php index 3e35059..b9fb153 100644 --- a/extend.php +++ b/extend.php @@ -43,20 +43,14 @@ ->get('/auth/twitter', 'auth.twitter', Controllers\TwitterAuthController::class), (new Extend\Routes('api')) - ->get('/linked-accounts', 'users.provider.list', Api\Controllers\ListProvidersController::class) + ->get('/users/{id}/linked-accounts', 'users.provider.list', Api\Controllers\ListProvidersController::class) ->delete('/linked-accounts/{id}', 'users.provider.delete', Api\Controllers\DeleteProviderLinkController::class), (new Extend\ServiceProvider()) ->register(OAuthServiceProvider::class), (new Extend\ApiSerializer(ForumSerializer::class)) - ->attributes(function (ForumSerializer $serializer, $model, array $attributes): array { - if ($serializer->getActor()->isGuest()) { - $attributes['fof-oauth'] = resolve('fof-oauth.providers.forum'); - } - - return $attributes; - }), + ->attributes(Api\AddForumAttributes::class), (new Extend\Settings()) ->default('fof-oauth.only_icons', false) diff --git a/js/src/admin/index.js b/js/src/admin/index.js index cbf01be..0477c7f 100644 --- a/js/src/admin/index.js +++ b/js/src/admin/index.js @@ -1,11 +1,20 @@ import app from 'flarum/admin/app'; - import AuthSettingsPage from './components/AuthSettingsPage'; import ConfigureWithOAuthPage from './components/ConfigureWithOAuthPage'; import ConfigureWithOAuthButton from './components/ConfigureWithOAuthButton'; app.initializers.add('fof/oauth', () => { - app.extensionData.for('fof-oauth').registerPage(AuthSettingsPage); + app.extensionData + .for('fof-oauth') + .registerPage(AuthSettingsPage) + .registerPermission( + { + icon: 'fas fa-sign-in-alt', + label: app.translator.trans('fof-oauth.admin.permissions.moderate_user_providers'), + permission: 'moderateUserProviders', + }, + 'moderate' + ); }); export { AuthSettingsPage, ConfigureWithOAuthPage, ConfigureWithOAuthButton }; diff --git a/js/src/forum/components/LinkStatus.tsx b/js/src/forum/components/LinkStatus.tsx index 3e06eee..e67891f 100644 --- a/js/src/forum/components/LinkStatus.tsx +++ b/js/src/forum/components/LinkStatus.tsx @@ -8,7 +8,7 @@ import User from 'flarum/common/models/User'; import ProviderInfo from './ProviderInfo'; import extractText from 'flarum/common/utils/extractText'; -interface IAttrs { +interface IAttrs extends ComponentAttrs { provider: LinkedAccount; user: User; } @@ -18,7 +18,7 @@ export default class LinkStatus extends Component { loading: false, }; - onbeforeupdate(vnode: Mithril.Vnode) { + onbeforeupdate(vnode: Mithril.Vnode) { super.onbeforeupdate(vnode); if (app.fof_oauth_linkingInProgress && app.fof_oauth_linkingProvider === this.attrs.provider.name()) { this.state.loading = true; @@ -29,7 +29,7 @@ export default class LinkStatus extends Component { } } - view(vnode: Mithril.Vnode): Mithril.Children { + view(vnode: Mithril.Vnode): Mithril.Children { return (
{this.iconView()} @@ -70,7 +70,7 @@ export default class LinkStatus extends Component {
); - } else if (!provider.orphaned()) { + } else if (!provider.orphaned() && (user.id() === app.session.user?.id() || !app.forum.attribute('fofOauthModerate'))) { return (