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
@@ -5,7 +5,6 @@ module Decidim
|
|
5
5
|
class RegistrationForm < Form
|
6
6
|
mimic :user
|
7
7
|
|
8
|
-
attribute :sign_up_as, String
|
9
8
|
attribute :name, String
|
10
9
|
attribute :nickname, String
|
11
10
|
attribute :email, String
|
@@ -14,11 +13,6 @@ module Decidim
|
|
14
13
|
attribute :newsletter, Boolean
|
15
14
|
attribute :tos_agreement, Boolean
|
16
15
|
|
17
|
-
attribute :user_group_name, String
|
18
|
-
attribute :user_group_document_number, String
|
19
|
-
attribute :user_group_phone, String
|
20
|
-
|
21
|
-
validates :sign_up_as, inclusion: { in: %w(user user_group) }
|
22
16
|
validates :name, presence: true
|
23
17
|
validates :nickname, presence: true, length: { maximum: Decidim::User.nickname_max_length }
|
24
18
|
validates :email, presence: true, 'valid_email_2/email': { disposable: true }
|
@@ -27,18 +21,8 @@ module Decidim
|
|
27
21
|
validates :password_confirmation, presence: true
|
28
22
|
validates :tos_agreement, allow_nil: false, acceptance: true
|
29
23
|
|
30
|
-
validates :user_group_name, presence: true, if: :user_group?
|
31
|
-
validates :user_group_document_number, presence: true, if: :user_group?
|
32
|
-
validates :user_group_phone, presence: true, if: :user_group?
|
33
|
-
|
34
24
|
validate :email_unique_in_organization
|
35
25
|
validate :nickname_unique_in_organization
|
36
|
-
validate :user_group_name_unique_in_organization
|
37
|
-
validate :user_group_document_number_unique_in_organization
|
38
|
-
|
39
|
-
def user_group?
|
40
|
-
sign_up_as == "user_group"
|
41
|
-
end
|
42
26
|
|
43
27
|
def newsletter_at
|
44
28
|
return nil unless newsletter?
|
@@ -54,16 +38,5 @@ module Decidim
|
|
54
38
|
def nickname_unique_in_organization
|
55
39
|
errors.add :nickname, :taken if User.find_by(nickname: nickname, organization: current_organization).present?
|
56
40
|
end
|
57
|
-
|
58
|
-
def user_group_name_unique_in_organization
|
59
|
-
errors.add :user_group_name, :taken if UserGroup.find_by(name: user_group_name, decidim_organization_id: current_organization.id).present?
|
60
|
-
end
|
61
|
-
|
62
|
-
def user_group_document_number_unique_in_organization
|
63
|
-
errors.add :user_group_document_number, :taken if UserGroup.find_by(
|
64
|
-
document_number: user_group_document_number,
|
65
|
-
decidim_organization_id: current_organization.id
|
66
|
-
).present?
|
67
|
-
end
|
68
41
|
end
|
69
42
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# The form object that handles the data behind creating a user group.
|
5
|
+
class UserGroupForm < Form
|
6
|
+
mimic :group
|
7
|
+
|
8
|
+
attribute :name
|
9
|
+
attribute :nickname
|
10
|
+
attribute :email
|
11
|
+
attribute :avatar
|
12
|
+
attribute :about
|
13
|
+
attribute :document_number
|
14
|
+
attribute :phone
|
15
|
+
|
16
|
+
validates :name, presence: true
|
17
|
+
validates :email, presence: true, 'valid_email_2/email': { disposable: true }
|
18
|
+
validates :nickname, presence: true
|
19
|
+
validates :document_number, presence: true
|
20
|
+
validates :phone, presence: true
|
21
|
+
|
22
|
+
validates :nickname, length: { maximum: Decidim::User.nickname_max_length, allow_blank: true }
|
23
|
+
validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
|
24
|
+
|
25
|
+
validate :unique_document_number
|
26
|
+
validate :unique_email
|
27
|
+
validate :unique_name
|
28
|
+
validate :unique_nickname
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def unique_document_number
|
33
|
+
errors.add :document_number, :taken if UserGroup
|
34
|
+
.with_document_number(
|
35
|
+
context.current_organization,
|
36
|
+
document_number
|
37
|
+
)
|
38
|
+
.where.not(id: id)
|
39
|
+
.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
def unique_email
|
43
|
+
return true if Decidim::UserBaseEntity
|
44
|
+
.where(
|
45
|
+
organization: context.current_organization,
|
46
|
+
email: email
|
47
|
+
)
|
48
|
+
.where.not(id: id)
|
49
|
+
.empty?
|
50
|
+
|
51
|
+
errors.add :email, :taken
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def unique_name
|
56
|
+
return true if Decidim::UserBaseEntity
|
57
|
+
.where(
|
58
|
+
organization: context.current_organization,
|
59
|
+
name: name
|
60
|
+
)
|
61
|
+
.where.not(id: id)
|
62
|
+
.empty?
|
63
|
+
|
64
|
+
errors.add :name, :taken
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def unique_nickname
|
69
|
+
return true if Decidim::UserBaseEntity
|
70
|
+
.where(
|
71
|
+
organization: context.current_organization,
|
72
|
+
nickname: nickname
|
73
|
+
)
|
74
|
+
.where.not(id: id)
|
75
|
+
.empty?
|
76
|
+
|
77
|
+
errors.add :nickname, :taken
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -32,5 +32,15 @@ module Decidim
|
|
32
32
|
current_params = try(:params) || {}
|
33
33
|
EngineRouter.admin_proxy(component).root_path(locale: current_params[:locale])
|
34
34
|
end
|
35
|
+
|
36
|
+
# Returns whether the component can be managed or not by checking if it has
|
37
|
+
# an admin engine.
|
38
|
+
#
|
39
|
+
# component - the Component we want to find if it's manageable or not.
|
40
|
+
#
|
41
|
+
# Returns a boolean matching the question.
|
42
|
+
def can_be_managed?(component)
|
43
|
+
component.manifest.admin_engine.present?
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
@@ -7,12 +7,13 @@ module Decidim
|
|
7
7
|
# the form_for helper with a custom builder
|
8
8
|
#
|
9
9
|
# filter - A filter object
|
10
|
+
# url - A String with the URL to post the from. Self URL by default.
|
10
11
|
# block - A block to be called with the form builder
|
11
12
|
#
|
12
13
|
# Returns the filter resource form wrapped in a div
|
13
|
-
def filter_form_for(filter)
|
14
|
+
def filter_form_for(filter, url = url_for)
|
14
15
|
content_tag :div, class: "filters" do
|
15
|
-
form_for filter, builder: FilterFormBuilder, url:
|
16
|
+
form_for filter, builder: FilterFormBuilder, url: url, as: :filter, method: :get, remote: true, html: { id: nil } do |form|
|
16
17
|
yield form
|
17
18
|
end
|
18
19
|
end
|
@@ -40,7 +40,9 @@ module Decidim
|
|
40
40
|
#
|
41
41
|
# Returns an HTML tag with the icon.
|
42
42
|
def resource_icon(resource, options = {})
|
43
|
-
if resource.
|
43
|
+
if resource.class.name == "Decidim::Comments::Comment"
|
44
|
+
icon "comment-square", options
|
45
|
+
elsif resource.respond_to?(:component)
|
44
46
|
component_icon(resource.component, options)
|
45
47
|
elsif resource.respond_to?(:manifest)
|
46
48
|
manifest_icon(resource.manifest, options)
|
@@ -33,7 +33,7 @@ module Decidim
|
|
33
33
|
"data-here-app-id" => Decidim.geocoder[:here_app_id],
|
34
34
|
"data-here-app-code" => Decidim.geocoder[:here_app_code]
|
35
35
|
}
|
36
|
-
content = capture { yield }
|
36
|
+
content = capture { yield }.html_safe
|
37
37
|
content_tag :div, class: "row column" do
|
38
38
|
content_tag(:div, "", map_html_options) + content
|
39
39
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
class MetricJob < ApplicationJob
|
5
|
+
queue_as :metrics
|
6
|
+
|
7
|
+
def perform(manager_class, organization_id, day = nil)
|
8
|
+
organization = Decidim::Organization.find_by(id: organization_id)
|
9
|
+
return unless organization
|
10
|
+
metric = manager_class.constantize.for(day, organization)
|
11
|
+
metric.save if metric.valid?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -32,10 +32,16 @@ module Decidim
|
|
32
32
|
|
33
33
|
validates :organization, :user, :action, presence: true
|
34
34
|
validates :resource, presence: true, if: ->(log) { log.action != "delete" }
|
35
|
+
validates :visibility, presence: true, inclusion: { in: %w(admin-only public-only all) }
|
35
36
|
|
36
37
|
# To ensure records can't be deleted
|
37
38
|
before_destroy { |_record| raise ActiveRecord::ReadOnlyRecord }
|
38
39
|
|
40
|
+
# A scope that filters all the logs that should be visible at the admin panel.
|
41
|
+
def self.for_admin
|
42
|
+
where(visibility: %w(admin-only all))
|
43
|
+
end
|
44
|
+
|
39
45
|
# Overwrites the method so that records cannot be modified.
|
40
46
|
#
|
41
47
|
# Returns a Boolean.
|
@@ -43,6 +49,39 @@ module Decidim
|
|
43
49
|
!new_record?
|
44
50
|
end
|
45
51
|
|
52
|
+
# Lazy loads the `component` association through BatchLoader, can be used
|
53
|
+
# as a regular object.
|
54
|
+
def component_lazy(cache: true)
|
55
|
+
self.class.lazy_relation(decidim_component_id, "Decidim::Component", cache)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Lazy loads the `organization` association through BatchLoader, can be used
|
59
|
+
# as a regular object.
|
60
|
+
def organization_lazy(cache: true)
|
61
|
+
self.class.lazy_relation(decidim_organization_id, "Decidim::Organization", cache)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Lazy loads the `user` association through BatchLoader, can be used
|
65
|
+
# as a regular object.
|
66
|
+
def user_lazy(cache: true)
|
67
|
+
self.class.lazy_relation(decidim_user_id, "Decidim::User", cache)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Lazy loads the `participatory_space` association through BatchLoader, can be used
|
71
|
+
# as a regular object.
|
72
|
+
def participatory_space_lazy(cache: true)
|
73
|
+
return if participatory_space_id.blank? || participatory_space_type.blank?
|
74
|
+
return resouce_lazy if participatory_space_id == resource_id && participatory_space_type == resource_type
|
75
|
+
|
76
|
+
self.class.lazy_relation(participatory_space_id, participatory_space_type, cache)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Lazy loads the `resource` association through BatchLoader, can be used
|
80
|
+
# as a regular object.
|
81
|
+
def resource_lazy(cache: true)
|
82
|
+
self.class.lazy_relation(resource_id, resource_type, cache)
|
83
|
+
end
|
84
|
+
|
46
85
|
# Public: Finds the correct presenter class for the given
|
47
86
|
# `log_type` and the related `resource_type`. If no specific
|
48
87
|
# presenter can be found, it falls back to `Decidim::Log::BasePresenter`
|
@@ -55,5 +94,32 @@ module Decidim
|
|
55
94
|
rescue NameError
|
56
95
|
Decidim::Log::BasePresenter
|
57
96
|
end
|
97
|
+
|
98
|
+
# Returns a Batchloader for a given class to avoid N+1 queries.
|
99
|
+
#
|
100
|
+
# Since ActionLogs are related to many different resources, loading a collection
|
101
|
+
# of them would trigger a lot of N+1 queries. We're using BatchLoader to
|
102
|
+
# accumulate and group all the resource by their class and only loading them
|
103
|
+
# when it's necessary.
|
104
|
+
def self.lazy_relation(id_method, klass_name, cache)
|
105
|
+
klass = klass_name.constantize
|
106
|
+
BatchLoader.for(id_method).batch(cache: cache, key: klass.name.underscore) do |relation_ids, loader|
|
107
|
+
scope = klass.where(id: relation_ids)
|
108
|
+
|
109
|
+
scope = if klass.include?(Decidim::HasComponent)
|
110
|
+
scope.where(id: relation_ids).includes(:component).where.not(decidim_components: { published_at: nil })
|
111
|
+
elsif klass.reflect_on_association(:organization)
|
112
|
+
scope.where(id: relation_ids).includes(:organization)
|
113
|
+
elsif klass_name == "Decidim::Comments::Comment"
|
114
|
+
scope.where(id: relation_ids).includes(:commentable)
|
115
|
+
else
|
116
|
+
scope
|
117
|
+
end
|
118
|
+
|
119
|
+
scope = scope.published if klass.include?(Decidim::Publicable)
|
120
|
+
|
121
|
+
scope.each { |relation| loader.call(relation.id, relation) }
|
122
|
+
end
|
123
|
+
end
|
58
124
|
end
|
59
125
|
end
|
@@ -8,6 +8,8 @@ module Decidim
|
|
8
8
|
|
9
9
|
validates :coauthorable, presence: true
|
10
10
|
|
11
|
+
after_commit :author_is_follower, on: [:create]
|
12
|
+
|
11
13
|
def identity
|
12
14
|
user_group || author
|
13
15
|
end
|
@@ -19,5 +21,12 @@ module Decidim
|
|
19
21
|
def organization
|
20
22
|
coauthorable&.organization
|
21
23
|
end
|
24
|
+
|
25
|
+
def author_is_follower
|
26
|
+
return unless author.is_a?(Decidim::User)
|
27
|
+
return unless coauthorable.is_a?(Decidim::Followable)
|
28
|
+
|
29
|
+
Decidim::Follow.find_or_create_by!(followable: coauthorable, user: author)
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
@@ -20,6 +20,11 @@ module Decidim
|
|
20
20
|
Decidim::AdminLog::ComponentPresenter
|
21
21
|
end
|
22
22
|
|
23
|
+
# Other components with the same manifest and same participatory space as this one.
|
24
|
+
def siblings
|
25
|
+
@siblings ||= participatory_space.components.where.not(id: id).where(manifest_name: manifest_name)
|
26
|
+
end
|
27
|
+
|
23
28
|
# Public: Finds the manifest this component is associated to.
|
24
29
|
#
|
25
30
|
# Returns a ComponentManifest.
|
@@ -5,7 +5,7 @@ module Decidim
|
|
5
5
|
class BadgeScore < ApplicationRecord
|
6
6
|
self.table_name = "decidim_gamification_badge_scores"
|
7
7
|
|
8
|
-
belongs_to :user, class_name: "Decidim::
|
8
|
+
belongs_to :user, class_name: "Decidim::UserBaseEntity"
|
9
9
|
validates :user, presence: true
|
10
10
|
validates :value, numericality: { greater_than_or_equal_to: 0 }
|
11
11
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# A Metric is a registry that holds cumulative and quantity value by day, category, participatory_space, category, an a related object
|
5
|
+
class Metric < ApplicationRecord
|
6
|
+
# ParticipatorySpace, RelatedObject and Category are optional relationships because not all metric objects need them
|
7
|
+
# For example, User is only related to an organization, but a Proposal can have all of them
|
8
|
+
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
|
9
|
+
belongs_to :participatory_space, foreign_key: "participatory_space_id", foreign_type: "participatory_space_type", polymorphic: true, optional: true
|
10
|
+
belongs_to :related_object, foreign_key: "related_object_id", foreign_type: "related_object_type", polymorphic: true, optional: true
|
11
|
+
belongs_to :category, foreign_key: "decidim_category_id", class_name: "Decidim::Category", optional: true
|
12
|
+
end
|
13
|
+
end
|
@@ -18,6 +18,10 @@ module Decidim
|
|
18
18
|
Decidim::DataPortabilitySerializers::DataPortabilityParticipatorySpacePrivateUserSerializer
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.log_presenter_class_for(_log)
|
22
|
+
Decidim::AdminLog::ParticipatorySpacePrivateUserPresenter
|
23
|
+
end
|
24
|
+
|
21
25
|
private
|
22
26
|
|
23
27
|
# Private: check if the participatory space and the user have the same organization
|
data/app/models/decidim/user.rb
CHANGED
@@ -6,11 +6,7 @@ require "valid_email2"
|
|
6
6
|
|
7
7
|
module Decidim
|
8
8
|
# A User is a citizen that wants to join the platform to participate.
|
9
|
-
class User <
|
10
|
-
include Nicknamizable
|
11
|
-
include Resourceable
|
12
|
-
include Decidim::Followable
|
13
|
-
include Decidim::Loggable
|
9
|
+
class User < UserBaseEntity
|
14
10
|
include Decidim::DataPortability
|
15
11
|
include Decidim::Searchable
|
16
12
|
|
@@ -24,21 +20,17 @@ module Decidim
|
|
24
20
|
request_keys: [:env], reset_password_keys: [:decidim_organization_id, :email],
|
25
21
|
confirmation_keys: [:decidim_organization_id, :email]
|
26
22
|
|
27
|
-
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
|
28
23
|
has_many :identities, foreign_key: "decidim_user_id", class_name: "Decidim::Identity", dependent: :destroy
|
29
24
|
has_many :memberships, class_name: "Decidim::UserGroupMembership", foreign_key: :decidim_user_id, dependent: :destroy
|
30
25
|
has_many :user_groups, through: :memberships, class_name: "Decidim::UserGroup", foreign_key: :decidim_user_group_id
|
31
|
-
has_many :notifications, foreign_key: "decidim_user_id", class_name: "Decidim::Notification", dependent: :destroy
|
32
26
|
has_many :access_grants, class_name: "Doorkeeper::AccessGrant", foreign_key: :resource_owner_id, dependent: :destroy
|
33
27
|
has_many :access_tokens, class_name: "Doorkeeper::AccessToken", foreign_key: :resource_owner_id, dependent: :destroy
|
34
|
-
has_many :following_follows, foreign_key: "decidim_user_id", class_name: "Decidim::Follow", dependent: :destroy
|
35
28
|
|
36
29
|
validates :name, presence: true, unless: -> { deleted? }
|
37
|
-
validates :nickname, presence: true, unless: -> { deleted? || managed?
|
30
|
+
validates :nickname, presence: true, unless: -> { deleted? || managed? }, length: { maximum: Decidim::User.nickname_max_length }
|
38
31
|
validates :locale, inclusion: { in: :available_locales }, allow_blank: true
|
39
32
|
validates :tos_agreement, acceptance: true, allow_nil: false, on: :create
|
40
33
|
validates :tos_agreement, acceptance: true, if: :user_invited?
|
41
|
-
validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
|
42
34
|
validates :email, :nickname, uniqueness: { scope: :organization }, unless: -> { deleted? || managed? || nickname.blank? }
|
43
35
|
|
44
36
|
validate :all_roles_are_valid
|
@@ -53,6 +45,9 @@ module Decidim
|
|
53
45
|
scope :officialized, -> { where.not(officialized_at: nil) }
|
54
46
|
scope :not_officialized, -> { where(officialized_at: nil) }
|
55
47
|
|
48
|
+
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
49
|
+
scope :not_confirmed, -> { where(confirmed_at: nil) }
|
50
|
+
|
56
51
|
attr_accessor :newsletter_notifications
|
57
52
|
|
58
53
|
searchable_fields({
|
@@ -112,34 +107,6 @@ module Decidim
|
|
112
107
|
Decidim::Follow.where(user: self, followable: followable).any?
|
113
108
|
end
|
114
109
|
|
115
|
-
# Public: Returns a collection with all the entities this user is following.
|
116
|
-
#
|
117
|
-
# This can't be done as with a `has_many :following, through: :following_follows`
|
118
|
-
# since it's a polymorphic relation and Rails doesn't know how to load it. With
|
119
|
-
# this implementation we only query the database once for each kind of following.
|
120
|
-
#
|
121
|
-
# Returns an Array of Decidim::Followable
|
122
|
-
def following
|
123
|
-
@following ||= begin
|
124
|
-
followings = following_follows.pluck(:decidim_followable_type, :decidim_followable_id)
|
125
|
-
grouped_followings = followings.each_with_object({}) do |(type, following_id), all|
|
126
|
-
all[type] ||= []
|
127
|
-
all[type] << following_id
|
128
|
-
all
|
129
|
-
end
|
130
|
-
|
131
|
-
grouped_followings.flat_map do |type, ids|
|
132
|
-
type.constantize.where(id: ids)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def following_users
|
138
|
-
@following_users ||= following.select do |f|
|
139
|
-
f.is_a?(Decidim::User)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
110
|
def unread_conversations
|
144
111
|
Decidim::Messaging::Conversation.unread_by(self)
|
145
112
|
end
|
@@ -176,6 +143,15 @@ module Decidim
|
|
176
143
|
accepted_tos_version >= organization.tos_version
|
177
144
|
end
|
178
145
|
|
146
|
+
# Whether this user can be verified against some authorization or not.
|
147
|
+
def verifiable?
|
148
|
+
confirmed? || managed? || being_impersonated?
|
149
|
+
end
|
150
|
+
|
151
|
+
def being_impersonated?
|
152
|
+
ImpersonationLog.active.where(user: self).exists?
|
153
|
+
end
|
154
|
+
|
179
155
|
protected
|
180
156
|
|
181
157
|
# Overrides devise email required validation.
|