Skip to content

Commit

Permalink
v5.0.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpanjwani committed Nov 30, 2021
1 parent d332712 commit 082d5ca
Show file tree
Hide file tree
Showing 1,323 changed files with 95,803 additions and 79,235 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ MAIL_PORT=587
MAIL_USERNAME=ff538f0e1037f4
MAIL_PASSWORD=c04c81145fcb73
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="admin@crater.com"
MAIL_FROM_ADDRESS="admin@craterapp.com"
MAIL_FROM_NAME="John Doe"
24 changes: 9 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// .eslintrc.js

module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/recommended',
'eslint:recommended',
'prettier/vue',
'plugin:prettier/recommended',
// add more generic rulesets here, such as:
// 'eslint:recommended',
"plugin:vue/vue3-recommended",
"prettier",
],
parserOptions: {
parser: 'babel-eslint',
},
plugins: ['prettier'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// override/add rules settings here, such as:
// 'vue/no-unused-vars': 'error'
},
}
};
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Homestead.yaml
.rnd
/.expo
/.vscode
/docker-compose/db/data/
/docker-compose/db/data/
78 changes: 41 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
FROM php:7.4-fpm
FROM php:7.4-fpm-alpine

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libzip-dev \
libmagickwand-dev \
mariadb-client

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pecl install imagick \
&& docker-php-ext-enable imagick

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user
RUN apk add --no-cache \
$PHPIZE_DEPS \
freetype-dev \
git \
zip \
libzip-dev \
php7-bcmath \
curl \
unzip \
libjpeg-turbo-dev \
libpng-dev \
libxml2-dev \
mariadb-client \
sqlite \
php7-json \
php7-openssl \
php7-pdo \
php7-pdo_mysql \
php7-session \
php7-simplexml \
php7-tokenizer \
php7-xml \
imagemagick \
imagemagick-libs \
imagemagick-dev \
php7-imagick \
php7-pcntl \
--repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3

ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

RUN printf "\n" | pecl install \
imagick && \
docker-php-ext-enable --ini-name 20-imagick.ini imagick

RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install iconv pdo pdo_mysql bcmath pcntl exif
RUN docker-php-ext-configure gd --with-jpeg --with-freetype
RUN docker-php-ext-install gd
2 changes: 1 addition & 1 deletion app/Console/Commands/CreateTemplateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function handle()
}

Storage::disk('views')->copy("/app/pdf/{$type}/{$type}1.blade.php", "/app/pdf/{$type}/{$templateName}.blade.php");
copy(public_path("/assets/img/PDF/{$type}1.png"), public_path("/assets/img/PDF/{$templateName}.png"));
copy(resource_path("/static/img/PDF/{$type}1.png"), resource_path("/static/img/PDF/{$templateName}.png"));

$path = resource_path("app/pdf/{$type}/{$templateName}.blade.php");
$type = ucfirst($type);
Expand Down
8 changes: 8 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crater\Console;

use Crater\Models\RecurringInvoice;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand Down Expand Up @@ -31,6 +32,13 @@ protected function schedule(Schedule $schedule)

$schedule->command('check:estimates:status')
->daily();

$recurringInvoices = RecurringInvoice::where('status', 'ACTIVE')->get();
foreach ($recurringInvoices as $recurringInvoice) {
$schedule->call(function () use ($recurringInvoice) {
$recurringInvoice->generateInvoice();
})->cron($recurringInvoice->frequency);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crater\Http\Controllers\V1\Auth;
namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Crater\Providers\RouteServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crater\Http\Controllers\V1\Auth;
namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Controllers/V1/Admin/Auth/LoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Crater\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;

/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crater\Http\Controllers\V1\Auth;
namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Crater\Models\User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crater\Http\Controllers\V1\Auth;
namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Crater\Providers\RouteServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Crater\Http\Controllers\V1\Auth;
namespace Crater\Http\Controllers\V1\Admin\Auth;

use Crater\Http\Controllers\Controller;
use Crater\Providers\RouteServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Implementation taken from nova-backup-tool - https://github.com/spatie/nova-backup-tool/

namespace Crater\Http\Controllers\V1\Backup;
namespace Crater\Http\Controllers\V1\Admin\Backup;

use Crater\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Implementation taken from nova-backup-tool - https://github.com/spatie/nova-backup-tool/

namespace Crater\Http\Controllers\V1\Backup;
namespace Crater\Http\Controllers\V1\Admin\Backup;

use Crater\Jobs\CreateBackupJob;
use Crater\Rules\Backup\PathToZip;
Expand All @@ -22,6 +22,8 @@ class BackupsController extends ApiController
*/
public function index(Request $request)
{
$this->authorize('manage backups');

$configuredBackupDisks = config('backup.backup.destination.disks');

try {
Expand Down Expand Up @@ -62,6 +64,8 @@ public function index(Request $request)
*/
public function store(Request $request)
{
$this->authorize('manage backups');

dispatch(new CreateBackupJob($request->all()))->onQueue(config('backup.queue.name'));

return $this->respondSuccess();
Expand All @@ -75,6 +79,8 @@ public function store(Request $request)
*/
public function destroy($disk, Request $request)
{
$this->authorize('manage backups');

$validated = $request->validate([
'path' => ['required', new PathToZip()],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Implementation taken from nova-backup-tool - https://github.com/spatie/nova-backup-tool/

namespace Crater\Http\Controllers\V1\Backup;
namespace Crater\Http\Controllers\V1\Admin\Backup;

use Crater\Rules\Backup\PathToZip;
use Illuminate\Http\Request;
Expand All @@ -15,6 +15,8 @@ class DownloadBackupController extends ApiController
{
public function __invoke(Request $request)
{
$this->authorize('manage backups');

$validated = $request->validate([
'path' => ['required', new PathToZip()],
]);
Expand Down
85 changes: 85 additions & 0 deletions app/Http/Controllers/V1/Admin/Company/CompaniesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Crater\Http\Controllers\V1\Admin\Company;

use Crater\Http\Controllers\Controller;
use Crater\Http\Requests\CompaniesRequest;
use Crater\Http\Resources\CompanyResource;
use Crater\Models\Company;
use Crater\Models\User;
use Illuminate\Http\Request;
use Silber\Bouncer\BouncerFacade;
use Vinkla\Hashids\Facades\Hashids;

class CompaniesController extends Controller
{
public function store(CompaniesRequest $request)
{
$this->authorize('create company');

$user = $request->user();

$company = Company::create($request->getCompanyPayload());
$company->unique_hash = Hashids::connection(Company::class)->encode($company->id);
$company->save();
$company->setupDefaultData();
$user->companies()->attach($company->id);
$user->assign('super admin');

if ($request->address) {
$company->address()->create($request->address);
}

return new CompanyResource($company);
}

public function destroy(Request $request)
{
$company = Company::find($request->header('company'));

$this->authorize('delete company', $company);

$user = $request->user();

if ($request->name !== $company->name) {
return respondJson('company_name_must_match_with_given_name', 'Company name must match with given name');
}

if ($user->loadCount('companies')->companies_count <= 1) {
return respondJson('You_cannot_delete_all_companies', 'You cannot delete all companies');
}

$company->deleteCompany($user);

return response()->json([
'success' => true
]);
}

public function transferOwnership(Request $request, User $user)
{
$company = Company::find($request->header('company'));
$this->authorize('transfer company ownership', $company);

if ($user->hasCompany($company->id)) {
return response()->json([
'success' => false,
'message' => 'User does not belongs to this company.'
]);
}

$company->update(['owner_id' => $user->id]);
BouncerFacade::sync($user)->roles(['super admin']);

return response()->json([
'success' => true
]);
}

public function getUserCompanies(Request $request)
{
$companies = $request->user()->companies;

return CompanyResource::collection($companies);
}
}
Loading

0 comments on commit 082d5ca

Please sign in to comment.