Module: MuckGroups::Models::MuckGroup
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/muck-groups/models/group.rb
Instance Method Summary collapse
- #can_edit?(user) ⇒ Boolean
- #can_participate?(user) ⇒ Boolean
- #can_upload?(check_user) ⇒ Boolean
- #content_a ⇒ Object
- #content_p ⇒ Object
- #content_u ⇒ Object
- #create_feed_item(template = nil) ⇒ Object
- #create_forum ⇒ Object
- #default_role ⇒ Object
- #default_role=(val) ⇒ Object
-
#delete! ⇒ Object
actually deleting a group could cause some problems so we cheat and just say we delete it.
- #feed_to ⇒ Object
- #is_content_visible?(user) ⇒ Boolean
- #is_member?(user) ⇒ Boolean
- #is_pending_member?(user) ⇒ Boolean
- #notify_approve ⇒ Object
- #notify_ban ⇒ Object
- #remove_member(user) ⇒ Object
- #remove_pledge(user) ⇒ Object
- #to_xml(options = {}) ⇒ Object
Instance Method Details
#can_edit?(user) ⇒ Boolean
139 140 141 142 |
# File 'lib/muck-groups/models/group.rb', line 139 def can_edit?(user) return false if user.nil? check_creator(user) || members.in_role(:manager).include?(user) end |
#can_participate?(user) ⇒ Boolean
148 149 150 151 |
# File 'lib/muck-groups/models/group.rb', line 148 def can_participate?(user) return false if user == :false user.has_role?('administrator') || !members.find(:all, :conditions => "user_id = #{user.id} AND role != 'banned' AND role != 'observer'").empty? end |
#can_upload?(check_user) ⇒ Boolean
144 145 146 |
# File 'lib/muck-groups/models/group.rb', line 144 def can_upload?(check_user) is_member?(check_user) end |
#content_a ⇒ Object
105 106 107 |
# File 'lib/muck-groups/models/group.rb', line 105 def content_a "#{name} #{description} #{.collect{|t| t.name}.join(' ')}" end |
#content_p ⇒ Object
97 98 99 |
# File 'lib/muck-groups/models/group.rb', line 97 def content_p visibility > MuckGroups::INVISIBLE ? "#{name} #{description} #{.collect{|t| t.name}.join(' ')}" : '' end |
#content_u ⇒ Object
101 102 103 |
# File 'lib/muck-groups/models/group.rb', line 101 def content_u content_p end |
#create_feed_item(template = nil) ⇒ Object
82 83 84 85 |
# File 'lib/muck-groups/models/group.rb', line 82 def create_feed_item template = nil feed_item = FeedItem.create(:item => self, :creator_id => self.creator_id, :template => template) (self.creator.feed_to).each{ |u| u.feed_items << feed_item } end |
#create_forum ⇒ Object
87 88 89 90 91 |
# File 'lib/muck-groups/models/group.rb', line 87 def create_forum @forum = self.forums.build(:name => self.name, :description => I18n.translate('muck.groups.forum_for_group', :forum => self.name)) @forum.save end |
#default_role ⇒ Object
113 114 115 |
# File 'lib/muck-groups/models/group.rb', line 113 def default_role read_attribute(:default_role).to_sym end |
#default_role=(val) ⇒ Object
109 110 111 |
# File 'lib/muck-groups/models/group.rb', line 109 def default_role= val write_attribute(:default_role, val.to_s) end |
#delete! ⇒ Object
actually deleting a group could cause some problems so we cheat and just say we delete it
165 166 167 |
# File 'lib/muck-groups/models/group.rb', line 165 def delete! update_attributes(:visibility => MuckGroups::DELETED) end |
#feed_to ⇒ Object
93 94 95 |
# File 'lib/muck-groups/models/group.rb', line 93 def feed_to [self] + self.members end |
#is_content_visible?(user) ⇒ Boolean
117 118 119 120 121 |
# File 'lib/muck-groups/models/group.rb', line 117 def is_content_visible? user return true if self.visibility > MuckGroups::PRIVATE return false if user == :false || user.nil? user.admin? || self.is_member?(user) end |
#is_member?(user) ⇒ Boolean
129 130 131 132 |
# File 'lib/muck-groups/models/group.rb', line 129 def is_member?(user) return false if user.nil? members.include?(user) end |
#is_pending_member?(user) ⇒ Boolean
134 135 136 137 |
# File 'lib/muck-groups/models/group.rb', line 134 def is_pending_member?(user) return false if user.nil? pledges.include?(user) end |
#notify_approve ⇒ Object
123 124 |
# File 'lib/muck-groups/models/group.rb', line 123 def notify_approve end |
#notify_ban ⇒ Object
126 127 |
# File 'lib/muck-groups/models/group.rb', line 126 def notify_ban end |
#remove_member(user) ⇒ Object
153 154 155 156 |
# File 'lib/muck-groups/models/group.rb', line 153 def remove_member(user) membership = memberships.find_by_user_id(user.id) membership.destroy end |
#remove_pledge(user) ⇒ Object
158 159 160 161 |
# File 'lib/muck-groups/models/group.rb', line 158 def remove_pledge(user) pledge = membership_requests.find_by_user_id(user.id) pledge.destroy if !pledge.nil? end |
#to_xml(options = {}) ⇒ Object
169 170 171 172 173 174 |
# File 'lib/muck-groups/models/group.rb', line 169 def to_xml( = {}) [:only] ||= [] [:only] << :name << :description << :icon << :state << :url_key << :created_at [:only] << :default_role << :visibility << :requires_approval_to_join super end |