decidim-core 0.14.4 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/app/assets/images/decidim/cc-badge.png +0 -0
- data/app/assets/images/decidim/gamification/badges/continuity.svg +73 -0
- data/app/assets/images/decidim/gamification/badges/followers.svg +115 -0
- data/app/assets/images/decidim/icons.svg +1 -0
- data/app/assets/javascripts/decidim/vizzs/areachart.js.es6 +186 -208
- data/app/assets/javascripts/decidim/vizzs/linechart.js.es6 +263 -0
- data/app/assets/javascripts/decidim/vizzs/metrics.js.es6 +36 -26
- data/app/assets/javascripts/decidim/vizzs/orgchart.js.es6 +3 -2
- data/app/assets/javascripts/decidim/vizzs/rowchart.js.es6 +324 -0
- data/app/assets/stylesheets/decidim/_decidim.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_cards.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_conference-diploma.scss +75 -0
- data/app/assets/stylesheets/decidim/modules/_conference-media.scss +44 -0
- data/app/assets/stylesheets/decidim/modules/_conference-programme.scss +5 -1
- data/app/assets/stylesheets/decidim/modules/_conference-registration.scss +34 -0
- data/app/assets/stylesheets/decidim/modules/_list-request.scss +16 -0
- data/app/assets/stylesheets/decidim/modules/_modules.scss +4 -4
- data/app/assets/stylesheets/decidim/modules/_process-phase.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_reveal.scss +6 -1
- data/app/assets/stylesheets/decidim/utils/_helpers.scss +1 -1
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_areachart.scss +8 -11
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_chart-tooltip.scss +0 -0
- data/app/assets/stylesheets/decidim/vizzs/_linechart.scss +115 -0
- data/app/assets/stylesheets/decidim/vizzs/_rowchart.scss +77 -0
- data/app/cells/decidim/activities/show.erb +3 -0
- data/app/cells/decidim/activities_cell.rb +38 -0
- data/app/cells/decidim/activity/show.erb +21 -0
- data/app/cells/decidim/activity_cell.rb +85 -0
- data/app/cells/decidim/address/details.erb +7 -0
- data/app/cells/decidim/address/show.erb +14 -0
- data/app/cells/decidim/address_cell.rb +19 -0
- data/app/cells/decidim/author/contact.erb +1 -1
- data/app/cells/decidim/author_cell.rb +1 -0
- data/app/cells/decidim/badge/show.erb +2 -2
- data/app/cells/decidim/badge/small.erb +5 -0
- data/app/cells/decidim/badge_cell.rb +36 -14
- data/app/cells/decidim/badges/show.erb +6 -3
- data/app/cells/decidim/badges_cell.rb +4 -4
- data/app/cells/decidim/coauthorships_cell.rb +8 -2
- data/app/cells/decidim/collapsible_authors/show.erb +9 -7
- data/app/cells/decidim/content_blocks/html/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_cell.rb +11 -0
- data/app/cells/decidim/content_blocks/html_settings_form/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_settings_form_cell.rb +17 -0
- data/app/cells/decidim/content_blocks/last_activity/show.erb +17 -0
- data/app/cells/decidim/content_blocks/last_activity_cell.rb +60 -0
- data/app/cells/decidim/content_blocks/metrics/show.erb +13 -0
- data/app/cells/decidim/content_blocks/metrics_cell.rb +18 -0
- data/app/cells/decidim/content_blocks/stats/show.erb +2 -1
- data/app/cells/decidim/groups/show.erb +10 -0
- data/app/cells/decidim/groups_cell.rb +19 -0
- data/app/cells/decidim/members/show.erb +9 -0
- data/app/cells/decidim/members_cell.rb +32 -0
- data/app/cells/decidim/profile/show.erb +3 -11
- data/app/cells/decidim/profile/user_group_tabs.erb +5 -0
- data/app/cells/decidim/profile/user_tabs.erb +12 -0
- data/app/cells/decidim/profile_cell.rb +7 -2
- data/app/cells/decidim/profile_sidebar/show.erb +108 -23
- data/app/cells/decidim/profile_sidebar_cell.rb +36 -2
- data/app/cells/decidim/user_group_admin_membership_profile/footer.erb +29 -0
- data/app/cells/decidim/user_group_admin_membership_profile_cell.rb +14 -0
- data/app/cells/decidim/user_group_membership_profile/tags.erb +1 -0
- data/app/cells/decidim/user_group_membership_profile_cell.rb +8 -0
- data/app/cells/decidim/user_group_pending_invitations_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_invitations_list_cell.rb +26 -0
- data/app/cells/decidim/user_group_pending_requests_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_requests_list_cell.rb +26 -0
- data/app/cells/decidim/user_profile/header.erb +1 -1
- data/app/cells/decidim/user_profile_cell.rb +15 -9
- data/app/commands/decidim/accept_group_invitation.rb +43 -0
- data/app/commands/decidim/accept_user_group_join_request.rb +53 -0
- data/app/commands/decidim/create_follow.rb +6 -0
- data/app/commands/decidim/create_registration.rb +13 -23
- data/app/commands/decidim/create_user_group.rb +57 -0
- data/app/commands/decidim/delete_follow.rb +7 -0
- data/app/commands/decidim/demote_membership.rb +57 -0
- data/app/commands/decidim/destroy_account.rb +6 -0
- data/app/commands/decidim/invite_user.rb +1 -3
- data/app/commands/decidim/invite_user_to_group.rb +62 -0
- data/app/commands/decidim/join_user_group.rb +63 -0
- data/app/commands/decidim/leave_user_group.rb +41 -0
- data/app/commands/decidim/promote_membership.rb +55 -0
- data/app/commands/decidim/reject_group_invitation.rb +42 -0
- data/app/commands/decidim/reject_user_group_join_request.rb +53 -0
- data/app/commands/decidim/remove_user_from_group.rb +53 -0
- data/app/commands/decidim/update_user_group.rb +53 -0
- data/app/controllers/concerns/decidim/locale_switcher.rb +3 -3
- data/app/controllers/concerns/decidim/paginable.rb +1 -0
- data/app/controllers/decidim/application_controller.rb +7 -0
- data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -1
- data/app/controllers/decidim/devise/sessions_controller.rb +1 -1
- data/app/controllers/decidim/gamification/badges_controller.rb +11 -0
- data/app/controllers/decidim/group_admins_controller.rb +41 -0
- data/app/controllers/decidim/group_invites_controller.rb +74 -0
- data/app/controllers/decidim/group_members_controller.rb +59 -0
- data/app/controllers/decidim/groups_controller.rb +85 -0
- data/app/controllers/decidim/last_activities_controller.rb +46 -0
- data/app/controllers/decidim/pages_controller.rb +9 -1
- data/app/controllers/decidim/profiles_controller.rb +35 -5
- data/app/controllers/decidim/user_group_join_requests_controller.rb +69 -0
- data/app/events/decidim/demoted_membership_event.rb +28 -0
- data/app/events/decidim/invited_to_group_event.rb +33 -0
- data/app/events/decidim/join_request_accepted_event.rb +28 -0
- data/app/events/decidim/join_request_created_event.rb +28 -0
- data/app/events/decidim/join_request_rejected_event.rb +28 -0
- data/app/events/decidim/promoted_to_admin_event.rb +28 -0
- data/app/events/decidim/removed_from_group_event.rb +28 -0
- data/app/forms/decidim/account_form.rb +1 -1
- data/app/forms/decidim/invite_user_to_group_form.rb +29 -0
- data/app/forms/decidim/notifications_settings_form.rb +4 -0
- data/app/forms/decidim/registration_form.rb +0 -27
- data/app/forms/decidim/user_group_form.rb +81 -0
- data/app/helpers/decidim/component_path_helper.rb +10 -0
- data/app/helpers/decidim/filters_helper.rb +3 -2
- data/app/helpers/decidim/icon_helper.rb +3 -1
- data/app/helpers/decidim/map_helper.rb +1 -1
- data/app/jobs/decidim/metric_job.rb +14 -0
- data/app/mailers/decidim/newsletter_mailer.rb +2 -0
- data/app/mailers/decidim/notification_mailer.rb +1 -1
- data/app/models/decidim/action_log.rb +66 -0
- data/app/models/decidim/coauthorship.rb +9 -0
- data/app/models/decidim/component.rb +5 -0
- data/app/models/decidim/continuity_badge_status.rb +9 -0
- data/app/models/decidim/gamification/badge_score.rb +1 -1
- data/app/models/decidim/messaging/message.rb +1 -0
- data/app/models/decidim/metric.rb +13 -0
- data/app/models/decidim/participatory_space_private_user.rb +4 -0
- data/app/models/decidim/user.rb +14 -38
- data/app/models/decidim/user_base_entity.rb +52 -0
- data/app/models/decidim/user_group.rb +48 -9
- data/app/models/decidim/user_group_membership.rb +8 -0
- data/app/permissions/decidim/permissions.rb +21 -0
- data/app/presenters/decidim/admin_log/organization_presenter.rb +0 -2
- data/app/presenters/decidim/admin_log/participatory_space_private_user_presenter.rb +38 -0
- data/app/presenters/decidim/metric_charts_presenter.rb +53 -0
- data/app/presenters/decidim/metric_object_presenter.rb +28 -0
- data/app/presenters/decidim/user_group_presenter.rb +16 -8
- data/app/presenters/decidim/user_presenter.rb +14 -0
- data/app/queries/decidim/metric_manage.rb +59 -0
- data/app/queries/decidim/metrics/users_metric_manage.rb +26 -0
- data/app/queries/decidim/user_groups/accepted_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/accepted_user_groups.rb +38 -0
- data/app/queries/decidim/user_groups/accepted_users.rb +36 -0
- data/app/queries/decidim/user_groups/admin_memberships.rb +37 -0
- data/app/queries/decidim/user_groups/invited_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/manageable_user_groups.rb +39 -0
- data/app/queries/decidim/user_groups/member_memberships.rb +37 -0
- data/app/resolvers/decidim/core/metric_resolver.rb +38 -0
- data/app/services/decidim/action_logger.rb +4 -2
- data/app/services/decidim/activity_search.rb +76 -0
- data/app/services/decidim/continuity_badge_tracker.rb +64 -0
- data/app/services/decidim/resource_search.rb +0 -1
- data/app/types/decidim/core/metric_history_type.rb +17 -0
- data/app/types/decidim/core/metric_type.rb +14 -0
- data/app/types/decidim/core/session_type.rb +1 -1
- data/app/types/decidim/core/user_group_type.rb +2 -2
- data/app/views/decidim/authorization_modals/show.html.erb +40 -27
- data/app/views/decidim/devise/registrations/new.html.erb +0 -19
- data/app/views/decidim/gamification/badges/index.html.erb +42 -0
- data/app/views/decidim/group_admins/index.html.erb +18 -0
- data/app/views/decidim/group_invites/index.html.erb +27 -0
- data/app/views/decidim/group_members/index.html.erb +19 -0
- data/app/views/decidim/groups/_form.html.erb +23 -0
- data/app/views/decidim/groups/edit.html.erb +26 -0
- data/app/views/decidim/groups/new.html.erb +26 -0
- data/app/views/decidim/last_activities/_activities.html.erb +13 -0
- data/app/views/decidim/last_activities/index.html.erb +18 -0
- data/app/views/decidim/last_activities/index.js.erb +6 -0
- data/app/views/decidim/profiles/show.html.erb +1 -1
- data/app/views/layouts/decidim/_user_menu.html.erb +0 -1
- data/app/views/layouts/decidim/_wrapper.html.erb +1 -1
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/foundation_rails_helper.rb +1 -0
- data/config/locales/ca.yml +325 -32
- data/config/locales/de.yml +325 -32
- data/config/locales/en.yml +325 -32
- data/config/locales/es-PY.yml +325 -32
- data/config/locales/es.yml +325 -32
- data/config/locales/eu.yml +325 -32
- data/config/locales/fi.yml +330 -37
- data/config/locales/fr.yml +325 -32
- data/config/locales/gl.yml +325 -32
- data/config/locales/hu.yml +327 -34
- data/config/locales/it.yml +325 -32
- data/config/locales/nl.yml +325 -32
- data/config/locales/pl.yml +329 -32
- data/config/locales/pt-BR.yml +326 -33
- data/config/locales/pt.yml +325 -32
- data/config/locales/ru.yml +4 -33
- data/config/locales/sv.yml +346 -53
- data/config/locales/uk.yml +4 -33
- data/config/routes.rb +27 -1
- data/db/migrate/20170128112958_change_user_groups_verified_to_timestamp.rb +11 -0
- data/db/migrate/20180705134647_create_decidim_metrics.rb +16 -0
- data/db/migrate/20180730071851_add_core_content_blocks.rb +3 -3
- data/db/migrate/20180810092428_move_organization_fields_to_hero_content_block.rb +4 -2
- data/db/migrate/20180918072506_add_visibility_to_action_logs.rb +8 -0
- data/db/migrate/20181001124950_move_users_groups_to_users_table.rb +84 -0
- data/db/migrate/20181008102144_add_badge_switch_to_organizations.rb +8 -0
- data/db/migrate/20181010044613_create_decidim_continuity_badge_statuses.rb +11 -0
- data/db/migrate/20181011080252_add_roles_to_memberships.rb +24 -0
- data/db/migrate/20181016091601_make_authors_polymorphic.rb +31 -0
- data/db/migrate/20181029112820_fix_user_follows.rb +18 -0
- data/db/migrate/20181030090144_destroy_deleted_users_follows.rb +16 -0
- data/db/seeds.rb +18 -4
- data/lib/decidim/attributes.rb +1 -0
- data/lib/decidim/attributes/localized_date.rb +16 -0
- data/lib/decidim/attributes/time_with_zone.rb +3 -1
- data/lib/decidim/authorable.rb +5 -4
- data/lib/decidim/authorization_form_builder.rb +2 -2
- data/lib/decidim/coauthorable.rb +68 -18
- data/lib/decidim/content_block_manifest.rb +7 -0
- data/lib/decidim/content_processor.rb +17 -7
- data/lib/decidim/core.rb +12 -0
- data/lib/decidim/core/engine.rb +54 -6
- data/lib/decidim/core/test/factories.rb +63 -17
- data/lib/decidim/core/test/shared_examples/coauthorable.rb +27 -9
- data/lib/decidim/core/test/shared_examples/coauthorable_interface_examples.rb +2 -2
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/data_portability.rb +3 -1
- data/lib/decidim/data_portability_file_reader.rb +1 -1
- data/lib/decidim/events/author_event.rb +4 -1
- data/lib/decidim/events/coauthor_event.rb +4 -1
- data/lib/decidim/faker/localized.rb +5 -4
- data/lib/decidim/form_builder.rb +18 -17
- data/lib/decidim/gamification.rb +8 -2
- data/lib/decidim/gamification/badge.rb +34 -0
- data/lib/decidim/gamification/badge_scorer.rb +29 -14
- data/lib/decidim/gamification/badge_status.rb +2 -0
- data/lib/decidim/hashtaggable.rb +1 -1
- data/lib/decidim/manifest_registry.rb +5 -3
- data/lib/decidim/metric_manifest.rb +20 -0
- data/lib/decidim/metric_registry.rb +71 -0
- data/lib/decidim/participable.rb +1 -1
- data/lib/decidim/participatory_space_resourceable.rb +0 -1
- data/lib/decidim/query_extensions.rb +19 -0
- data/lib/decidim/resourceable.rb +1 -0
- data/lib/decidim/searchable.rb +2 -1
- data/lib/tasks/decidim_metrics_tasks.rake +41 -0
- data/lib/tasks/decidim_tasks.rake +1 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ca.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.es.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.gl.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.pt.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ru.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.uk.js +1 -2
- data/vendor/assets/javascripts/form_datepicker.js.es6 +1 -11
- metadata +144 -23
- data/app/cells/decidim/invitations_toggle/content.erb +0 -1
- data/app/cells/decidim/invitations_toggle/label.erb +0 -1
- data/app/cells/decidim/invitations_toggle_cell.rb +0 -27
- data/app/cells/decidim/toggle/show.erb +0 -8
- data/app/cells/decidim/toggle_cell.rb +0 -42
- data/app/commands/decidim/invite_friends.rb +0 -48
- data/app/controllers/decidim/invitations_controller.rb +0 -32
- data/app/forms/decidim/invitations_form.rb +0 -37
- data/app/views/decidim/invitations/index.html.erb +0 -48
- data/app/views/devise/mailer/invite_friend.html.erb +0 -27
- data/app/views/devise/mailer/invite_friend.text.erb +0 -19
- data/lib/decidim/rectify_ext.rb +0 -32
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This class serves as a base class for `Decidim::User` and `Decidim::UserGroup`
|
5
|
+
# so that we can set some shared logic.
|
6
|
+
# This class is not supposed to be used directly.
|
7
|
+
class UserBaseEntity < ApplicationRecord
|
8
|
+
self.table_name = "decidim_users"
|
9
|
+
|
10
|
+
include Nicknamizable
|
11
|
+
include Resourceable
|
12
|
+
include Decidim::Followable
|
13
|
+
include Decidim::Loggable
|
14
|
+
|
15
|
+
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
|
16
|
+
has_many :notifications, foreign_key: "decidim_user_id", class_name: "Decidim::Notification", dependent: :destroy
|
17
|
+
has_many :following_follows, foreign_key: "decidim_user_id", class_name: "Decidim::Follow", dependent: :destroy
|
18
|
+
|
19
|
+
validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
|
20
|
+
mount_uploader :avatar, Decidim::AvatarUploader
|
21
|
+
|
22
|
+
validates :name, :nickname, format: { with: /\A(?!.*[<>?%&\^*#@\(\)\[\]\=\+\:\;\"\{\}\\\|])/ }
|
23
|
+
|
24
|
+
# Public: Returns a collection with all the entities this user is following.
|
25
|
+
#
|
26
|
+
# This can't be done as with a `has_many :following, through: :following_follows`
|
27
|
+
# since it's a polymorphic relation and Rails doesn't know how to load it. With
|
28
|
+
# this implementation we only query the database once for each kind of following.
|
29
|
+
#
|
30
|
+
# Returns an Array of Decidim::Followable
|
31
|
+
def following
|
32
|
+
@following ||= begin
|
33
|
+
followings = following_follows.pluck(:decidim_followable_type, :decidim_followable_id)
|
34
|
+
grouped_followings = followings.each_with_object({}) do |(type, following_id), all|
|
35
|
+
all[type] ||= []
|
36
|
+
all[type] << following_id
|
37
|
+
all
|
38
|
+
end
|
39
|
+
|
40
|
+
grouped_followings.flat_map do |type, ids|
|
41
|
+
type.constantize.where(id: ids)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def following_users
|
47
|
+
@following_users ||= following.select do |f|
|
48
|
+
f.is_a?(Decidim::User) || f.is_a?(Decidim::UserGroup)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -2,27 +2,28 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
# A UserGroup is an organization of citizens
|
5
|
-
class UserGroup <
|
5
|
+
class UserGroup < UserBaseEntity
|
6
6
|
include Decidim::Traceable
|
7
|
-
include Decidim::Loggable
|
8
7
|
include Decidim::DataPortability
|
9
8
|
|
10
|
-
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
|
11
|
-
|
12
9
|
has_many :memberships, class_name: "Decidim::UserGroupMembership", foreign_key: :decidim_user_group_id, dependent: :destroy
|
13
10
|
has_many :users, through: :memberships, class_name: "Decidim::User", foreign_key: :decidim_user_id
|
14
11
|
|
15
12
|
validates :name, presence: true, uniqueness: { scope: :decidim_organization_id }
|
16
|
-
validates :document_number, presence: true
|
13
|
+
validates :document_number, presence: true
|
17
14
|
validates :phone, presence: true
|
18
|
-
validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
|
19
15
|
|
20
16
|
validate :correct_state
|
17
|
+
validate :unique_document_number
|
21
18
|
|
22
|
-
|
19
|
+
scope :verified, -> { where.not("extended_data->>'verified_at' IS ?", nil) }
|
20
|
+
scope :rejected, -> { where.not("extended_data->>'rejected_at' IS ?", nil) }
|
21
|
+
scope :pending, -> { where("extended_data->>'rejected_at' IS ? AND extended_data->>'verified_at' IS ?", nil, nil) }
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
def self.with_document_number(organization, number)
|
24
|
+
where(decidim_organization_id: organization.id)
|
25
|
+
.where("extended_data->>'document_number' = ?", number)
|
26
|
+
end
|
26
27
|
|
27
28
|
def self.log_presenter_class_for(_log)
|
28
29
|
Decidim::AdminLog::UserGroupPresenter
|
@@ -51,11 +52,49 @@ module Decidim
|
|
51
52
|
Decidim::DataPortabilitySerializers::DataPortabilityUserGroupSerializer
|
52
53
|
end
|
53
54
|
|
55
|
+
def document_number
|
56
|
+
extended_data["document_number"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def phone
|
60
|
+
extended_data["phone"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def rejected_at
|
64
|
+
extended_data["rejected_at"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def verified_at
|
68
|
+
extended_data["verified_at"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def reject!
|
72
|
+
extended_data["verified_at"] = nil
|
73
|
+
extended_data["rejected_at"] = Time.current
|
74
|
+
save!
|
75
|
+
end
|
76
|
+
|
77
|
+
def verify!
|
78
|
+
extended_data["verified_at"] = Time.current
|
79
|
+
extended_data["rejected_at"] = nil
|
80
|
+
save!
|
81
|
+
end
|
82
|
+
|
54
83
|
private
|
55
84
|
|
56
85
|
# Private: Checks if the state user group is correct.
|
57
86
|
def correct_state
|
58
87
|
errors.add(:base, :invalid) if verified? && rejected?
|
59
88
|
end
|
89
|
+
|
90
|
+
def unique_document_number
|
91
|
+
is_repeated = self
|
92
|
+
.class
|
93
|
+
.with_document_number(organization, document_number)
|
94
|
+
.where.not(id: id)
|
95
|
+
.any?
|
96
|
+
|
97
|
+
errors.add(:document_number, :taken) if is_repeated
|
98
|
+
end
|
60
99
|
end
|
61
100
|
end
|
@@ -5,5 +5,13 @@ module Decidim
|
|
5
5
|
class UserGroupMembership < ApplicationRecord
|
6
6
|
belongs_to :user, class_name: "Decidim::User", foreign_key: :decidim_user_id
|
7
7
|
belongs_to :user_group, class_name: "Decidim::UserGroup", foreign_key: :decidim_user_group_id
|
8
|
+
|
9
|
+
ROLES = %w(creator admin member requested invited).freeze
|
10
|
+
validates :role, inclusion: { in: ROLES }
|
11
|
+
validates :role, uniqueness: { scope: [:role, :decidim_user_group_id] }, if: :creator?
|
12
|
+
|
13
|
+
def creator?
|
14
|
+
role.to_s == "creator"
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
@@ -18,6 +18,8 @@ module Decidim
|
|
18
18
|
follow_action?
|
19
19
|
notification_action?
|
20
20
|
conversation_action?
|
21
|
+
user_group_action?
|
22
|
+
user_group_invitations_action?
|
21
23
|
|
22
24
|
permission_action
|
23
25
|
end
|
@@ -91,6 +93,25 @@ module Decidim
|
|
91
93
|
toggle_allow(conversation.participants.include?(user))
|
92
94
|
end
|
93
95
|
|
96
|
+
def user_group_action?
|
97
|
+
return unless permission_action.subject == :user_group
|
98
|
+
return allow! if [:join, :create].include?(permission_action.action)
|
99
|
+
|
100
|
+
user_group = context.fetch(:user_group)
|
101
|
+
|
102
|
+
if permission_action.action == :leave
|
103
|
+
user_can_leave_group = Decidim::UserGroupMembership.where(user: user, user_group: user_group).where.not(role: :creator).any?
|
104
|
+
return toggle_allow(user_can_leave_group)
|
105
|
+
end
|
106
|
+
|
107
|
+
user_manages_group = Decidim::UserGroups::ManageableUserGroups.for(user).include?(user_group)
|
108
|
+
toggle_allow(user_manages_group) if permission_action.action == :manage
|
109
|
+
end
|
110
|
+
|
111
|
+
def user_group_invitations_action?
|
112
|
+
allow! if permission_action.subject == :user_group_invitations
|
113
|
+
end
|
114
|
+
|
94
115
|
def user_can_admin_component?
|
95
116
|
new_permission_action = Decidim::PermissionAction.new(
|
96
117
|
action: permission_action.action,
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module AdminLog
|
5
|
+
# This class holds the logic to present a `Decidim::ParticipatorySpacePrivateUserPresenter`
|
6
|
+
# for the `AdminLog` log.
|
7
|
+
#
|
8
|
+
# Usage should be automatic and you shouldn't need to call this class
|
9
|
+
# directly, but here's an example:
|
10
|
+
#
|
11
|
+
# action_log = Decidim::ActionLog.last
|
12
|
+
# view_helpers # => this comes from the views
|
13
|
+
# ParticipatorySpacePrivateUserPresenter.new(action_log, view_helpers).present
|
14
|
+
class ParticipatorySpacePrivateUserPresenter < Decidim::Log::BasePresenter
|
15
|
+
private
|
16
|
+
|
17
|
+
def diff_fields_mapping
|
18
|
+
{
|
19
|
+
name: :string,
|
20
|
+
email: :string
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def action_string
|
25
|
+
case action
|
26
|
+
when "invite", "delete"
|
27
|
+
"decidim.admin_log.participatory_space_private_user.#{action}"
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def i18n_labels_scope
|
34
|
+
"activemodel.attributes.participatory_space_private_user"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# A presenter to render metrics in pages
|
5
|
+
class MetricChartsPresenter < Rectify::Presenter
|
6
|
+
attribute :organization, Decidim::Organization
|
7
|
+
|
8
|
+
# Public: Render a collection of primary metrics.
|
9
|
+
def highlighted
|
10
|
+
highlighted_metrics = Decidim.metrics_registry.highlighted
|
11
|
+
safe_join(
|
12
|
+
highlighted_metrics.map do |metric|
|
13
|
+
render_metrics_data(metric.metric_name, klass: "column medium-4")
|
14
|
+
end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Render a collection of metrics that are not primary.
|
19
|
+
def not_highlighted
|
20
|
+
not_highlighted_metrics = Decidim.metrics_registry.not_highlighted
|
21
|
+
safe_join(
|
22
|
+
not_highlighted_metrics.in_groups_of(2, [:empty]).map do |metrics_group|
|
23
|
+
content_tag :div, class: "column medium-4" do
|
24
|
+
safe_join(
|
25
|
+
metrics_group.map do |metric|
|
26
|
+
render_metrics_data(metric.metric_name, klass: "column medium-6", graph_klass: "small")
|
27
|
+
end
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def render_metrics_data(metric_name, opts = {})
|
37
|
+
content_tag :div, class: opts[:klass].presence || "column medium-6" do
|
38
|
+
content_tag :div,
|
39
|
+
"",
|
40
|
+
id: "#{metric_name}_chart",
|
41
|
+
class: "areachart metric-chart #{opts[:graph_klass]}",
|
42
|
+
data: {
|
43
|
+
chart: "areachart",
|
44
|
+
metric: metric_name,
|
45
|
+
info: {
|
46
|
+
title: I18n.t("decidim.metrics.#{metric_name}.title"),
|
47
|
+
object: I18n.t("decidim.metrics.#{metric_name}.object")
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
#
|
5
|
+
# Presenter for metric objects
|
6
|
+
#
|
7
|
+
class MetricObjectPresenter < SimpleDelegator
|
8
|
+
def attr_int(attr, default: 0)
|
9
|
+
return default unless __getobj__
|
10
|
+
__getobj__[attr] || default
|
11
|
+
end
|
12
|
+
|
13
|
+
def attr_string(attr, default: "")
|
14
|
+
return default unless __getobj__
|
15
|
+
__getobj__[attr].presence || default
|
16
|
+
end
|
17
|
+
|
18
|
+
def attr_date(attr, default: "")
|
19
|
+
return default unless __getobj__
|
20
|
+
__getobj__[attr].try(:strftime, "%Y-%m-%d") || default
|
21
|
+
end
|
22
|
+
|
23
|
+
def attr_translated(attr, locale: I18n.locale, default: "")
|
24
|
+
return default unless __getobj__
|
25
|
+
__getobj__[attr].try(:[], locale.to_s).presence || default
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -4,11 +4,7 @@ module Decidim
|
|
4
4
|
#
|
5
5
|
# Decorator for user groups
|
6
6
|
#
|
7
|
-
class UserGroupPresenter <
|
8
|
-
def nickname
|
9
|
-
""
|
10
|
-
end
|
11
|
-
|
7
|
+
class UserGroupPresenter < UserPresenter
|
12
8
|
def deleted?
|
13
9
|
false
|
14
10
|
end
|
@@ -19,10 +15,22 @@ module Decidim
|
|
19
15
|
"verified-badge"
|
20
16
|
end
|
21
17
|
|
22
|
-
|
23
|
-
|
18
|
+
delegate :url, to: :avatar, prefix: true
|
19
|
+
|
20
|
+
def can_be_contacted?
|
21
|
+
false
|
24
22
|
end
|
25
23
|
|
26
|
-
|
24
|
+
def officialization_text
|
25
|
+
I18n.t("decidim.profiles.default_officialization_text_for_user_groups")
|
26
|
+
end
|
27
|
+
|
28
|
+
def can_follow?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def members_count
|
33
|
+
Decidim::UserGroups::AcceptedUsers.for(__getobj__).count
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
@@ -7,6 +7,7 @@ module Decidim
|
|
7
7
|
class UserPresenter < SimpleDelegator
|
8
8
|
include Rails.application.routes.mounted_helpers
|
9
9
|
include ActionView::Helpers::UrlHelper
|
10
|
+
include Decidim::TranslatableAttributes
|
10
11
|
|
11
12
|
#
|
12
13
|
# nickname presented in a twitter-like style
|
@@ -46,5 +47,18 @@ module Decidim
|
|
46
47
|
def following_count
|
47
48
|
__getobj__.following_users.count
|
48
49
|
end
|
50
|
+
|
51
|
+
def can_be_contacted?
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def officialization_text
|
56
|
+
translated_attribute(officialized_as).presence ||
|
57
|
+
I18n.t("decidim.profiles.default_officialization_text_for_users")
|
58
|
+
end
|
59
|
+
|
60
|
+
def can_follow?
|
61
|
+
true
|
62
|
+
end
|
49
63
|
end
|
50
64
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This class search for objects related to Metrics, and creates a new registry within
|
5
|
+
# his own parameters
|
6
|
+
class MetricManage
|
7
|
+
def self.for(day_string, organization)
|
8
|
+
new(day_string, organization)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(day_string, organization)
|
12
|
+
@day = day_string.present? ? Date.parse(day_string) : Time.zone.today - 1.day
|
13
|
+
raise ArgumentError, "[ERROR] Malformed `day` argument. Format must be `YYYY-MM-DD` and in the past" if @day > Time.zone.today
|
14
|
+
@day ||= Time.zone.today - 1.day
|
15
|
+
@organization = organization
|
16
|
+
@metric_name = metric_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def metric_name
|
20
|
+
""
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
@day.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
return @registry if @registry
|
29
|
+
|
30
|
+
return if cumulative.zero?
|
31
|
+
@registry = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name, organization: @organization)
|
32
|
+
@registry.assign_attributes(cumulative: cumulative, quantity: quantity)
|
33
|
+
@registry.save!
|
34
|
+
@registry
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def start_time
|
40
|
+
@start_time ||= @day.beginning_of_day
|
41
|
+
end
|
42
|
+
|
43
|
+
def end_time
|
44
|
+
@end_time ||= @day.end_of_day
|
45
|
+
end
|
46
|
+
|
47
|
+
def query
|
48
|
+
raise "Not implemented"
|
49
|
+
end
|
50
|
+
|
51
|
+
def cumulative
|
52
|
+
@cumulative ||= query.count
|
53
|
+
end
|
54
|
+
|
55
|
+
def quantity
|
56
|
+
@quantity ||= cumulative
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|