Skip to content

Commit

Permalink
refact : app owner
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jun 16, 2023
1 parent 9a5f89c commit 60a1947
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion graphql/schemas/Ecosystem/country.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type Country {
id: Int!
name: String!
code: String!
flag: String!
flag: String
states: [States]
}
type States {
Expand Down
7 changes: 7 additions & 0 deletions src/Kanvas/Apps/Models/Apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Auth;
use Kanvas\Companies\Models\Companies;
Expand All @@ -31,6 +32,7 @@
* @property string $description
* @property string $domain
* @property int $is_actived
* @property int $users_id
* @property int $ecosystem_auth
* @property int $default_apps_plan_id
* @property int $payments_active
Expand Down Expand Up @@ -87,6 +89,11 @@ public function keys(): HasMany
return $this->hasMany(AppKey::class, 'apps_id');
}

public function user() : BelongsTo
{
return $this->belongsTo(Users::class, 'users_id');
}

/**
* Settings relationship.
*/
Expand Down
7 changes: 6 additions & 1 deletion src/Kanvas/Users/Models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Kanvas\Apps\Enums\DefaultRoles;
use Kanvas\Apps\Models\AppKey;
use Kanvas\Apps\Models\Apps;
use Kanvas\Auth\Contracts\Authenticatable as ContractsAuthenticatable;
use Kanvas\Auth\Traits\HasApiTokens;
Expand Down Expand Up @@ -464,10 +465,14 @@ public function updateEmail(string $email): bool

/**
* Is the creator of the current app.
* @psalm-suppress MixedReturnStatement
*/
public function isAppOwner(): bool
{
return $this->getId() === app(Apps::class)->users_id;
return (bool) AppKey::where('users_id', $this->getId())
->where('apps_id', app(Apps::class)->getId())
->notDeleted()
->exists();
}

/**
Expand Down

0 comments on commit 60a1947

Please sign in to comment.