Class: Decidim::UserGroup
Overview
A UserGroup is an organization of participants
Constant Summary
Decidim::UserBaseEntity::REGEXP_NAME
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Searchable
searchable_resources, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space
#public_followings
#attached_uploader, #maximum_avatar_size, #maximum_upload_size
Methods included from Followable
#followers
Class Method Details
.export_serializer ⇒ Object
.log_presenter_class_for(_log) ⇒ Object
.ransackable_scopes(_auth = nil) ⇒ Object
148
149
150
|
# File 'app/models/decidim/user_group.rb', line 148
def self.ransackable_scopes(_auth = nil)
[:state_eq]
end
|
.sort_by_document_number_asc ⇒ Object
160
161
162
|
# File 'app/models/decidim/user_group.rb', line 160
def self.sort_by_document_number_asc
order(Arel.sql("extended_data->>'document_number' ASC"))
end
|
.sort_by_document_number_desc ⇒ Object
164
165
166
|
# File 'app/models/decidim/user_group.rb', line 164
def self.sort_by_document_number_desc
order(Arel.sql("extended_data->>'document_number' DESC"))
end
|
.sort_by_phone_asc ⇒ Object
168
169
170
|
# File 'app/models/decidim/user_group.rb', line 168
def self.sort_by_phone_asc
order(Arel.sql("extended_data->>'phone' ASC"))
end
|
.sort_by_phone_desc ⇒ Object
172
173
174
|
# File 'app/models/decidim/user_group.rb', line 172
def self.sort_by_phone_desc
order(Arel.sql("extended_data->>'phone' DESC"))
end
|
.sort_by_state_asc ⇒ Object
176
177
178
|
# File 'app/models/decidim/user_group.rb', line 176
def self.sort_by_state_asc
order(Arel.sql("extended_data->>'rejected_at' ASC, extended_data->>'verified_at' ASC, deleted_at ASC"))
end
|
.sort_by_state_desc ⇒ Object
180
181
182
|
# File 'app/models/decidim/user_group.rb', line 180
def self.sort_by_state_desc
order(Arel.sql("extended_data->>'rejected_at' DESC, extended_data->>'verified_at' DESC, deleted_at DESC"))
end
|
.state_eq(value) ⇒ Object
144
145
146
|
# File 'app/models/decidim/user_group.rb', line 144
def self.state_eq(value)
send(value.to_sym) if %w(all pending rejected verified).include?(value)
end
|
.user_collection(user) ⇒ Object
85
86
87
|
# File 'app/models/decidim/user_group.rb', line 85
def self.user_collection(user)
user.user_groups
end
|
.with_document_number(organization, number) ⇒ Object
46
47
48
49
|
# File 'app/models/decidim/user_group.rb', line 46
def self.with_document_number(organization, number)
where(decidim_organization_id: organization.id)
.where("extended_data->>'document_number' = ?", number)
end
|
Instance Method Details
#accepted_memberships ⇒ Object
sugar for the memberships query
#accepted_users ⇒ Object
easy way to return all the users accepted in this group
127
128
129
|
# File 'app/models/decidim/user_group.rb', line 127
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.
135
136
137
|
# File 'app/models/decidim/user_group.rb', line 135
def accepts_conversation?(_user)
true
end
|
#deleted? ⇒ Boolean
Check if the group has been deleted or not
81
82
83
|
# File 'app/models/decidim/user_group.rb', line 81
def deleted?
deleted_at.present?
end
|
#document_number ⇒ Object
93
94
95
|
# File 'app/models/decidim/user_group.rb', line 93
def document_number
extended_data["document_number"]
end
|
#non_deleted_memberships ⇒ Object
51
52
53
|
# File 'app/models/decidim/user_group.rb', line 51
def non_deleted_memberships
memberships.where(decidim_users: { deleted_at: nil })
end
|
#pending? ⇒ Boolean
Public: Checks if the user group is pending.
76
77
78
|
# File 'app/models/decidim/user_group.rb', line 76
def pending?
verified_at.blank? && rejected_at.blank?
end
|
#phone ⇒ Object
97
98
99
|
# File 'app/models/decidim/user_group.rb', line 97
def phone
extended_data["phone"]
end
|
#presenter ⇒ Object
Returns the presenter for this author, to be used in the views. Required by ActsAsAuthor.
#reject! ⇒ Object
109
110
111
112
113
|
# File 'app/models/decidim/user_group.rb', line 109
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.
71
72
73
|
# File 'app/models/decidim/user_group.rb', line 71
def rejected?
rejected_at.present?
end
|
#rejected_at ⇒ Object
101
102
103
|
# File 'app/models/decidim/user_group.rb', line 101
def rejected_at
extended_data["rejected_at"]
end
|
#unread_messages_count_for(user) ⇒ Object
139
140
141
142
|
# File 'app/models/decidim/user_group.rb', line 139
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.
66
67
68
|
# File 'app/models/decidim/user_group.rb', line 66
def verified?
verified_at.present?
end
|
#verified_at ⇒ Object
105
106
107
|
# File 'app/models/decidim/user_group.rb', line 105
def verified_at
extended_data["verified_at"]
end
|
#verify! ⇒ Object
115
116
117
118
119
|
# File 'app/models/decidim/user_group.rb', line 115
def verify!
extended_data["verified_at"] = Time.current
extended_data["rejected_at"] = nil
save!
end
|