Class: Decidim::UserGroup

Inherits:
UserBaseEntity show all
Includes:
ActsAsAuthor, DataPortability, Traceable
Defined in:
app/models/decidim/user_group.rb

Overview

A UserGroup is an organization of citizens

Constant Summary

Constants inherited from UserBaseEntity

Decidim::UserBaseEntity::REGEXP_NAME

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UserBaseEntity

#following

Methods included from HasUploadValidations

#maximum_avatar_size, #maximum_upload_size

Methods included from Followable

#followers

Class Method Details

.export_serializerObject



68
69
70
# File 'app/models/decidim/user_group.rb', line 68

def self.export_serializer
  Decidim::DataPortabilitySerializers::DataPortabilityUserGroupSerializer
end

.log_presenter_class_for(_log) ⇒ Object



45
46
47
# File 'app/models/decidim/user_group.rb', line 45

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::UserGroupPresenter
end

.user_collection(user) ⇒ Object



64
65
66
# File 'app/models/decidim/user_group.rb', line 64

def self.user_collection(user)
  user.user_groups
end

.with_document_number(organization, number) ⇒ Object



34
35
36
37
# File 'app/models/decidim/user_group.rb', line 34

def self.with_document_number(organization, number)
  where(decidim_organization_id: organization.id)
    .where("extended_data->>'document_number' = ?", number)
end

Instance Method Details

#accepted_membershipsObject

sugar for the memberships query



101
102
103
# File 'app/models/decidim/user_group.rb', line 101

def accepted_memberships
  UserGroups::AcceptedMemberships.for(self)
end

#accepted_usersObject

easy way to return all the users accepted in this group



106
107
108
# File 'app/models/decidim/user_group.rb', line 106

def accepted_users
  accepted_memberships.map(&:user)
end

#accepts_conversation?(_user) ⇒ Boolean

Currently, groups always accept conversations from anyone. This may change in the future in case the desired behaviour is to check if all (or any) of the administrators accepts conversations or there’s simply and option for this in the group preferences.

Returns:

  • (Boolean)


114
115
116
# File 'app/models/decidim/user_group.rb', line 114

def accepts_conversation?(_user)
  true
end

#document_numberObject



72
73
74
# File 'app/models/decidim/user_group.rb', line 72

def document_number
  extended_data["document_number"]
end

#pending?Boolean

Public: Checks if the user group is pending.

Returns:

  • (Boolean)


60
61
62
# File 'app/models/decidim/user_group.rb', line 60

def pending?
  verified_at.blank? && rejected_at.blank?
end

#phoneObject



76
77
78
# File 'app/models/decidim/user_group.rb', line 76

def phone
  extended_data["phone"]
end

#presenterObject

Returns the presenter for this author, to be used in the views. Required by ActsAsAuthor.



41
42
43
# File 'app/models/decidim/user_group.rb', line 41

def presenter
  Decidim::UserGroupPresenter.new(self)
end

#reject!Object



88
89
90
91
92
# File 'app/models/decidim/user_group.rb', line 88

def reject!
  extended_data["verified_at"] = nil
  extended_data["rejected_at"] = Time.current
  save!
end

#rejected?Boolean

Public: Checks if the user group is rejected.

Returns:

  • (Boolean)


55
56
57
# File 'app/models/decidim/user_group.rb', line 55

def rejected?
  rejected_at.present?
end

#rejected_atObject



80
81
82
# File 'app/models/decidim/user_group.rb', line 80

def rejected_at
  extended_data["rejected_at"]
end

#unread_messages_count_for(user) ⇒ Object



118
119
120
121
# File 'app/models/decidim/user_group.rb', line 118

def unread_messages_count_for(user)
  @unread_messages_count_for ||= {}
  @unread_messages_count_for[user.id] ||= Decidim::Messaging::Conversation.user_collection(self).unread_messages_by(user).count
end

#verified?Boolean

Public: Checks if the user group is verified.

Returns:

  • (Boolean)


50
51
52
# File 'app/models/decidim/user_group.rb', line 50

def verified?
  verified_at.present?
end

#verified_atObject



84
85
86
# File 'app/models/decidim/user_group.rb', line 84

def verified_at
  extended_data["verified_at"]
end

#verify!Object



94
95
96
97
98
# File 'app/models/decidim/user_group.rb', line 94

def verify!
  extended_data["verified_at"] = Time.current
  extended_data["rejected_at"] = nil
  save!
end