Skip to content

Commit

Permalink
Rename managers to owners
Browse files Browse the repository at this point in the history
  • Loading branch information
NFarrington committed Apr 29, 2018
1 parent 72bc6c7 commit 348acf3
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Platform/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function store(Request $request)

$organization = Organization::create($attributes);
$organization->users()->attach(
$request->user()->id, ['role_id' => OrganizationUser::ROLE_MANAGER]
$request->user()->id, ['role_id' => OrganizationUser::ROLE_OWNER]
);

return redirect()->route('platform.organizations.index')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function store(Request $request, Organization $organization)
'required',
'integer',
Rule::in([
OrganizationUser::ROLE_MANAGER,
OrganizationUser::ROLE_OWNER,
OrganizationUser::ROLE_MEMBER,
]),
],
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Revision[] $dataChanges
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $managers
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $owners
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $members
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Url[] $urls
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $users
Expand Down Expand Up @@ -44,16 +44,16 @@ public function urls()
}

/**
* The organization's managers.
* The organization's owners.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function managers()
public function owners()
{
return $this->belongsToMany(User::class)
->withTimestamps()
->using(OrganizationUser::class)
->wherePivot('role_id', OrganizationUser::ROLE_MANAGER)
->wherePivot('role_id', OrganizationUser::ROLE_OWNER)
->whereNull('organization_user.deleted_at');
}

Expand Down
4 changes: 2 additions & 2 deletions app/Models/OrganizationUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class OrganizationUser extends Pivot
{
/**
* The manager role ID.
* The owner role ID.
*
* @var int
*/
const ROLE_MANAGER = 1;
const ROLE_OWNER = 1;

/**
* The member role ID.
Expand Down
4 changes: 2 additions & 2 deletions app/Policies/OrganizationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function view(User $user, Organization $organization)
*/
public function update(User $user, Organization $organization)
{
return $organization->managers->where('id', $user->id)->isNotEmpty();
return $organization->owners->where('id', $user->id)->isNotEmpty();
}

/**
Expand All @@ -43,6 +43,6 @@ public function update(User $user, Organization $organization)
*/
public function delete(User $user, Organization $organization)
{
return $organization->managers->where('id', $user->id)->isNotEmpty();
return $organization->owners->where('id', $user->id)->isNotEmpty();
}
}
8 changes: 4 additions & 4 deletions resources/views/platform/organizations/_form-edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Managers</label>
@forelse($organization->managers as $manager)
<label class="col-sm-2 col-form-label">Owners</label>
@forelse($organization->owners as $owner)
<div class="{{ !$loop->first ? 'offset-sm-2' : '' }} col-sm-10">
<p class="form-control-plaintext">
{{ $manager->display_info }}
{{ $owner->display_info }}
<delete-resource link-only
route="{{ route('platform.organizations.users.destroy', [$organization, $manager]) }}">
route="{{ route('platform.organizations.users.destroy', [$organization, $owner]) }}">
(Remove)
</delete-resource>
</p>
Expand Down
8 changes: 4 additions & 4 deletions resources/views/platform/organizations/_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<tr>
<th>ID</th>
<th>Name</th>
<th>Managers</th>
<th>Owners</th>
<th>Members</th>
<th>Created</th>
<th></th>
Expand All @@ -16,10 +16,10 @@
<td class="break-all">{{ $organization->name }}</td>
<td>
<ul class="list-unstyled">
@forelse($organization->managers as $manager)
@forelse($organization->owners as $owner)
<li>
<span title="{{ $manager->full_name }} ({{ $manager->id }})" class="text-limit">
{{ $manager->full_name }} ({{ $manager->id }})
<span title="{{ $owner->full_name }} ({{ $owner->id }})" class="text-limit">
{{ $owner->full_name }} ({{ $owner->id }})
</span>
</li>
@empty
Expand Down
8 changes: 4 additions & 4 deletions resources/views/platform/organizations/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<div class="col-sm-10">
<select id="role_id" name="role_id"
class="custom-select{{ $errors->has('role_id') ? ' is-invalid' : '' }}">
<option value="{{ \App\Models\OrganizationUser::ROLE_MANAGER }}"
{{ (old('role_id') ?: \App\Models\OrganizationUser::ROLE_MEMBER) == \App\Models\OrganizationUser::ROLE_MANAGER ? 'selected' : '' }}>
Manager
<option value="{{ \App\Models\OrganizationUser::ROLE_OWNER }}"
{{ (old('role_id') ?: \App\Models\OrganizationUser::ROLE_MEMBER) == \App\Models\OrganizationUser::ROLE_OWNER ? 'selected' : '' }}>
Owner
</option>
<option value="{{ \App\Models\OrganizationUser::ROLE_MEMBER }}"
{{ (old('role_id') ?: \App\Models\OrganizationUser::ROLE_MEMBER) == \App\Models\OrganizationUser::ROLE_MEMBER ? 'selected' : '' }}>
Expand All @@ -55,7 +55,7 @@ class="custom-select{{ $errors->has('role_id') ? ' is-invalid' : '' }}">
</div>
@endif
<small class="form-text text-muted">
Members can manage the organization's URLs. Managers can also manage the organization and
Members can manage the organization's URLs. Owners can also manage the organization and
its members.
</small>
</div>
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/Platform/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function index_page_loads_successfully()
$this->get(route('platform.organizations.index'))
->assertStatus(200);
$organization = create(Organization::class);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_OWNER]);
$this->get(route('platform.organizations.index'))
->assertStatus(200);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ function show_organization_redirects_to_edit()
function edit_page_loads_successfully()
{
$organization = create(Organization::class);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_OWNER]);
$this->get(route('platform.organizations.edit', $organization))
->assertStatus(200);
}
Expand All @@ -74,7 +74,7 @@ function edit_page_loads_successfully()
function organization_can_be_edited()
{
$organization = create(Organization::class);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_OWNER]);
$template = make(Organization::class);

$this->get(route('platform.organizations.edit', $organization));
Expand All @@ -91,7 +91,7 @@ function organization_can_be_edited()
function organization_can_be_deleted()
{
$organization = create(Organization::class);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_OWNER]);

$this->get(route('platform.organizations.edit', $organization));
$this->delete(route('platform.organizations.destroy', $organization))
Expand All @@ -106,7 +106,7 @@ function organization_can_be_deleted()
function organization_with_urls_cannot_be_deleted()
{
$organization = create(Organization::class);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_OWNER]);
factory(Url::class)->states('org')->create(['organization_id' => $organization->id]);

$this->get(route('platform.organizations.edit', $organization));
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/Platform/OrganizationUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp()
function user_can_be_added_to_organization()
{
$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);
$user = create(User::class);

$this->get(route('platform.organizations.edit', $organization));
Expand All @@ -52,7 +52,7 @@ function user_can_be_added_to_organization()
function unregistered_user_can_be_added_to_organization()
{
$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);

$user = make(User::class);
$response = <<<EOT
Expand All @@ -64,7 +64,7 @@ function unregistered_user_can_be_added_to_organization()
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$this->app->instance('guzzle', $client);

$this->get(route('platform.organizations.edit', $organization));
$this->post(route('platform.organizations.users.store', $organization), [
Expand All @@ -86,7 +86,7 @@ function error_retrieving_unregistered_user_causes_validation_exception()
$this->expectException(ValidationException::class);

$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);

$user = make(User::class);
$mock = $this->createMock(Vatsim::class);
Expand All @@ -106,7 +106,7 @@ function perm_error_retrieving_unregistered_user_causes_validation_exception()
$this->expectException(ValidationException::class);

$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);

$user = make(User::class);
$mock = $this->createMock(Vatsim::class);
Expand All @@ -124,7 +124,7 @@ function perm_error_retrieving_unregistered_user_causes_validation_exception()
function user_can_be_removed_from_organization()
{
$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);
$user = create(User::class);
$user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MEMBER]);

Expand All @@ -142,7 +142,7 @@ function user_can_be_removed_from_organization()
function user_cannot_remove_themselves_from_an_organization()
{
$organization = create(Organization::class);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_MANAGER]);
$this->user->organizations()->attach($organization, ['role_id' => OrganizationUser::ROLE_OWNER]);

$this->get(route('platform.organizations.edit', $organization));
$this->delete(route('platform.organizations.users.destroy', [$organization, $this->user]))
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ function organization_has_urls()
}

/** @test */
function organization_has_managers()
function organization_has_owners()
{
$organization = create(Organization::class);
$user = create(User::class);
DB::table($organization->managers()->getTable())->insert([
DB::table($organization->owners()->getTable())->insert([
'organization_id' => $organization->id,
'user_id' => $user->id,
'role_id' => OrganizationUser::ROLE_MANAGER,
'role_id' => OrganizationUser::ROLE_OWNER,
]);
$this->assertEquals($user->id, $organization->managers->first()->id);
$this->assertEquals(1, $organization->managers->count());
$this->assertEquals($user->id, $organization->owners->first()->id);
$this->assertEquals(1, $organization->owners->count());
}

/** @test */
Expand All @@ -59,7 +59,7 @@ function organization_has_users()
DB::table($organization->users()->getTable())->insert([
'organization_id' => $organization->id,
'user_id' => $user->id,
'role_id' => OrganizationUser::ROLE_MANAGER,
'role_id' => OrganizationUser::ROLE_OWNER,
]);
DB::table($organization->users()->getTable())->insert([
'organization_id' => $organization->id,
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function user_has_organizations()
DB::table($organization->users()->getTable())->insert([
'organization_id' => $organization->id,
'user_id' => $user->id,
'role_id' => OrganizationUser::ROLE_MANAGER,
'role_id' => OrganizationUser::ROLE_OWNER,
]);
DB::table($organization->users()->getTable())->insert([
'organization_id' => $organization->id,
Expand Down

0 comments on commit 348acf3

Please sign in to comment.