-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Impersonation From Admin Panel (#39)
* refactor: move modules to `common` * fix: use correct app import * chore: move translations to shared key * fix: export common extend in admin * feat: create shared button * refactor: use shared button in forum frontend * feat: allow passing redirect href to Button * feat: extend `UserListPage` with new Button * chore: require `flarum/core` 1.8.6 * chore * chore: try 1.8.7
- Loading branch information
1 parent
1ee1e2f
commit 907149d
Showing
12 changed files
with
90 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { default as commonExtend } from '../common/extend'; | ||
|
||
export default [...commonExtend]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import app from 'flarum/admin/app'; | ||
import { extend } from 'flarum/common/extend'; | ||
import UserListPage from 'flarum/admin/components/UserListPage'; | ||
import LoginAsUserButton from '../common/components/#AsUserButton'; | ||
|
||
import type ItemList from 'flarum/common/utils/ItemList'; | ||
import type User from 'flarum/common/models/User'; | ||
import type Mithril from 'mithril'; | ||
|
||
export default function extendUserListPage() { | ||
extend(UserListPage.prototype, 'userActionItems', function (items: ItemList<Mithril.Children>, user: User) { | ||
const forumBaseUrl = app.forum.attribute('baseUrl'); | ||
|
||
items.add('impersonate', <LoginAsUserButton user={user} redirectTo={`${forumBaseUrl}/u/${user.slug()}`} />); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import app from 'flarum/common/app'; | ||
import Button from 'flarum/common/components/Button'; | ||
import type { IButtonAttrs } from 'flarum/common/components/Button'; | ||
import type User from 'flarum/common/models/User'; | ||
import ImpersonateModal from './ImpersonateModal'; | ||
|
||
export interface ILoginAsUserButtonAttrs extends IButtonAttrs { | ||
user: User; | ||
redirectTo?: string; | ||
} | ||
|
||
export default class LoginAsUserButton extends Button<ILoginAsUserButtonAttrs> { | ||
view() { | ||
return ( | ||
<Button icon="fas fa-id-card" onclick={this.loginAsUser.bind(this)}> | ||
{app.translator.trans('fof-impersonate.lib.user_controls.impersonate_button')} | ||
</Button> | ||
); | ||
} | ||
|
||
loginAsUser(): void { | ||
const { user, redirectTo } = this.attrs; | ||
app.modal.show(ImpersonateModal, { | ||
callback: () => { | ||
redirectTo ? (window.location.href = redirectTo) : window.location.reload(); | ||
}, | ||
user, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Extend from 'flarum/common/extenders'; | ||
import User from 'flarum/common/models/User'; | ||
import Impersonate from './models/Impersonate'; | ||
|
||
export default [ | ||
new Extend.Store() // | ||
.add('impersonate', Impersonate), | ||
|
||
new Extend.Model(User) // | ||
.attribute<boolean>('canFoFImpersonate') | ||
.attribute<boolean>('impersonateReasonRequired'), | ||
]; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
import Extend from 'flarum/common/extenders'; | ||
import User from 'flarum/common/models/User'; | ||
import Impersonate from './model/Impersonate'; | ||
import { default as commonExtend } from '../common/extend'; | ||
|
||
export default [ | ||
new Extend.Store() // | ||
.add('impersonate', Impersonate), | ||
|
||
new Extend.Model(User) // | ||
.attribute<boolean>('canFoFImpersonate') | ||
.attribute<boolean>('impersonateReasonRequired'), | ||
]; | ||
export default [...commonExtend]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { extend } from 'flarum/common/extend'; | ||
import app from 'flarum/forum/app'; | ||
import UserControls from 'flarum/forum/utils/UserControls'; | ||
import LoginAsUserButton from '../common/components/#AsUserButton'; | ||
|
||
export { default as extend } from './extend'; | ||
|
||
app.initializers.add('fof-impersonate', () => { | ||
extend(UserControls, 'moderationControls', (items, user) => { | ||
if (user.canFoFImpersonate()) { | ||
items.add('fof-impersonate-login', <LoginAsUserButton user={user} />); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters