Class: Decidim::UserGroup

Inherits:
UserBaseEntity show all
Includes:
ActsAsAuthor, DataPortability, Searchable, Traceable, UserReportable
Defined in:
decidim-core/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 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

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


89
90
91
# File 'decidim-core/app/models/decidim/user_group.rb', line 89

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

.log_presenter_class_for(_log) ⇒ Object


61
62
63
# File 'decidim-core/app/models/decidim/user_group.rb', line 61

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

.user_collection(user) ⇒ Object


85
86
87
# File 'decidim-core/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 'decidim-core/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_membershipsObject

sugar for the memberships query


122
123
124
# File 'decidim-core/app/models/decidim/user_group.rb', line 122

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

#accepted_usersObject

easy way to return all the users accepted in this group


127
128
129
# File 'decidim-core/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.

Returns:

  • (Boolean)

135
136
137
# File 'decidim-core/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

Returns:

  • (Boolean)

81
82
83
# File 'decidim-core/app/models/decidim/user_group.rb', line 81

def deleted?
  deleted_at.present?
end

#document_numberObject


93
94
95
# File 'decidim-core/app/models/decidim/user_group.rb', line 93

def document_number
  extended_data["document_number"]
end

#non_deleted_membershipsObject


51
52
53
# File 'decidim-core/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.

Returns:

  • (Boolean)

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

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

#phoneObject


97
98
99
# File 'decidim-core/app/models/decidim/user_group.rb', line 97

def phone
  extended_data["phone"]
end

#presenterObject

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


57
58
59
# File 'decidim-core/app/models/decidim/user_group.rb', line 57

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

#reject!Object


109
110
111
112
113
# File 'decidim-core/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.

Returns:

  • (Boolean)

71
72
73
# File 'decidim-core/app/models/decidim/user_group.rb', line 71

def rejected?
  rejected_at.present?
end

#rejected_atObject


101
102
103
# File 'decidim-core/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 'decidim-core/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.

Returns:

  • (Boolean)

66
67
68
# File 'decidim-core/app/models/decidim/user_group.rb', line 66

def verified?
  verified_at.present?
end

#verified_atObject


105
106
107
# File 'decidim-core/app/models/decidim/user_group.rb', line 105

def verified_at
  extended_data["verified_at"]
end

#verify!Object


115
116
117
118
119
# File 'decidim-core/app/models/decidim/user_group.rb', line 115

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