Skip to content

Commit

Permalink
Merge branch 'master' into remove-comments-init
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Jul 4, 2023
2 parents a991751 + 5946af3 commit 6749d69
Show file tree
Hide file tree
Showing 35 changed files with 344 additions and 773 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ APP_LOG_LEVEL=debug

# DOCS_URL=

# clockwork provides local development insights (at /__clockwork/)
# adds a slight performance overhead.
CLOCKWORK_ENABLE=true

DB_HOST=localhost
DB_DATABASE=osu
DB_USERNAME=osuweb
Expand Down
99 changes: 1 addition & 98 deletions app/Http/Controllers/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use App\Http\Controllers\Store\Controller as Controller;
use App\Models\Store;
use Auth;
use Request;
use Validator;

class StoreController extends Controller
{
Expand All @@ -20,21 +18,16 @@ public function __construct()
{
$this->middleware('auth', ['only' => [
'getInvoice',
'postNewAddress',
'postUpdateAddress',
]]);

if (!$this->isAllowRestrictedUsers()) {
$this->middleware('check-user-restricted', ['only' => [
'getInvoice',
'postNewAddress',
'postUpdateAddress',
]]);
}

$this->middleware('verify-user', ['only' => [
'getInvoice',
'postUpdateAddress',
]]);

parent::__construct();
Expand All @@ -58,96 +51,6 @@ public function getInvoice($id = null)
abort(403);
}

$sentViaAddress = Store\Address::sender();
$forShipping = Auth::user()->isAdmin() && get_bool(Request::input('for_shipping'));
$copies = clamp(get_int(request('copies')), 1, config('store.invoice.max_copies'));

return ext_view('store.invoice', compact('order', 'forShipping', 'copies', 'sentViaAddress'));
}

public function missingMethod($parameters = [])
{
abort(404);
}

public function postUpdateAddress()
{
$address_id = (int) Request::input('id');
$address = Store\Address::find($address_id);
$order = $this->userCart();

if (!$address || $address->user_id !== Auth::user()->user_id) {
return error_popup('invalid address');
}

switch (Request::input('action')) {
default:
case 'use':
$order->address()->associate($address);
$order->save();

return ext_view('layout.ujs-reload', [], 'js');
break;
case 'remove':
if ($order->address_id === $address_id) {
return error_popup('Address is being used for this order!');
}

if ($otherOrders = Store\Order::where('address_id', '=', $address_id)->first()) {
return error_popup('Address was used in a previous order!');
}

Store\Address::destroy($address_id);

return ext_view('store.address-destroy', ['address_id' => $address_id], 'js');
break;
}
}

public function postNewAddress()
{
\Log::info(json_encode([
'tag' => 'NEW_ADDRESS',
'user_id' => Auth::user()->user_id,
'address' => Request::input('address'),
]));

$addressInput = get_params(request()->all(), 'address', [
'first_name',
'last_name',
'street',
'city',
'state',
'zip',
'country_code',
'phone',
]);

$validator = Validator::make($addressInput, [
'first_name' => ['required'],
'last_name' => ['required'],
'street' => ['required', 'mixture'],
'city' => ['required'],
'state' => ['required'],
'zip' => ['required', 'required'],
'country_code' => ['required'],
'phone' => ['required'],
]);

$addressInput['user_id'] = Auth::user()->user_id;

if ($validator->fails()) {
return error_popup($validator->errors()->first());
}

$address = Store\Address::create($addressInput);
$address->user()->associate(Auth::user());
$address->save();

$order = $this->userCart();
$order->address()->associate($address);
$order->save();

return ext_view('layout.ujs-reload', [], 'js');
return ext_view('store.invoice', compact('order'));
}
}
15 changes: 15 additions & 0 deletions app/Jobs/EsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace App\Jobs;

use Datadog;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function handle(): void

if ($model !== null) {
$model->esIndexDocument();
$this->incrementStat('index');

return;
}
Expand All @@ -66,5 +68,18 @@ public function handle(): void
$keyName = $model->getKeyName();
$model->setAttribute($keyName, $id);
$model->esDeleteDocument();
$this->incrementStat('delete');
}

private function incrementStat(string $action): void
{
Datadog::increment(
config('datadog-helper.prefix_web').'.es_document',
1,
[
'action' => $action,
'class' => $this->modelMeta['class'],
],
);
}
}
16 changes: 11 additions & 5 deletions app/Libraries/OrderCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,29 @@ public function validate()
$messages[] = $item->validationErrors()->allMessages();
}

$product = $item->product;

// Checkout process level validations, should not be part of OrderItem validation.
if ($item->product === null || !$item->product->isAvailable()) {
if ($product === null || !$product->isAvailable()) {
$messages[] = osu_trans('model_validation/store/product.not_available');
}

if (!$item->product->inStock($item->quantity)) {
if (!$product->inStock($item->quantity)) {
$messages[] = osu_trans('model_validation/store/product.insufficient_stock');
}

if ($item->quantity > $item->product->max_quantity) {
$messages[] = osu_trans('model_validation/store/product.too_many', ['count' => $item->product->max_quantity]);
if ($item->quantity > $product->max_quantity) {
$messages[] = osu_trans('model_validation/store/product.too_many', ['count' => $product->max_quantity]);
}

if ($shouldShopify && !$item->product->isShopify()) {
if ($shouldShopify && !$product->isShopify()) {
$messages[] = osu_trans('model_validation/store/product.must_separate');
}

if ($product->requiresShipping() && !$product->isShopify()) {
$messages[] = osu_trans('model_validation/store/product.not_available');
}

$customClass = $item->getCustomClassInstance();
if ($customClass !== null) {
$messages[] = $customClass->validate()->allMessages();
Expand Down
31 changes: 0 additions & 31 deletions app/Models/Store/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use App\Models\Country;
use App\Models\User;
use Auth;

/**
* @property int $address_id
Expand Down Expand Up @@ -55,34 +54,4 @@ public function countryName()
return $this->country->name;
}
}

public static function sender()
{
//todo: move to database
switch (Auth::user()->user_id) {
default:
case 4916903:
return new self([
'first_name' => 'osu!store',
'last_name' => '',
'street' => 'Room 304, Build 700 Nishijin 7-7-1',
'city' => 'Sawara',
'state' => 'Fukuoka',
'zip' => '814-0002',
'country' => Country::find('JP'),
'phone' => '+819064201305',
]);
case 2:
return new self([
'first_name' => 'osu!store',
'last_name' => '',
'street' => 'Nishi-Ooi 4-21-3 Birdie House A',
'city' => 'Shinagawa',
'state' => 'Tokyo',
'zip' => '140-0015',
'country' => Country::find('JP'),
'phone' => '+818013811430',
]);
}
}
}
6 changes: 1 addition & 5 deletions app/Models/Store/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,10 @@ public function getProviderReference(): ?string
return static::splitTransactionId($this->transaction_id)[1] ?? null;
}

public function getSubtotal($forShipping = false)
public function getSubtotal()
{
$total = 0;
foreach ($this->items as $i) {
if ($forShipping && !$i->product->requiresShipping()) {
continue;
}

$total += $i->subtotal();
}

Expand Down
3 changes: 0 additions & 3 deletions config/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

return [
'allow_restricted_users' => get_bool(env('STORE_ALLOW_RESTRICTED_USERS')) ?? false,
'invoice' => [
'max_copies' => get_int(env('STORE_INVOICE_MAX_COPIES')) ?? 10,
],
'mail' => [
'donation_thanks' => [
'sender_address' => env('STORE_THANKS_SENDER_ADDRESS', 'osu@ppy.sh'),
Expand Down
9 changes: 9 additions & 0 deletions database/factories/Store/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ public function masterTshirt(): static
'weight' => 100,
]);
}

public function virtual(): static
{
return $this->state([
'base_shipping' => 0.00,
'next_shipping' => 0.00,
'weight' => null,
]);
}
}
4 changes: 1 addition & 3 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@import "bem/account-edit-status";
@import "bem/account-verification-message";
@import "bem/address";
@import "bem/address-list";
@import "bem/admin-contest";
@import "bem/admin-contest-entry";
@import "bem/admin-menu";
Expand Down Expand Up @@ -178,8 +177,6 @@
@import "bem/gallery-thumbnails";
@import "bem/game-mode";
@import "bem/game-mode-link";
@import "bem/grid";
@import "bem/grid-cell";
@import "bem/grid-items";
@import "bem/header-buttons";
@import "bem/header-nav-mobile";
Expand Down Expand Up @@ -390,6 +387,7 @@
@import "bem/user-session-list-session";
@import "bem/user-verification";
@import "bem/user-verification-popup";
@import "bem/username-change";
@import "bem/value-display";
@import "bem/warning-box";
@import "bem/wiki-main-page";
Expand Down
44 changes: 1 addition & 43 deletions resources/css/bem/address.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,5 @@

.address {
margin-bottom: 20px;

&--card {
.default-box-shadow();
.default-border-radius();
background: @osu-colour-b4;
padding: 20px;
margin: 0;
}

&--card-active {
.default-box-shadow();
box-shadow: 0 0 0 3px @osu-colour-l4;
}

&--card-hover {
&:hover {
.default-box-shadow();
box-shadow: 0 0 0 3px @osu-colour-l4;
}
}

&__button-delete {
.reset-input();
color: @osu-colour-c1;
position: absolute;
padding: 10px;
top: 0;
right: 0;
font-size: 20px; // icon size

&:hover {
color: @osu-colour-red-2;
}
}

&__button-select {
position: absolute;
top: 0;
left: 0;
width: 1px;
height: 1px;
opacity: 0;
}
overflow-wrap: break-word;
}
13 changes: 7 additions & 6 deletions resources/css/bem/beatmap-discussion-timestamp.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

// avatar + paddings + margins
height: (@beatmap-discussion--avatar-size + 20px + 10px);

align-items: center;

display: flex;
position: sticky;
// 36px is page-extra-tabs height on desktop.
// This doesn't work when the new discussion box is visible.
top: calc(var(--navbar-height) + 36px);

&--sticky {
position: sticky;
// 36px is page-extra-tabs height on desktop.
// This doesn't work when the new discussion box is visible.
top: calc(var(--navbar-height) + 36px);
}

&__icons {
display: flex;
Expand Down
Loading

0 comments on commit 6749d69

Please sign in to comment.