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