Skip to content

Commit 1784180

Browse files
alecslupufblupiandreslucena
authored
Require organization in method (decidim#14683)
Co-authored-by: Fran Bolívar <francisco.bolivar@nazaries.com> Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
1 parent 9f1e8fd commit 1784180

16 files changed

Lines changed: 55 additions & 36 deletions

File tree

RELEASE_NOTES.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,27 @@ You can read more about this change on PR [\#XXXX](https://github.com/decidim/de
5656

5757
## 5. Changes in APIs
5858

59-
### 5.1. [[TITLE OF THE CHANGE]]
59+
### 5.1. Require organization in nicknamize method
60+
61+
In order to avoid potential performance issues, we have changed the `nicknamize` method by requiring the organization as a parameter.
62+
63+
If you have used code as such:
64+
65+
```ruby
66+
# We were including the organization in an optional scope
67+
Decidim::UserBaseEntity.nicknamize(nickname, decidim_organization_id: user.decidim_organization_id)
68+
```
69+
70+
You need to change it, to something like:
71+
72+
```ruby
73+
# Now the organization is the required second parameter of the method
74+
Decidim::UserBaseEntity.nicknamize(nickname, user.decidim_organization_id)
75+
```
76+
77+
You can read more about this change on PR [#14669](https://github.com/decidim/decidim/pull/14669).
78+
79+
### 5.2. [[TITLE OF THE CHANGE]]
6080

6181
In order to [[REASONING (e.g. improve the maintenance of the code base)]] we have changed...
6282

decidim-admin/app/controllers/decidim/admin/impersonations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def new_managed_user
9999
managed: true,
100100
name: params.dig(:impersonate_user, :name)
101101
) do |u|
102-
u.nickname = Decidim::UserBaseEntity.nicknamize(u.name, organization: current_organization)
102+
u.nickname = Decidim::UserBaseEntity.nicknamize(u.name, current_organization.id)
103103
u.admin = false
104104
u.tos_agreement = true
105105
end

decidim-conferences/app/commands/decidim/conferences/admin/invite_user_to_join_conference.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def invite_user
7979
end
8080
else
8181
user.name = form.name
82-
user.nickname = UserBaseEntity.nicknamize(user.name, organization: user.organization)
82+
user.nickname = UserBaseEntity.nicknamize(user.name, user.decidim_organization_id)
8383
invite_user_to_sign_up
8484
create_invitation!
8585
end

decidim-core/app/commands/decidim/invite_user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def invite_user
4141
@user = Decidim::User.new(
4242
name: form.name,
4343
email: form.email.downcase,
44-
nickname: UserBaseEntity.nicknamize(form.name, organization: form.organization),
44+
nickname: UserBaseEntity.nicknamize(form.name, form.organization.id),
4545
organization: form.organization,
4646
admin: form.role == "admin",
4747
roles: form.role == "admin" ? [] : [form.role].compact

decidim-core/app/forms/decidim/omniauth_registration_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def self.create_signature(provider, uid)
2525
end
2626

2727
def normalized_nickname
28-
UserBaseEntity.nicknamize(nickname || name, organization: current_organization)
28+
UserBaseEntity.nicknamize(nickname || name, current_organization.id)
2929
end
3030
end
3131
end

decidim-core/app/forms/decidim/registration_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def email_unique_in_organization
3737
end
3838

3939
def generate_nickname(name, organization)
40-
Decidim::UserBaseEntity.nicknamize(name, organization:)
40+
Decidim::UserBaseEntity.nicknamize(name, organization.id)
4141
end
4242

4343
def valid_users

decidim-core/db/migrate/20171212103803_create_unique_nicknames.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def up
1111
add_column :decidim_users, :nickname, :string, limit: 20
1212

1313
User.where.not(name: nil).find_each do |user|
14-
user.update!(nickname: UserBaseEntity.nicknamize(user.name, decidim_organization_id: user.decidim_organization_id))
14+
user.update!(nickname: UserBaseEntity.nicknamize(user.name, user.decidim_organization_id))
1515
end
1616

1717
add_index :decidim_users,

decidim-core/db/migrate/20180221101934_fix_nickname_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def change
1111
User.where(nickname: nil)
1212
.where(deleted_at: nil)
1313
.where(managed: false)
14-
.find_each { |u| u.update(nickname: UserBaseEntity.nicknamize(u.name, decidim_organization_id: u.decidim_organization_id)) }
14+
.find_each { |u| u.update(nickname: UserBaseEntity.nicknamize(u.name, u.decidim_organization_id)) }
1515

1616
# rubocop:disable Rails/SkipsModelValidations
1717
User.where(nickname: nil).update_all("nickname = ''")

decidim-core/db/migrate/20180706104107_add_nickname_to_managed_users.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class User < ApplicationRecord
77

88
def up
99
User.where(managed: true, nickname: nil).includes(:organization).find_each do |user|
10-
user.nickname = UserBaseEntity.nicknamize(user.name, organization: user.organization)
10+
user.nickname = UserBaseEntity.nicknamize(user.name, user.decidim_organization_id)
1111
user.save
1212
end
1313
end

decidim-core/db/migrate/20181001124950_move_users_groups_to_users_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def change
6464
verified_at: old_user_group.verified_at
6565
}
6666
new_attributes = clean_attributes.merge(
67-
nickname: UserBaseEntity.nicknamize(clean_attributes["name"]),
67+
nickname: UserBaseEntity.nicknamize(clean_attributes["name"], old_user_group.decidim_organization_id),
6868
extended_data:
6969
)
7070
new_user_group = NewUserGroup.create!(new_attributes)

0 commit comments

Comments
 (0)