1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Fixes for missing fields for company transformer (#3406)

This commit is contained in:
David Bomba 2020-03-01 21:45:23 +11:00 committed by GitHub
parent 0ff14c97fd
commit 6e51b225b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 4 deletions

View File

@ -438,9 +438,23 @@ class UserController extends BaseController
*/
public function destroy(DestroyUserRequest $request, User $user)
{
$user->delete();
/* If the user passes the company user we archive the company user */
if(array_key_exists('company_user', $request->all()))
{
$this->forced_includes = 'company_users';
$company = auth()->user()->company();
$cu = CompanyUser::whereUserId($user->id)
->whereCompanyId($company->id)
->first();
$cu->delete();
}
else
$user->delete();
return response()->json([], 200);
return $this->itemResponse($user->fresh());
}
/**

View File

@ -178,7 +178,7 @@ class User extends Authenticatable implements MustVerifyEmail
public function company_users()
{
return $this->hasMany(CompanyUser::class);
return $this->hasMany(CompanyUser::class)->withTrashed();
}
public function company_user()
@ -187,7 +187,7 @@ class User extends Authenticatable implements MustVerifyEmail
$this->id = auth()->user()->id;
}
return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id')->where('company_user.user_id', $this->id);
return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id')->where('company_user.user_id', $this->id)->withTrashed();
}
/**

View File

@ -109,6 +109,8 @@ class CompanyTransformer extends EntityTransformer
'updated_at' => (int)$company->updated_at,
'archived_at' => (int)$company->deleted_at,
'created_at' =>(int)$company->created_at,
'slack_webhook_url' => (string)$company->slack_webhook_url,
'google_analytics_url' => (string)$company->google_analytics_url,
];
}

View File

@ -53,6 +53,7 @@ class CompanyUserTransformer extends EntityTransformer
// 'user_id' => $company_user->user_id,
// 'company_id' => $company_user->company_id,
'permissions' => $company_user->permissions ?: '',
'notifications' => $company_user->notifications ?: '',
'settings' => $company_user->settings,
'is_owner' => (bool) $company_user->is_owner,
'is_admin' => (bool) $company_user->is_admin,