Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[36467] Add API users form and schema endpoints #9090

Merged
merged 21 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e73ea3f
Add Users form endpoints
oliverguenther Mar 15, 2021
c99e818
Avoid cache_if as it caches properties for new_record? as well
oliverguenther Mar 15, 2021
62403db
Add specs
oliverguenther Mar 15, 2021
ba75899
Add missing custom_field_values method
oliverguenther Mar 15, 2021
dc41f74
Fix missing firstname lastname api conversions
oliverguenther Mar 15, 2021
daf5417
Disable cached_representer on user payload
oliverguenther Mar 15, 2021
232c0ef
Add patch to allow using our custom setter in case of nil values
oliverguenther Mar 15, 2021
a4add83
Add test for changing status
oliverguenther Mar 15, 2021
6e56bd9
Fix expectation with changed attribute mapping
oliverguenther Mar 15, 2021
c018f95
Disable rendering name property for users
oliverguenther Mar 17, 2021
fa7efab
Fix attribute names for first and lastname for writable
oliverguenther Mar 17, 2021
bc43035
Ensure password is marked writable even though its not an attribute
oliverguenther Mar 17, 2021
1e0c9bf
Avoid explicitly setting to_ar_name conversion
oliverguenther Mar 17, 2021
9f7b148
Reuse AssignableCustomFieldValues concern
oliverguenther Mar 17, 2021
579ff77
Fix structure of users.apib to be flat
oliverguenther Mar 17, 2021
b1b9591
Extend requests with custom fields
oliverguenther Mar 17, 2021
c3edd40
Output name, but dont mark as writable attribute
oliverguenther Mar 17, 2021
64a6754
Fix id indentation
oliverguenther Mar 23, 2021
47f72ea
Rename schema email property
oliverguenther Mar 23, 2021
f20065f
Fix param for user update form
oliverguenther Mar 23, 2021
0c33fa7
Fix schema docs
oliverguenther Mar 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions app/contracts/users/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@

module Users
class BaseContract < ::ModelContract
include AssignableCustomFieldValues

attribute :login,
writeable: ->(*) { user.allowed_to_globally?(:manage_user) && model.id != user.id }
attribute :firstname
attribute :lastname
attribute :name
attribute :mail
attribute :admin,
writeable: ->(*) { user.admin? && model.id != user.id }
Expand All @@ -53,18 +54,33 @@ def self.model
User
end

validate :password_writable
validate :validate_password_writable
validate :existing_auth_source

delegate :available_custom_fields, to: :model

def reduce_writable_attributes(attributes)
super.tap do |writable|
writable << 'password' if password_writable?
end
end

private

##
# Password is not a regular attribute so it bypasses
# attribute writable checks
def password_writable?
user.admin? || user.id == model.id
end

##
# User#password is not an ActiveModel property,
# but just an accessor, so we need to identify it being written there.
# It is only present when freshly written
def password_writable
def validate_password_writable
# Only admins or the user themselves can set the password
return if user.admin? || user.id == model.id
return if password_writable?

errors.add :password, :error_readonly if model.password.present?
end
Expand Down
4 changes: 3 additions & 1 deletion config/constants/ar_to_api_conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class ARToAPIConversions
column_names: 'columns',
is_public: 'public',
sort_criteria: 'sortBy',
message: 'post'
message: 'post',
firstname: 'firstName',
lastname: 'lastName',
}.freeze

# Conversions that are unidirectional (from the API to AR)
Expand Down
Loading