-
Notifications
You must be signed in to change notification settings - Fork 363
/
Copy pathuser_create_message.rb
28 lines (25 loc) · 1.24 KB
/
user_create_message.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'messages/metadata_base_message'
module VCAP::CloudController
class UserCreateMessage < MetadataBaseMessage
register_allowed_keys %i[guid origin username]
class UserCreateValidator < ActiveModel::Validator
def validate(record)
if record.guid
record.errors.add(:username, message: "cannot be provided with 'guid'") if record.username
record.errors.add(:origin, message: "cannot be provided with 'guid'") if record.origin
elsif record.username || record.origin
record.errors.add(:origin, message: "can only be provided together with 'username'") unless record.username
record.errors.add(:username, message: "can only be provided together with 'origin'") unless record.origin
record.errors.add(:origin, message: "cannot be 'uaa' when creating a user by username") unless record.origin != 'uaa'
else
record.errors.add(:guid, message: "or 'username' and 'origin' must be provided")
end
end
end
validates_with NoAdditionalKeysValidator
validates :guid, guid: true, allow_nil: true
validates :origin, string: true, allow_nil: true
validates :username, string: true, allow_nil: true
validates_with UserCreateValidator
end
end