FEATURE: support group owner, capable of controlling group membership

Group owners are regular users that can add or remove users to a group
The Admin UX allows admins to appoint group owners
The public group UX will display group owners first and unlock UI to
add and remove members

Group owners can only be appointed on non automatic groups
Group owners may not appoint another group owner
This commit is contained in:
Sam Saffron
2015-11-10 00:52:04 +11:00
parent 13bf6a6d7b
commit 6dd4bc7d57
27 changed files with 384 additions and 234 deletions

View File

@@ -7,9 +7,6 @@ class Group < ActiveRecord::Base
has_many :categories, through: :category_groups
has_many :users, through: :group_users
has_many :group_managers, dependent: :destroy
has_many :managers, through: :group_managers
after_save :destroy_deletions
after_save :automatic_group_membership
after_save :update_primary_group
@@ -283,8 +280,8 @@ class Group < ActiveRecord::Base
user.update_columns(primary_group_id: nil) if user.primary_group_id == self.id
end
def appoint_manager(user)
managers << user
def add_owner(user)
self.group_users.create(user_id: user.id, owner: true)
end
protected