lib/scrivito/membership.rb in scrivito_sdk-0.17.0 vs lib/scrivito/membership.rb in scrivito_sdk-0.18.0
- old
+ new
@@ -1,26 +1,45 @@
module Scrivito
- # @api beta
+ # @api public
# Represents a Membership of a {User} in a {Workspace}
class Membership
- # @api beta
+ # @api public
# The {User User's} id
#
# @return [String]
attr_reader :user_id
- # @api beta
+ # @api public
# The role associated with this membership.
#
# @note Currently the only available role is "owner".
#
# @return [String] the name of role
attr_reader :role
def initialize(user_id, data)
@user_id = user_id
@role = data.fetch("role")
+ end
+
+ # Fetches and returns the {User} with the id {Membership#user_id}.
+ # Uses the proc set in {Configuration.find_user} to fetch the user.
+ # @api public
+ # @return The value returned by the proc set in {Configuration.find_user}.
+ # @return An unknown user if no proc is set in {Configuration.find_user} or the proc returns a
+ # falsy value. The unknown user will have the id of the original user and no abilities.
+ # @see Scrivito::Configuration.find_user
+ def user
+ User.find(user_id) || User.unknown_user(user_id)
+ end
+
+ def as_json(options = nil)
+ {
+ user_id: user_id,
+ role: role,
+ description: user.description,
+ }
end
end
end