Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organization leaders can create chapters for their org and are listed on the organization index at /organizations.
- Loading branch information
1 parent
f07a099
commit 94be27b
Showing
14 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
class Organization < ActiveRecord::Base | ||
has_many :chapters, dependent: :destroy | ||
has_many :leaders, through: :organization_leaderships, source: :user | ||
has_many :organization_leaderships, dependent: :destroy | ||
|
||
def has_leader?(user) | ||
return false unless user | ||
|
||
return true if user.admin? | ||
|
||
leaders.include?(user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class OrganizationLeadership < ActiveRecord::Base | ||
belongs_to :organization | ||
belongs_to :user | ||
|
||
validates :user, uniqueness: { scope: :organization } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
class ChapterPolicy < ApplicationPolicy | ||
def new? | ||
user.admin? | ||
user.admin? || user.organization_leaderships.present? | ||
end | ||
|
||
def edit? | ||
record.has_leader?(user) | ||
record.editable_by?(user) | ||
end | ||
|
||
def update? | ||
record.has_leader?(user) | ||
record.editable_by?(user) | ||
end | ||
|
||
def create? | ||
user.admin? | ||
user.admin? || record.editable_by?(user) | ||
end | ||
|
||
def destroy? | ||
user.admin? | ||
end | ||
|
||
def modify_leadership? | ||
record.has_leader?(user) | ||
record.editable_by?(user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class OrganizationPolicy < ApplicationPolicy | ||
class Scope < Scope | ||
def resolve | ||
if user.admin? | ||
scope.all | ||
else | ||
scope.where(id: user.organization_leaderships.map(&:organization_id)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateOrganizationLeaderships < ActiveRecord::Migration | ||
def change | ||
create_table :organization_leaderships do |t| | ||
t.references :user, index: true, foreign_key: true | ||
t.references :organization, index: true, foreign_key: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters