mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Attach and Detach a user to a company (#3107)
* fixes for template controller * Default gateway as string * Bulk actions * Move currency_id back to settings * Allow store and update currency ID * Attach user to company_user * Add / Detach company users
This commit is contained in:
parent
bf41c634c0
commit
32aedf26dd
@ -212,6 +212,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
|
||||
public static $casts = [
|
||||
'currency_id' => 'string',
|
||||
'counter_number_applied' => 'string',
|
||||
'email_subject_custom1' => 'string',
|
||||
'email_subject_custom2' => 'string',
|
||||
|
@ -519,7 +519,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$invoices = Invoice::withTrashed()->find($this->transformKeys($ids))->company();
|
||||
$invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids));
|
||||
|
||||
if(!$invoices)
|
||||
return response()->json(['message'=>'No Invoices Found']);
|
||||
|
@ -8,7 +8,7 @@
|
||||
* @OA\Property(property="military_time", type="boolean", example=true, description="____________"),
|
||||
* @OA\Property(property="language_id", type="string", example="1", description="____________"),
|
||||
* @OA\Property(property="show_currency_code", type="boolean", example=true, description="____________"),
|
||||
* @OA\Property(property="currency_id", type="string", example=true, description="The settings currency id"),
|
||||
* @OA\Property(property="currency_id", type="string", example=true, description="The default currency id"),
|
||||
* @OA\Property(property="payment_terms", type="integer", example="1", description="-1 sets no payment term, 0 sets payment due immediately, positive integers indicates payment terms in days"),
|
||||
* @OA\Property(property="company_gateway_ids", type="string", example="1,2,3,4", description="A commad separate list of available gateways"),
|
||||
* @OA\Property(property="custom_value1", type="string", example="Custom Label", description="____________"),
|
||||
|
@ -4,5 +4,6 @@
|
||||
* schema="Payment",
|
||||
* type="object",
|
||||
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
|
||||
* @OA\Property(property="is_manual", type="bool", example=true, description="______"),
|
||||
* )
|
||||
*/
|
@ -15,6 +15,7 @@ use App\DataMapper\DefaultSettings;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Filters\UserFilters;
|
||||
use App\Http\Controllers\Traits\VerifiesUserEmail;
|
||||
use App\Http\Requests\User\AttachCompanyUserRequest;
|
||||
use App\Http\Requests\User\CreateUserRequest;
|
||||
use App\Http\Requests\User\DestroyUserRequest;
|
||||
use App\Http\Requests\User\DetachCompanyUserRequest;
|
||||
@ -23,6 +24,7 @@ use App\Http\Requests\User\ShowUserRequest;
|
||||
use App\Http\Requests\User\StoreUserRequest;
|
||||
use App\Http\Requests\User\UpdateUserRequest;
|
||||
use App\Jobs\Company\CreateCompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\User;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Transformers\UserTransformer;
|
||||
@ -571,10 +573,10 @@ class UserController extends BaseController
|
||||
{
|
||||
|
||||
$company = auth()->user()->company();
|
||||
|
||||
$user->companies()->attach($company->id, $request->all());
|
||||
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->user());
|
||||
$user->companies()->attach($company->id, array_merge($request->all(), ['account_id' => $company->account->id]));
|
||||
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->name());
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
|
||||
@ -617,8 +619,8 @@ class UserController extends BaseController
|
||||
public function detach(DetachCompanyUserRequest $request, User $user)
|
||||
{
|
||||
$company_user = CompanyUser::whereUserId($user->id)
|
||||
->whereCompanyId(auth()->user()->id)->first();
|
||||
|
||||
->whereCompanyId(auth()->user()->companyId())->first();
|
||||
|
||||
$company_user->token->delete();
|
||||
$company_user->delete();
|
||||
|
||||
|
@ -66,8 +66,9 @@ class StoreClientRequest extends Request
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input['settings'] = ClientSettings::defaults();
|
||||
|
||||
if(!isset($input['settings']))
|
||||
$input['settings'] = ClientSettings::defaults();
|
||||
|
||||
if(isset($input['group_settings_id']))
|
||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||
|
@ -39,7 +39,6 @@ class UpdateClientRequest extends Request
|
||||
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
|
||||
$rules['industry_id'] = 'integer|nullable';
|
||||
$rules['size_id'] = 'integer|nullable';
|
||||
//$rules['currency_id'] = 'integer|nullable';
|
||||
$rules['country_id'] = 'integer|nullable';
|
||||
$rules['shipping_country_id'] = 'integer|nullable';
|
||||
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
|
||||
@ -74,6 +73,7 @@ class UpdateClientRequest extends Request
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
|
||||
if(isset($input['group_settings_id']))
|
||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Requests\User;
|
||||
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -31,12 +32,16 @@ class AttachCompanyUserRequest extends Request
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
|
||||
$is_admin = request()->has('is_admin') ? request()->input('is_admin') : false;
|
||||
$permissions = request()->has('permissions') ? request()->input('permissions') : '';
|
||||
$settings = request()->has('settings') ? request()->input('settings') : json_encode(DefaultSettings::userSettings());
|
||||
$is_locked =request()->has('is_locked') ? request()->input('is_locked') : false;
|
||||
|
||||
$this->replace([
|
||||
'is_admin' => isset($request->input('is_admin')) ? $request->input('is_admin') : false,
|
||||
'permissions' => isset($request->input('permissions')) ? $request->input('permissions') : '',
|
||||
'settings' => isset($request->input('settings')) ? $request->input('settings') : json_encode(DefaultSettings::userSettings()),
|
||||
'is_locked' => isset($request->input('is_locked')) ? $request->input('is_locked') : false,
|
||||
'is_admin' => $is_admin,
|
||||
'permissions' => $permissions,
|
||||
'settings' => $settings,
|
||||
'is_locked' => $is_locked,
|
||||
'is_owner' => false,
|
||||
]);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class ClientTransformer extends EntityTransformer
|
||||
'group_settings_id' => isset($client->group_settings_id) ? (string)$this->encodePrimaryKey($client->group_settings_id) : '',
|
||||
'paid_to_date' => (float) $client->paid_to_date,
|
||||
'last_login' => (int)$client->last_login,
|
||||
'currency_id' => (string)$client->currency_id,
|
||||
// 'currency_id' => (string)$client->currency_id,
|
||||
'address1' => $client->address1 ?: '',
|
||||
'address2' => $client->address2 ?: '',
|
||||
'phone' => $client->phone ?: '',
|
||||
|
@ -298,7 +298,7 @@ class CreateUsersTable extends Migration
|
||||
$table->timestamp('last_login')->nullable();
|
||||
$table->unsignedInteger('industry_id')->nullable();
|
||||
$table->unsignedInteger('size_id')->nullable();
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
// $table->unsignedInteger('currency_id')->nullable();
|
||||
|
||||
$table->string('address1')->nullable();
|
||||
$table->string('address2')->nullable();
|
||||
@ -330,7 +330,7 @@ class CreateUsersTable extends Migration
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->foreign('industry_id')->references('id')->on('industries');
|
||||
$table->foreign('size_id')->references('id')->on('sizes');
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
// $table->foreign('currency_id')->references('id')->on('currencies');
|
||||
|
||||
});
|
||||
|
||||
@ -764,6 +764,7 @@ class CreateUsersTable extends Migration
|
||||
$t->timestamps(6);
|
||||
$t->softDeletes('deleted_at', 6);
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
$t->boolean('is_manual')->default(false);
|
||||
|
||||
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
|
@ -8,6 +8,8 @@ use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\User;
|
||||
@ -93,6 +95,23 @@ class UserTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
|
||||
$this->assertNotNull($user->company_user);
|
||||
$this->assertEquals($user->company_user->company_id, $this->company->id)
|
||||
$this->assertEquals($user->company_user->company_id, $this->company->id);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detachFromCompany?include=company_user');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
|
||||
$cu = CompanyUser::whereUserId($user->id)->whereCompanyId($this->company->id)->first();
|
||||
$ct = CompanyToken::whereUserId($user->id)->whereCompanyId($this->company->id)->first();
|
||||
|
||||
$this->assertNull($cu);
|
||||
$this->assertNull($ct);
|
||||
$this->assertNotNull($user);
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user