Skip to content

Commit

Permalink
Merge pull request #1156 from ladybirdweb/development
Browse files Browse the repository at this point in the history
Country code bug fixed
  • Loading branch information
Ashutosh pathak authored Jun 11, 2020
2 parents 9104fab + 2c8ec23 commit 9d5f75f
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 66 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Common/BaseSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct()
$this->middleware('auth');
$this->middleware('admin');
}

/**
* Get the logged activity.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Common/MailChimpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MailChimpController extends BaseMailChimpController

public function __construct()
{
$this->middleware('auth',['except'=>['addSubscriberByClientPanel']]);
$this->middleware('auth', ['except'=>['addSubscriberByClientPanel']]);
$mailchimp_set = new MailchimpSetting();
$this->mailchimp_set = $mailchimp_set->firstOrFail();
$this->mail_api_key = $this->mailchimp_set->api_key;
Expand Down
17 changes: 8 additions & 9 deletions app/Http/Controllers/Front/BaseCartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ public function reduceAgentQty(Request $request)
} catch (\Exception $ex) {
return errorResponse($ex->getMessage());
}

}

/**
Expand All @@ -225,7 +224,7 @@ public function updateAgentQty(Request $request)
}
}

private function getCartValues($productId, $canReduceAgent= false)
private function getCartValues($productId, $canReduceAgent = false)
{
$cart = \Cart::get($productId);
$hasPermissionToModifyAgent = Product::find($productId)->can_modify_agent;
Expand All @@ -238,17 +237,17 @@ private function getCartValues($productId, $canReduceAgent= false)
throw new \Exception('Product not present in cart.');
}

if($hasPermissionToModifyAgent) {
if($canReduceAgent) {
if ($hasPermissionToModifyAgent) {
if ($canReduceAgent) {
$agtqty = $agtqty / 2;
$price = \Cart::getTotal() /2;
$price = \Cart::getTotal() / 2;
} else {
$agtqty = $agtqty * 2;
$price = \Cart::getTotal() * 2;
}

}
return (['agtqty'=>$agtqty, 'price'=>$price, 'currency'=>$currency, 'symbol'=>$symbol]);

return ['agtqty'=>$agtqty, 'price'=>$price, 'currency'=>$currency, 'symbol'=>$symbol];
}

/**
Expand Down Expand Up @@ -284,8 +283,8 @@ public function updateProductQty(Request $request)
$id = $request->input('productid');
$cart = \Cart::get($id);
$qty = $cart->quantity + 1;
$price = $this->cost($id) ;
Cart::update($id, [
$price = $this->cost($id);
Cart::update($id, [
'quantity' => [
'relative' => false,
'value' => $qty,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Front/BaseClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function getInvoice($id)
try {
$invoice = $this->invoice->findOrFail($id);
$user = \Auth::user();
if($invoice->user_id != $user->id) {
if ($invoice->user_id != $user->id) {
throw new \Exception('Cannot view invoice. Invalid modification of data.');
}
$items = $invoice->invoiceItem()->get();
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/Front/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function payNow($invoiceid)
{
try {
$invoice = $this->invoice->find($invoiceid);
if($invoice->user_id != \Auth::user()->id) {
if ($invoice->user_id != \Auth::user()->id) {
throw new \Exception('Cannot initiate payment. Invalid modification of data');
}
$items = new \Illuminate\Support\Collection();
Expand Down Expand Up @@ -321,17 +321,16 @@ public function checkregularPaymentOrRenewal($invoiceid)
$paynow = false;

if ($invoiceid) {
if(Invoice::find($invoiceid)->user_id != \Auth::user()->id) {
if (Invoice::find($invoiceid)->user_id != \Auth::user()->id) {
throw new \Exception('Invalid modification of data');
}
$paynow = true;
}

return $paynow;
} catch (\Exception $ex) {
return redirect()->back()->with('fails',$ex->getMessage());
return redirect()->back()->with('fails', $ex->getMessage());
}

}

public function checkoutAction($invoice)
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Front/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function getOrder($id)
try {
$user = \Auth::user();
$order = $this->order->findOrFail($id);
if($order->client != $user->id) {
if ($order->client != $user->id) {
throw new \Exception('Cannot view order. Invalid modification of data.');
}
$invoice = $order->invoice()->first();
Expand All @@ -413,7 +413,6 @@ public function getOrder($id)
$licenseStatus = StatusSetting::pluck('license_status')->first();
$allowDomainStatus = StatusSetting::pluck('domain_check')->first();


return view(
'themes.default1.front.clients.show-order',
compact('invoice', 'order', 'user', 'product', 'subscription', 'licenseStatus', 'installationDetails', 'allowDomainStatus', 'date', 'licdate', 'versionLabel')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Front/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PageController extends GetPageTemplateController

public function __construct()
{
$this->middleware('auth',['except'=>['pageTemplates']]);
$this->middleware('auth', ['except'=>['pageTemplates']]);

$page = new FrontendPage();
$this->page = $page;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Google2FAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function postSetupValidateToken(Request $request)
public function disableTwoFactor(Request $request)
{
$user = $request->userId ? User::where('id', $request->userId)->first() : $request->user();
if(\Auth::user()->role != 'admin' && $user->id != \Auth::user()->id) {
if (\Auth::user()->role != 'admin' && $user->id != \Auth::user()->id) {
return errorResponse('Cannot disable 2FA. Invalid modification of data');
}
//make secret column blank
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Order/BaseOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

class BaseOrderController extends ExtendedOrderController
{
public function __construct(){
public function __construct()
{
$this->middleware('auth');
$this->middleware('admin');
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Order/ExtendedOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ public function changeDomain(Request $request)
public function reissueLicense(Request $request)
{
$order = Order::findorFail($request->input('id'));
if(\Auth::user()->role != 'admin' && $order->client != \Auth::user()->id) {
return errorResponse('Cannot reissue license. Invalid modification of data');
if (\Auth::user()->role != 'admin' && $order->client != \Auth::user()->id) {
return errorResponse('Cannot reissue license. Invalid modification of data');
}
$order->domain = '';
$licenseCode = $order->serial_key;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Order/RenewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function renewForm($id)
public function renewByClient($id, Request $request)
{
$userId = Subscription::find($id)->user_id;
if(\Auth::user()->role != 'admin' && $userId != \Auth::user()->id) {
if (\Auth::user()->role != 'admin' && $userId != \Auth::user()->id) {
throw new \Exception('Permission denied. Invalid modification of data');
}
$this->validate($request, [
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Payment/CurrencyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public function getButtonColor($id)
} else {
return '<form method="post" action='.url('dashboard-currency/'.$id).'>'.'<input type="hidden" name="_token" value='.\Session::token().'>'.'
<button type="submit" class="btn btn-sm btn-danger btn-xs"><i class="fa fa-close" style="color:white;"></i>&nbsp;&nbsp; Show on Dashboard</button></form>';

}
}

Expand Down
34 changes: 17 additions & 17 deletions app/Http/Controllers/Product/ExtendedBaseProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function getProductField(int $productid)
}
}

public function adminDownload($id, $invoice = '', $api= false)
public function adminDownload($id, $invoice = '', $api = false)
{
try {
if ($this->downloadValidation(true, $id, $invoice, $api)) {
Expand All @@ -157,6 +157,7 @@ public function adminDownload($id, $invoice = '', $api= false)
}
} catch (\Exception $e) {
Bugsnag::notifyException($e);

return redirect()->back()->with('fails', $e->getMessage());
}
}
Expand All @@ -173,38 +174,37 @@ public function adminDownload($id, $invoice = '', $api= false)
*/
private function downloadValidation(bool $allowDownload, $id, $invoice, $api)
{
if($api == false) {
if ($api == false) {
if (\Auth::user()->role == 'user') {
$invoice = Invoice::where('number', $invoice)->first(); //If invoice number sent as parameter exists
$this->checkSubscriptionExpiry($invoice);
$allowDownload = $invoice ? $invoice->order()->value('product') == $id : false; //If the order for the product sent in the parameter exists
}
}

return $allowDownload;
}

public function checkSubscriptionExpiry($invoice)
{
$checkSubscription = false;
if($invoice) {
if($invoice->user_id != \Auth::user()->id) {
throw new \Exception('Invalid modification of data. This user does not have permission for this action.');
}
$checkSubscription = $invoice->order()->first() ? $invoice->order()->first()->subscription : false;
$checkSubscription = false;
if ($invoice) {
if ($invoice->user_id != \Auth::user()->id) {
throw new \Exception('Invalid modification of data. This user does not have permission for this action.');
}
if($checkSubscription) {
if (strtotime($checkSubscription->update_ends_at) > 1) {
if ($checkSubscription->update_ends_at < (new Carbon())->toDateTimeString()) {
throw new \Exception('Please renew your subscription to download');
}
$checkSubscription = $invoice->order()->first() ? $invoice->order()->first()->subscription : false;
}
if ($checkSubscription) {
if (strtotime($checkSubscription->update_ends_at) > 1) {
if ($checkSubscription->update_ends_at < (new Carbon())->toDateTimeString()) {
throw new \Exception('Please renew your subscription to download');
}
} else {
throw new \Exception('No order exists for this invoice.');
}

} else {
throw new \Exception('No order exists for this invoice.');
}
}


/**
* Save Values Related to Cart(eg: whether show Agents or Quantity in Cart etc).
*
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RazorpayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct()
public function payment($invoice, Request $request)
{
$userId = Invoice::find($invoice)->user_id;
if(\Auth::user()->role != 'admin' && $userId != \Auth::user()->id) {
if (\Auth::user()->role != 'admin' && $userId != \Auth::user()->id) {
return errorResponse('Payment cannot be initiated. Invalid modification of data');
}
//Input items of form
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WelcomeController extends Controller

public function __construct(Request $request)
{
$this->middleware('auth');
$this->middleware('auth', ['except'=>['getCode']]);
$this->request = $request;
}

Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'name' => env('APP_NAME', 'Laravel'),

'version' => 'v1.3.0',
'version' => 'v1.3.1',

/*
|--------------------------------------------------------------------------
Expand Down
15 changes: 0 additions & 15 deletions tests/Unit/Client/Account/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ public function test_profile_whenClientUpdatesProfile()
$response->assertStatus(302);
}

/** @group my-profile */
public function test_profile_whenClientUpdatesPassword()
{
$this->withoutMiddleware();
$this->getLoggedInUser();
$user = $this->user;
$response = $this->call('PATCH', 'my-password', [
'old_password' => $user->password,
'new_password' => 'Faveo@123',
'confirm_password'=> 'Faveo@123',

]);
$response->assertStatus(200);
}

/** @group my-profile */
public function test_profile_whenOldAndNewPasswordDoesNotMatch()
{
Expand Down
18 changes: 11 additions & 7 deletions tests/Unit/Client/Product/DownloadApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Model\Order\Invoice;
use App\Model\Order\Order;
use App\Model\Product\Product;
use App\Model\Product\Subscription;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\DBTestCase;

Expand All @@ -21,8 +22,9 @@ public function test_downloadValidation_whenValidParamasPassed_returnstrue()
$product = factory(Product::class)->create();
$invoice = factory(Invoice::class)->create(['user_id'=> $user_id]);
$order = factory(Order::class)->create(['client'=> $user_id, 'invoice_id'=>$invoice->id, 'product'=>$product->id]);
$subscription = factory(Subscription::class)->create(['user_id'=>$user_id, 'product_id'=>$product->id, 'order_id'=>$order->id]);
$cont = new \App\Http\Controllers\Product\ExtendedBaseProductController();
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number]);
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number, false]);
$this->assertEquals($response, true);
}

Expand All @@ -35,36 +37,38 @@ public function test_downloadValidation_whenInValidProductIdPassed_returnsFalse(
$product = factory(Product::class)->create();
$invoice = factory(Invoice::class)->create(['user_id'=> $user_id]);
$order = factory(Order::class)->create(['client'=> $user_id, 'invoice_id'=>$invoice->id, 'product'=>$product->id]);
$subscription = factory(Subscription::class)->create(['user_id'=>$user_id, 'product_id'=>$product->id, 'order_id'=>$order->id]);
$cont = new \App\Http\Controllers\Product\ExtendedBaseProductController();
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', '1223434', $invoice->number]);
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', '1223434', $invoice->number, false]);
$this->assertEquals($response, false);
}

/** @group product-download */
public function test_downloadValidation_whenInValidInvoiceNoPassed_returnsFalse()
{
$this->expectException(\Exception::class);
$this->withoutMiddleware();
$this->getLoggedInUser();
$user_id = $this->user->id;
$product = factory(Product::class)->create();
$invoice = factory(Invoice::class)->create(['user_id'=> $user_id]);
$order = factory(Order::class)->create(['client'=> $user_id, 'invoice_id'=>$invoice->id, 'product'=>$product->id]);
$subscription = factory(Subscription::class)->create(['user_id'=>$user_id, 'order_id'=>$order->id]);
$cont = new \App\Http\Controllers\Product\ExtendedBaseProductController();
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, '2222']);
$this->assertEquals($response, false);
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, '2222', false]);
}

/** @group product-download */
public function test_downloadValidation_whenNoOrdersAttachedToAnInvoice_returnsFalse()
{
$this->expectException(\Exception::class);
$this->withoutMiddleware();
$this->getLoggedInUser();
$user_id = $this->user->id;
$product = factory(Product::class)->create();
$invoice = factory(Invoice::class)->create(['user_id'=> $user_id]);
$cont = new \App\Http\Controllers\Product\ExtendedBaseProductController();
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number]);
$this->assertEquals($response, false);
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number, false]);
}

/** @group product-download */
Expand All @@ -76,7 +80,7 @@ public function test_downloadValidation_whenUserRoleIsAdmin_returnsTrue()
$product = factory(Product::class)->create();
$invoice = factory(Invoice::class)->create(['user_id'=> $user_id]);
$cont = new \App\Http\Controllers\Product\ExtendedBaseProductController();
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number]);
$response = $this->getPrivateMethod($cont, 'downloadValidation', ['true', $product->id, $invoice->number, false]);
$this->assertEquals($response, true);
}
}

0 comments on commit 9d5f75f

Please sign in to comment.