Skip to content

Commit

Permalink
- UpdateUserForm checks if user is an external and if the current user
Browse files Browse the repository at this point in the history
signed in doesn't have Manage Users permissions
- `external_account` method & attribute moved from current user serializer to user
  serializer
  • Loading branch information
alihadimazeh committed Nov 20, 2024
1 parent 19084c4 commit 509ee97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function UpdateUserForm({ user }) {

return (
<Form methods={methods} onSubmit={updateUserAPI.mutate}>
<FormControl field={fields.name} type="text" readOnly={currentUser.external_account} />
<FormControl field={fields.name} type="text" readOnly={user.external_account && !PermissionChecker.hasManageUsers(currentUser)} />
<FormControl field={fields.email} type="email" readOnly />
<FormSelect field={fields.language} variant="dropdown">
{
Expand Down Expand Up @@ -102,6 +102,7 @@ UpdateUserForm.propTypes = {
name: PropTypes.string.isRequired,
email: PropTypes.string.isRequired,
provider: PropTypes.string.isRequired,
external_account: PropTypes.bool.isRequired,
role: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/current_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
# frozen_string_literal: true

class CurrentUserSerializer < UserSerializer
attributes :signed_in, :permissions, :status, :external_account, :super_admin
attributes :signed_in, :permissions, :status, :super_admin

def signed_in
true
end

def external_account
object.external_id?
end

def permissions
RolePermission.joins(:permission)
.where(role_id: object.role_id)
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
class UserSerializer < ApplicationSerializer
include Avatarable

attributes :id, :name, :email, :provider, :language, :avatar, :verified, :created_at
attributes :id, :name, :email, :provider, :language, :avatar, :verified, :created_at, :external_account

belongs_to :role

def language
object.language.tr('_', '-')
end

def external_account
object.external_id?
end

def avatar
user_avatar(object)
end
Expand Down

0 comments on commit 509ee97

Please sign in to comment.