Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Team to Concern #139

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions core/app/models/mno_enterprise/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,6 @@

module MnoEnterprise
class Team < BaseResource

attributes :id, :name, :organization_id

#=====================================
# Associations
#=====================================
belongs_to :organization, class_name: 'MnoEnterprise::Organization'
has_many :users, class_name: 'MnoEnterprise::User'
has_many :app_instances, class_name: 'MnoEnterprise::AppInstance'


# Add a user to the team
# TODO: specs
def add_user(user)
self.users.create(id: user.id)
end

# Remove a user from the team
# TODO: specs
def remove_user(user)
self.users.destroy(id: user.id)
end

# Set the app_instance permissions of this team
# Accept a collection of hashes or an array of ids
# TODO: specs
def set_access_to(collection_or_array)
# Empty arrays do not seem to be passed in the request. Force value in this case
list = collection_or_array.empty? ? [""] : collection_or_array
self.put(data: { set_access_to: list })
self.reload
self
end
include MnoEnterprise::Concerns::Models::Team
end
end
67 changes: 67 additions & 0 deletions core/lib/mno_enterprise/concerns/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# == Schema Information
#
# Endpoint:
# - /v1/teams
# - /v1/organizations/:organization_id/teams
#
# id :integer not null, primary key
# name :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# organization_id :integer
#

module MnoEnterprise::Concerns::Models::Team
extend ActiveSupport::Concern

#==================================================================
# Included methods
#==================================================================
# 'included do' causes the included code to be evaluated in the
# context where it is included rather than being executed in the module's context
included do
attributes :id, :name, :organization_id

#=====================================
# Associations
#=====================================
belongs_to :organization, class_name: 'MnoEnterprise::Organization'
has_many :users, class_name: 'MnoEnterprise::User'
has_many :app_instances, class_name: 'MnoEnterprise::AppInstance'
end

#==================================================================
# Class methods
#==================================================================
module ClassMethods
# def some_class_method
# 'some text'
# end
end

#==================================================================
# Instance methods
#==================================================================
# Add a user to the team
# TODO: specs
def add_user(user)
self.users.create(id: user.id)
end

# Remove a user from the team
# TODO: specs
def remove_user(user)
self.users.destroy(id: user.id)
end

# Set the app_instance permissions of this team
# Accept a collection of hashes or an array of ids
# TODO: specs
def set_access_to(collection_or_array)
# Empty arrays do not seem to be passed in the request. Force value in this case
list = collection_or_array.empty? ? [""] : collection_or_array
self.put(data: { set_access_to: list })
self.reload
self
end
end