booleanify public property

This commit is contained in:
Pig Fang 2018-07-16 11:10:01 +08:00
parent 0f7d44a2c9
commit 9cd6e0945d
9 changed files with 28 additions and 28 deletions

View File

@ -86,12 +86,12 @@ class SkinlibController extends Controller
if ($anonymous) {
// Show public textures only to anonymous visitors
$query = $query->where('public', 1);
$query = $query->where('public', true);
} else {
// Show private textures when show uploaded textures of current user
if ($uploader != $this->user->uid && !$this->user->isAdmin()) {
$query = $query->where(function ($innerQuery) {
$innerQuery->where('public', '=', '1')->orWhere('uploader', '=', $this->user->uid);
$innerQuery->where('public', true)->orWhere('uploader', '=', $this->user->uid);
});
}
}
@ -132,7 +132,7 @@ class SkinlibController extends Controller
abort(404, trans('skinlib.show.deleted').trans('skinlib.show.contact-admin'));
}
if ($texture->public == "0") {
if (!$texture->public) {
if (is_null($this->user) || ($this->user->uid != $texture->uploader && !$this->user->isAdmin()))
abort(403, trans('skinlib.show.private'));
}
@ -171,11 +171,11 @@ class SkinlibController extends Controller
$t->likes = 1;
$t->hash = bs_hash_file($request->file('file'));
$t->size = ceil($request->file('file')->getSize() / 1024);
$t->public = ($request->input('public') == 'true') ? "1" : "0";
$t->public = $request->input('public') == 'true';
$t->uploader = $this->user->uid;
$t->upload_at = Utils::getTimeFormatted();
$cost = $t->size * (($t->public == "1") ? Option::get('score_per_storage') : Option::get('private_score_per_storage'));
$cost = $t->size * ($t->public ? Option::get('score_per_storage') : Option::get('private_score_per_storage'));
$cost += option('score_per_closet_item');
if ($this->user->getScore() < $cost)
@ -187,7 +187,7 @@ class SkinlibController extends Controller
foreach ($results as $result) {
// if the texture already uploaded was set to private,
// then allow to re-upload it.
if ($result->type == $t->type && $result->public == "1") {
if ($result->type == $t->type && $result->public) {
return json(trans('skinlib.upload.repeated'), 0, [
'tid' => $result->tid
]);
@ -229,7 +229,7 @@ class SkinlibController extends Controller
if (option('return_score')) {
if ($u = $users->get($result->uploader)) {
if ($result->public == 1) {
if ($result->public) {
$u->setScore(
$result->size * option('score_per_storage'), 'plus'
);
@ -256,7 +256,7 @@ class SkinlibController extends Controller
if ($t->uploader != $this->user->uid && !$this->user->isAdmin())
return json(trans('skinlib.no-permission'), 1);
$score_diff = $t->size * (option('private_score_per_storage') - option('score_per_storage')) * ($t->public == 1 ? -1 : 1);
$score_diff = $t->size * (option('private_score_per_storage') - option('score_per_storage')) * ($t->public ? -1 : 1);
if ($users->get($t->uploader)->getScore() + $score_diff < 0) {
return json(trans('skinlib.upload.lack-score'), 1);
}
@ -274,7 +274,7 @@ class SkinlibController extends Controller
if ($t->setPrivacy(!$t->public)) {
return json([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => ($t->public == "0" ? trans('general.private') : trans('general.public'))]),
'msg' => trans('skinlib.privacy.success', ['privacy' => (!$t->public ? trans('general.private') : trans('general.public'))]),
'public' => $t->public
]);
}

View File

@ -63,7 +63,7 @@ class Closet
return true;
}
if ($t->public == 0 && $t->uploader != $uid && !app('users')->get($uid)->isAdmin()) {
if (!$t->public && $t->uploader != $uid && !app('users')->get($uid)->isAdmin()) {
return true;
}

View File

@ -19,12 +19,12 @@ class Texture extends Model
'likes' => 'integer',
'size' => 'integer',
'uploader' => 'integer',
'public' => 'integer',
'public' => 'boolean',
];
public function setPrivacy($public)
{
$this->public = $public ? "1" : "0";
$this->public = $public;
return $this->save();
}

View File

@ -49,7 +49,7 @@ class CreateAllTables extends Migration
$table->string('hash', 64);
$table->integer('size');
$table->integer('uploader');
$table->integer('public');
$table->tinyInteger('public');
$table->dateTime('upload_at');
});

View File

@ -58,7 +58,7 @@ describe('tests for "index" module', () => {
tid: 1,
name: 'name',
type: 'steve',
public: 0
public: false
}]);
expect($('#skinlib-paginator').css('display')).not.toBe('none');
expect($('.item').attr('tid')).toBe('1');
@ -75,7 +75,7 @@ describe('tests for "index" module', () => {
tid: 1,
name: 'name',
type: 'steve',
public: 0,
public: false,
liked: true
}]);
expect($('a.more.like').attr('title')).toBe('skinlib.removeFromCloset');
@ -88,7 +88,7 @@ describe('tests for "index" module', () => {
tid: 1,
name: 'name',
type: 'steve',
public: 0,
public: false,
liked: false
}]);
expect($('a.more.like').attr('title')).toBe('skinlib.addToCloset');
@ -101,7 +101,7 @@ describe('tests for "index" module', () => {
tid: 1,
name: 'name',
type: 'steve',
public: 1,
public: true,
liked: false
}]);
expect($('small.more').hasClass('hide')).toBe(true);
@ -560,8 +560,8 @@ describe('tests for "operations" module', () => {
it('change privacy', async () => {
const fetch = jest.fn()
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success', public: '0' }))
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success', public: false }))
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success', public: true }))
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
.mockReturnValueOnce(Promise.reject());
window.fetch = fetch;

View File

@ -120,7 +120,7 @@ function renderSkinlibItemComponent(item) {
<a title="${title}" class="more like ${liked} ${anonymous}" tid="${ item.tid }" href="javascript:;" data-placement="top" data-toggle="tooltip"><i class="fa fa-heart"></i></a>
<small class="more private-label ${(item.public === 0) ? '' : 'hide'}" tid="${ item.tid }">
<small class="more private-label ${(!item.public) ? '' : 'hide'}" tid="${ item.tid }">
${ trans('skinlib.private') }
</small>
</div>

View File

@ -179,7 +179,7 @@ async function changePrivacy(tid) {
if (errno === 0) {
toastr.success(msg);
if (result.public === '0') {
if (!result.public) {
$(`a:contains("${trans('skinlib.setAsPrivate')}")`).html(trans('skinlib.setAsPublic'));
} else {
$(`a:contains("${trans('skinlib.setAsPublic')}")`).html(trans('skinlib.setAsPrivate'));

View File

@ -25,7 +25,7 @@ class ClosetTest extends TestCase
$other = factory(User::class)->create();
$texture = factory(Texture::class)->create([
'uploader' => $other->uid,
'public' => 0
'public' => true
]);
$user = factory(User::class)->create();
$closet = new Closet($user->uid);

View File

@ -37,7 +37,7 @@ class SkinlibControllerTest extends TestCase
'hash' => $texture->hash,
'size' => $texture->size,
'uploader' => $texture->uploader,
'public' => $texture->public ? 1 : 0,
'public' => $texture->public,
'upload_at' => $texture->upload_at->format('Y-m-d H:i:s')
];
})
@ -374,7 +374,7 @@ class SkinlibControllerTest extends TestCase
'hash' => $texture->hash,
'size' => $texture->size,
'uploader' => $texture->uploader,
'public' => $texture->public ? 1 : 0,
'public' => $texture->public,
'upload_at' => $texture->upload_at->format('Y-m-d H:i:s')
]);
}
@ -605,8 +605,8 @@ class SkinlibControllerTest extends TestCase
$this->assertEquals('steve', $t->type);
$this->assertEquals(1, $t->likes);
$this->assertEquals(1, $t->size);
$this->assertEquals('1', $t->public);
$this->assertEquals($user->uid, $t->uploader);
$this->assertTrue($t->public);
// Upload a duplicated texture
$user = factory(User::class)->create();
@ -744,7 +744,7 @@ class SkinlibControllerTest extends TestCase
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => 0
'public' => false
]);
$this->assertEquals(0, Texture::find($texture->tid)->public);
@ -769,7 +769,7 @@ class SkinlibControllerTest extends TestCase
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => 0
'public' => false
]);
$this->assertEquals(0, User::find($uploader->uid)->score);
@ -783,7 +783,7 @@ class SkinlibControllerTest extends TestCase
->assertJson([
'errno' => 0,
'msg' => trans('skinlib.privacy.success', ['privacy' => trans('general.private')]),
'public' => 0
'public' => false
]);
$this->assertEquals(0, Player::find($player->pid)->tid_steve);
}