Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

showing ip, needs permission now

  • Loading branch information...
luceos committed Jan 19, 2016
1 parent 042ef63 commit dbebc07763ff367debf9121caff572da5bd8ddbb
@@ -1,6 +1,6 @@
<?php
namespace Hyn\Guardian;
namespace Flagrow\Guardian;
use Illuminate\Contracts\Events\Dispatcher;
@@ -16,7 +16,7 @@
"source": "https://github.com/flagrow/flarum-ext-guardian"
},
"require": {
"flarum/core": "^0.1.0-beta.5"
"flarum/core": "^0.1.0-beta.4"
},
"extra": {
"flarum-extension": {
@@ -0,0 +1 @@
node_modules
@@ -0,0 +1,9 @@
var gulp = require('flarum-gulp');

gulp({
modules: {
'hyn/guardian': [
'src/**/*.js'
]
}
});
@@ -0,0 +1,33 @@
System.register('hyn/guardian/main', ['flarum/extend', 'flarum/components/PostMeta', 'flarum/components/CommentPost', 'flarum/models/Post', 'flarum/Model'], function (_export) {
'use strict';

var extend, PostMeta, CommentPost, Post, Model;
return {
setters: [function (_flarumExtend) {
extend = _flarumExtend.extend;
}, function (_flarumComponentsPostMeta) {
PostMeta = _flarumComponentsPostMeta['default'];
}, function (_flarumComponentsCommentPost) {
CommentPost = _flarumComponentsCommentPost['default'];
}, function (_flarumModelsPost) {
Post = _flarumModelsPost['default'];
}, function (_flarumModel) {
Model = _flarumModel['default'];
}],
execute: function () {

app.initializers.add('hyn-guardian', function (app) {
babelHelpers._extends(Post.prototype, {
user_ip: Model.attribute('user_ip')
});
extend(CommentPost.prototype, 'headerItems', function (items) {
if (this.props.post.user_ip()) {
items.add('guardian', m('div', { className: 'PostGuardian PostMeta' }, [this.props.post.user_ip()]));
}

return items;
});
});
}
};
});
@@ -0,0 +1,7 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.8.11",
"flarum-gulp": "^0.1.0"
}
}
@@ -0,0 +1,20 @@
import { extend } from 'flarum/extend';
import PostMeta from 'flarum/components/PostMeta';
import CommentPost from 'flarum/components/CommentPost';
import Post from 'flarum/models/Post';
import Model from 'flarum/Model';

app.initializers.add('hyn-guardian', app => {
Object.assign(Post.prototype, {
user_ip: Model.attribute('user_ip')
});
extend(CommentPost.prototype, 'headerItems', function(items) {
if(this.props.post.user_ip()) {
items.add('guardian', m('div', {className: 'PostGuardian PostMeta'}, [
this.props.post.user_ip()
]));
}

return items;
});
});
@@ -3,8 +3,10 @@
namespace Flagrow\Guardian\Listeners;
use DirectoryIterator;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Event\ConfigureClientView;
use Flarum\Event\ConfigureLocales;
use Flarum\Event\PrepareApiAttributes;
use Illuminate\Contracts\Events\Dispatcher;
/**
@@ -19,6 +21,7 @@ public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
$events->listen(ConfigureLocales::class, [$this, 'addLocales']);
$events->listen(PrepareApiAttributes::class, [$this, 'prepareApiAttributes']);
}
/**
@@ -34,6 +37,14 @@ public function addAssets(ConfigureClientView $event)
$event->addBootstrapper('hyn/guardian/main');
}
if ($event->isForum()) {
$event->addAssets([
__DIR__.'/../../js/forum/dist/extension.js',
]);
$event->addBootstrapper('hyn/guardian/main');
}
}
/**
@@ -47,4 +58,14 @@ public function addLocales(ConfigureLocales $event)
}
}
}
/**
* @param PrepareApiAttributes $event
*/
public function prepareApiAttributes(PrepareApiAttributes $event)
{
if ($event->isSerializer(PostSerializer::class) && $event->actor->can('guard', $event->model)) {
$event->attributes['user_ip'] = $event->model->ip_address;
}
}
}

0 comments on commit dbebc07

Please sign in to comment.
You can’t perform that action at this time.