Add "STAFF" badge for admin & show badges at texture detail page
This commit is contained in:
parent
65d82fba64
commit
920d45a723
@ -10,6 +10,7 @@ use Storage;
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
use App\Services\Filter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
@ -111,7 +112,7 @@ class SkinlibController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($tid)
|
||||
public function show(Filter $filter, $tid)
|
||||
{
|
||||
$texture = Texture::find($tid);
|
||||
$user = Auth::user();
|
||||
@ -133,6 +134,16 @@ class SkinlibController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$badges = [];
|
||||
$uploader = User::find($texture->uploader);
|
||||
if ($uploader) {
|
||||
if ($uploader->isAdmin()) {
|
||||
$badges[] = ['text' => 'STAFF', 'color' => 'primary'];
|
||||
}
|
||||
|
||||
$badges = $filter->apply('user_badges', $badges, [$uploader]);
|
||||
}
|
||||
|
||||
$commentScript = get_string_replaced(
|
||||
option('comment_script'),
|
||||
[
|
||||
@ -152,6 +163,7 @@ class SkinlibController extends Controller
|
||||
'inCloset' => $user && $user->closet()->where('tid', $texture->tid)->count() > 0,
|
||||
'nickname' => ($up = User::find($texture->uploader)) ? $up->nickname : null,
|
||||
'report' => intval(option('reporter_score_modification', 0)),
|
||||
'badges' => $badges,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,9 @@ class UserPanelComposer
|
||||
$avatar = url('avatar/45/'.base64_encode($user->email).'.png?tid='.$user->avatar);
|
||||
|
||||
$badges = [];
|
||||
if (auth()->user()->isAdmin()) {
|
||||
$badges[] = ['text' => 'STAFF', 'color' => 'primary'];
|
||||
}
|
||||
$this->dispatcher->dispatch(new \App\Events\RenderingBadges($badges));
|
||||
|
||||
$view->with([
|
||||
|
@ -125,7 +125,7 @@ class Hook
|
||||
Event::listen(
|
||||
Events\RenderingBadges::class,
|
||||
function (Events\RenderingBadges $event) use ($text, $color) {
|
||||
$event->badges[] = [$text, $color];
|
||||
$event->badges[] = compact('text', 'color');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -130,6 +130,13 @@
|
||||
<a
|
||||
:href="`${baseUrl}/skinlib?filter=${type === 'cape' ? 'cape' : 'skin'}&uploader=${uploader}`"
|
||||
>{{ uploaderNickName }}</a>
|
||||
<br>
|
||||
<span
|
||||
v-for="(badge, i) in badges"
|
||||
:key="i"
|
||||
class="badge mr-2"
|
||||
:class="`bg-${badge.color}`"
|
||||
>{{ badge.text }}</span>
|
||||
</td>
|
||||
<td v-else><span v-t="'general.unexistent-user'" /></td>
|
||||
</tr>
|
||||
@ -256,6 +263,7 @@ export default {
|
||||
admin: blessing.extra.admin,
|
||||
uploaderNickName: blessing.extra.nickname,
|
||||
reportScore: blessing.extra.report,
|
||||
badges: blessing.extra.badges,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -422,4 +430,6 @@ export default {
|
||||
<style lang="stylus">
|
||||
.table > tbody > tr > td
|
||||
border-top 0
|
||||
&:first-child
|
||||
min-width 30%
|
||||
</style>
|
||||
|
@ -14,13 +14,16 @@ type Component = Vue & {
|
||||
type: 'steve' | 'alex' | 'cape'
|
||||
}
|
||||
|
||||
window.blessing.extra = {
|
||||
download: true,
|
||||
currentUid: 0,
|
||||
admin: false,
|
||||
nickname: 'author',
|
||||
inCloset: false,
|
||||
}
|
||||
beforeEach(() => {
|
||||
window.blessing.extra = {
|
||||
download: true,
|
||||
currentUid: 0,
|
||||
admin: false,
|
||||
nickname: 'author',
|
||||
inCloset: false,
|
||||
badges: [],
|
||||
}
|
||||
})
|
||||
|
||||
const previewer = Vue.extend({
|
||||
render(h) {
|
||||
@ -53,6 +56,7 @@ test('button for adding to closet should be enabled if auth', () => {
|
||||
|
||||
test('likes count indicator', async () => {
|
||||
Vue.prototype.$http.get.mockResolvedValue({ data: { likes: 2 } })
|
||||
Object.assign(window.blessing.extra, { inCloset: true, currentUid: 1 })
|
||||
const wrapper = mount(Show, {
|
||||
mocks: {
|
||||
$route: ['/skinlib/show/1', '1'],
|
||||
@ -384,6 +388,7 @@ test('delete texture', async () => {
|
||||
})
|
||||
|
||||
test('report texture', async () => {
|
||||
Object.assign(window.blessing.extra, { currentUid: 1 })
|
||||
Vue.prototype.$http.get.mockResolvedValue({ data: { report: 0 } })
|
||||
Vue.prototype.$http.post
|
||||
.mockResolvedValueOnce({ code: 1, message: 'duplicated' })
|
||||
@ -439,6 +444,7 @@ test('report texture', async () => {
|
||||
})
|
||||
|
||||
test('apply texture to player', () => {
|
||||
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
|
||||
Vue.prototype.$http.get
|
||||
.mockResolvedValue({ data: {} })
|
||||
.mockResolvedValue([])
|
||||
@ -466,3 +472,17 @@ test('truncate too long texture name', async () => {
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.card-primary').text()).toContain('very-very-long-...')
|
||||
})
|
||||
|
||||
test('render badges', async () => {
|
||||
Vue.prototype.$http.get.mockResolvedValue({ data: {} })
|
||||
Object.assign(window.blessing.extra, {
|
||||
badges: [{ text: 'reina', color: 'purple' }]
|
||||
})
|
||||
const wrapper = mount(Show, {
|
||||
mocks: {
|
||||
$route: ['/skinlib/show/1', '1'],
|
||||
},
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.badge.bg-purple').text()).toBe('reina')
|
||||
})
|
||||
|
@ -12,6 +12,8 @@
|
||||
- Spanish support (Greatly thanks [@poopingpenis](https://github.com/poopingpenis))
|
||||
- Brand new website theme color settings.
|
||||
- Detect Readme file of plugin automatically.
|
||||
- Added badge "STAFF" for administrators.
|
||||
- Added badges at texture detail page.
|
||||
|
||||
## Tweaked
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
- 西班牙语支持(感谢 [@poopingpenis](https://github.com/poopingpenis))
|
||||
- 全新的站点配色设置
|
||||
- 自动识别插件的说明文件
|
||||
- 增加管理员专有的「STAFF」badge
|
||||
- 在材质详情页中显示上传者的 badge
|
||||
|
||||
## 调整
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
<div class="mt-3 ml-2 mr-2 d-flex flex-wrap">
|
||||
{% for badge in badges %}
|
||||
<span class="badge bg-{{ badge[1] }} mb-1">{{ badge[0] }}</span>
|
||||
<span class="badge bg-{{ badge.color }} mb-1">{{ badge.text }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,6 +5,7 @@ namespace Tests;
|
||||
use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
use App\Services\Filter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@ -317,6 +318,24 @@ class SkinlibControllerTest extends TestCase
|
||||
$this->actingAs($uploader)
|
||||
->get('/skinlib/show/'.$texture->tid)
|
||||
->assertViewHas('texture');
|
||||
|
||||
// Badges.
|
||||
$uploader->permission = User::ADMIN;
|
||||
$uploader->save();
|
||||
$this->get('/skinlib/show/'.$texture->tid)
|
||||
->assertSee('primary')
|
||||
->assertSee('STAFF');
|
||||
$uid = $uploader->uid;
|
||||
resolve(Filter::class)->add('user_badges', function ($badges, $uploader) use ($uid) {
|
||||
$this->assertEquals($uid, $uploader->uid);
|
||||
|
||||
$badges[] = ['text' => 'badge-test', 'color' => 'maroon'];
|
||||
|
||||
return $badges;
|
||||
});
|
||||
$this->get('/skinlib/show/'.$texture->tid)
|
||||
->assertSee('badge-test')
|
||||
->assertSee('maroon');
|
||||
}
|
||||
|
||||
public function testInfo()
|
||||
|
@ -24,9 +24,15 @@ class UserPanelComposerTest extends TestCase
|
||||
$this->actingAs($user);
|
||||
|
||||
Event::listen(\App\Events\RenderingBadges::class, function ($event) {
|
||||
$event->badges[] = ['Pro', 'purple'];
|
||||
$event->badges[] = ['text' => 'Pro', 'color' => 'purple'];
|
||||
});
|
||||
|
||||
$this->get('/user')->assertSee('<span class="badge bg-purple mb-1">Pro</span>');
|
||||
$this->get('/user')
|
||||
->assertSee('<span class="badge bg-purple mb-1">Pro</span>');
|
||||
|
||||
$user->permission = User::ADMIN;
|
||||
$user->save();
|
||||
$this->get('/user')
|
||||
->assertSee('<span class="badge bg-primary mb-1">STAFF</span>');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user