diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-07-05 02:41:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 02:41:40 +0200 |
commit | 44b2ee3485ba0845e5910cefcb4b1e2f84f34470 (patch) | |
tree | cc91189c9b36aaf0a04d339455c6d238992753a9 /app/serializers/rest | |
parent | 1b4054256f9d3302b44f71627a23bb0902578867 (diff) |
Add customizable user roles (#18641)
* Add customizable user roles * Various fixes and improvements * Add migration for old settings and fix tootctl role management
Diffstat (limited to 'app/serializers/rest')
-rw-r--r-- | app/serializers/rest/credential_account_serializer.rb | 6 | ||||
-rw-r--r-- | app/serializers/rest/instance_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/rest/role_serializer.rb | 13 |
3 files changed, 20 insertions, 1 deletions
diff --git a/app/serializers/rest/credential_account_serializer.rb b/app/serializers/rest/credential_account_serializer.rb index be0d763dc..27e1db207 100644 --- a/app/serializers/rest/credential_account_serializer.rb +++ b/app/serializers/rest/credential_account_serializer.rb @@ -3,6 +3,8 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer attributes :source + has_one :role, serializer: REST::RoleSerializer + def source user = object.user @@ -15,4 +17,8 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer follow_requests_count: FollowRequest.where(target_account: object).limit(40).count, } end + + def role + object.user_role + end end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index f5dec0dac..9cc245422 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -93,7 +93,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer end def invites_enabled - Setting.min_invite_role == 'user' + UserRole.everyone.can?(:invite_users) end private diff --git a/app/serializers/rest/role_serializer.rb b/app/serializers/rest/role_serializer.rb new file mode 100644 index 000000000..5b81c6e04 --- /dev/null +++ b/app/serializers/rest/role_serializer.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class REST::RoleSerializer < ActiveModel::Serializer + attributes :id, :name, :permissions, :color, :highlighted + + def id + object.id.to_s + end + + def permissions + object.computed_permissions.to_s + end +end |