[Git][noosfero/noosfero][master] 2 commits: roles: not display other profiles roles on organization_roles
Rodrigo Souto
gitlab at mg.gitlab.com
Thu Jan 11 11:34:13 BRST 2018
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
b57dad19 by Rodrigo Souto at 2018-01-10T11:08:00-03:00
roles: not display other profiles roles on organization_roles
- - - - -
da51c586 by Rodrigo Souto at 2018-01-11T13:34:02+00:00
Merge branch 'organization-roles' into 'master'
roles: not display other profiles roles on organization_roles
See merge request noosfero/noosfero!1370
- - - - -
4 changed files:
- app/models/profile.rb
- + db/migrate/20180105151301_fix_memberships_through_wrong_roles.rb
- db/schema.rb
- test/unit/profile_test.rb
Changes:
=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -62,7 +62,7 @@ class Profile < ApplicationRecord
all_roles(env_id).where('profile_id = ?', profile_id)
end
def self.organization_roles(env_id, profile_id)
- all_roles(env_id).where("profile_id = ? or key like 'profile_%'", profile_id)
+ all_roles(env_id).where("profile_id = ? or (key like 'profile_%' and profile_id is null)", profile_id)
end
def self.organization_member_and_custom_roles(env_id, profile_id)
self.organization_member_roles(env_id) | self.organization_custom_roles(env_id, profile_id)
=====================================
db/migrate/20180105151301_fix_memberships_through_wrong_roles.rb
=====================================
--- /dev/null
+++ b/db/migrate/20180105151301_fix_memberships_through_wrong_roles.rb
@@ -0,0 +1,15 @@
+class FixMembershipsThroughWrongRoles < ActiveRecord::Migration
+ def change
+ Community.find_each do |group|
+ m1 = group.members
+ m2 = group.members.by_role(Profile::Roles.organization_member_and_custom_roles(group.environment.id, group.id))
+ m3 = m1 - m2
+ if m3.present?
+ m3.each do |member|
+ group.remove_member(member)
+ group.add_member(member)
+ end
+ end
+ end
+ end
+end
=====================================
db/schema.rb
=====================================
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170923044548) do
+ActiveRecord::Schema.define(version: 20180105151301) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -2025,8 +2025,10 @@ class ProfileTest < ActiveSupport::TestCase
env = fast_create(Environment)
env.roles.delete_all
profile = fast_create(Organization)
+ another_profile = fast_create(Organization)
roles = %w(foo bar profile_foo profile_bar).map{ |r| create(Role, :name => r, :key => r, :environment_id => env.id, :permissions => ["some"]) }
roles << create(Role, name: 'test', key: 'something_else', environment_id: env.id, profile_id: profile.id)
+ roles << create(Role, name: 'another test', key: 'profile_something_else', environment_id: env.id, profile_id: another_profile.id)
assert_equal roles[2..4], Profile::Roles.organization_roles(env.id, profile.id)
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/768516b5f8f98cc853ba279f4ea0b6d28792a364...da51c58682339d38979f3031ae1828464878d319
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/768516b5f8f98cc853ba279f4ea0b6d28792a364...da51c58682339d38979f3031ae1828464878d319
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180111/9085a04c/attachment-0001.html>
More information about the Noosfero-dev
mailing list