-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: IP info modal and map for moderators, and integration with sess…
…ion info (#29) * feat: IP info modal and map for moderators, and integration with session info * Apply fixes from StyleCI * change icon * chore: ready up for core 1.8.2 --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
af0ab7f
commit f144434
Showing
12 changed files
with
391 additions
and
45 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
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,87 @@ | ||
import app from 'flarum/forum/app'; | ||
import Modal, { IInternalModalAttrs } from 'flarum/common/components/Modal'; | ||
import ZipCodeMap from './ZipCodeMap'; | ||
import IPInfo from '../models/IPInfo'; | ||
import { handleCopyIP } from '../helpers/ClipboardHelper'; | ||
import LabelValue from 'flarum/common/components/LabelValue'; | ||
import type Mithril from 'mithril'; | ||
import LoadingIndicator from 'flarum/common/components/LoadingIndicator'; | ||
|
||
interface MapModalAttrs extends IInternalModalAttrs { | ||
ipInfo?: IPInfo; | ||
ipAddr: string; | ||
} | ||
|
||
export default class MapModal extends Modal<MapModalAttrs> { | ||
ipInfo: IPInfo | undefined; | ||
|
||
oninit(vnode: Mithril.Vnode<MapModalAttrs, this>) { | ||
super.oninit(vnode); | ||
this.ipInfo = this.attrs.ipInfo; | ||
if (this.ipInfo === undefined) { | ||
this.loadIpInfo(); | ||
} | ||
} | ||
|
||
className() { | ||
return 'MapModal Modal--medium'; | ||
} | ||
|
||
loadIpInfo() { | ||
app.store | ||
.find<IPInfo>('ip_info', encodeURIComponent(this.attrs.ipAddr)) | ||
.then((ipInfo) => { | ||
this.ipInfo = ipInfo; | ||
m.redraw(); | ||
}) | ||
.catch((error) => { | ||
console.error('Failed to load IP information from the store', error); | ||
}); | ||
} | ||
|
||
title() { | ||
return app.translator.trans('fof-geoip.forum.map_modal.title'); | ||
} | ||
|
||
content() { | ||
const ipInfo = this.ipInfo; | ||
|
||
if (!ipInfo) { | ||
return ( | ||
<div className="Modal-body"> | ||
<LoadingIndicator /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="Modal-body"> | ||
<div className="IPDetails"> | ||
<LabelValue | ||
label={app.translator.trans('fof-geoip.forum.map_modal.ip_address')} | ||
value={ | ||
<span className="clickable-ip" onclick={handleCopyIP(this.attrs.ipAddr)}> | ||
{this.attrs.ipAddr} | ||
</span> | ||
} | ||
/> | ||
{ipInfo.countryCode() && <LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.country_code')} value={ipInfo.countryCode()} />} | ||
{ipInfo.zipCode() && <LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.zip_code')} value={ipInfo.zipCode()} />} | ||
{ipInfo.isp() && <LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.isp')} value={ipInfo.isp()} />} | ||
{ipInfo.organization() && ( | ||
<LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.organization')} value={ipInfo.organization()} /> | ||
)} | ||
{ipInfo.threatLevel() && <LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.threat_level')} value={ipInfo.threatLevel()} />} | ||
{ipInfo.threatTypes().length > 0 && ( | ||
<LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.threat_types')} value={ipInfo.threatTypes().join(', ')} /> | ||
)} | ||
{ipInfo.error() && <LabelValue label={app.translator.trans('fof-geoip.forum.map_modal.error')} value={ipInfo.error()} />} | ||
</div> | ||
<hr /> | ||
<div id="mapContainer"> | ||
<ZipCodeMap zip={ipInfo.zipCode()} country={ipInfo.countryCode()} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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,28 @@ | ||
import app from 'flarum/forum/app'; | ||
import { extend } from 'flarum/common/extend'; | ||
import AccessTokensList from 'flarum/forum/components/AccessTokensList'; | ||
import ItemList from 'flarum/common/utils/ItemList'; | ||
import MapModal from '../components/MapModal'; | ||
import Button from 'flarum/common/components/Button'; | ||
import type Mithril from 'mithril'; | ||
import AccessToken from 'flarum/common/models/AccessToken'; | ||
|
||
export default function extendAccessTokensList() { | ||
extend(AccessTokensList.prototype, 'tokenActionItems', function (items: ItemList<Mithril.Children>, token: AccessToken) { | ||
const ipAddr = token.lastIpAddress(); | ||
|
||
if (ipAddr) { | ||
items.add( | ||
'geoip-info', | ||
<Button | ||
className="Button" | ||
onclick={() => app.modal.show(MapModal, { ipAddr: ipAddr })} | ||
aria-label={app.translator.trans('fof-geoip.forum.map_button_label')} | ||
> | ||
{app.translator.trans('fof-geoip.forum.map_button_label')} | ||
</Button>, | ||
10 | ||
); | ||
} | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import app from 'flarum/forum/app'; | ||
import extendPostMeta from './extenders/extendPostMeta'; | ||
import extendBanIPModal from './extenders/extendBanIPModal'; | ||
import extendAccessTokensList from './extenders/extendAccessTokensList'; | ||
|
||
export { default as extend } from './extend'; | ||
|
||
app.initializers.add('fof/geoip', () => { | ||
extendPostMeta(); | ||
extendBanIPModal(); | ||
|
||
// This cannot be enabled until https://github.com/flarum/framework/pull/3888 is merged and released | ||
extendAccessTokensList(); | ||
}); |
Oops, something went wrong.