app/cms/scrivito/user_definition.rb in scrivito_sdk-1.11.0 vs app/cms/scrivito/user_definition.rb in scrivito_sdk-1.12.0.rc1

- old
+ new

@@ -20,11 +20,11 @@ # @note By default, all users are allowed to create a new workspace. # @see https://scrivito.com/user-permissions Defining users and their permissions # # @param [Symbol] verb the verb of the action (see {Scrivito::User::VERBS}). # @param [Symbol] subject the subject of the action. Currently, only +:workspace+ is supported. - # @param [String] message optional message to be displayed in the UI. + # @param [String] message an optional message to be displayed in the UI. # # @raise [Scrivito::ScrivitoError] if the given verb is invalid # @raise [Scrivito::ScrivitoError] if the specified rule conflicts with a # {Scrivito::UserDefinition#can_never} rule. # @@ -55,11 +55,11 @@ # @note By default, all users are allowed to create a new workspace. Use this method to forbid a # user to create a new workspace. # # @param [Symbol] verb the verb of the action (see {Scrivito::User::VERBS}). # @param [Symbol] subject the subject of the action. Currently, only +:workspace+ is supported. - # @param [String] message optional message to be displayed in the UI. + # @param [String] message an optional message to be displayed in the UI. # # @raise [Scrivito::ScrivitoError] if the given verb is invalid # @raise [Scrivito::ScrivitoError] if the specified rule conflicts with a # {Scrivito::UserDefinition#can_always} rule. # @@ -80,35 +80,35 @@ assert_no_conflict(:always, verb, subject) @explicit_rules << [:never, verb, subject, message] end # - # Enable the user to create workspaces, to read from, write to, publish, delete workspaces, + # Enables the user to create workspaces, to read from, write to, publish, delete workspaces, # and to invite others to collaborate on any workspace. # # @api public # def is_admin! @explicit_rules = User::VERBS.map { |verb| [:always, verb, :workspace, nil] } end # - # Defines the user description to be displayed in the in-place GUI, e.g. in the workspace menu. + # Defines the user description to be displayed in the in-place UI, e.g. in the workspace menu. # # @api public # # @param [String] description_string the description, defaults to the the user id. - # @param [Proc] description_proc proc to calculate the description, defaults to the the user id. + # @param [Proc] description_proc a proc to calculate the description, defaults to the user id. # - # @note The description is calculated "lazyly". The calculated description is cached. + # @note The description is calculated "lazily". The calculated description is cached. # # @see Scrivito::User.define # - # @example Display the user +alice+ as "alice" in the in-place GUI: + # @example Displays the user +alice+ as "alice" in the in-place UI: # alice = Scrivito::User.define('alice') # - # @example Display the user +bob+ as "Bob Doe" in the in-place GUI: + # @example Displays the user +bob+ as "Bob Doe" in the in-place UI: # bob = Scrivito::User.define('bob') do |user| # user.description('Bob Doe') # end # # bob = Scrivito::User.define('bob') do |user| @@ -124,21 +124,21 @@ @description_proc = description_proc end end # - # Defines the proc for fetching users for autocompletion purposes in the in-place GUI. + # Defines the proc for fetching users for autocompletion purposes in the in-place UI. # User autocompletion is used in the settings dialog of a workspace. # If the proc is not set, {Scrivito::User.find} is used to fetch the suggested users, # assuming the input is part of the user id. # # @api public # - # @note Only the first 20 users returned are displayed in the in-place GUI. + # @note Only the first 20 users returned are displayed in the in-place UI. # @note +suggest_users_proc+ may also be invoked with an empty string. # - # @param [Proc] suggest_users_proc proc for fetching users to be suggested in the in-place GUI + # @param [Proc] suggest_users_proc proc for fetching users to be suggested in the in-place UI # @yieldparam [String] input an arbitrary string originating from the user autocompletion input field, # e.g. the first letters of a user name # @yieldreturn [Array<Scrivito::User>] users that were found on account of the given input string # # @example @@ -166,11 +166,11 @@ # @note The callback is only executed for {BasicObj Objs} equipped with the attribute # specified using the +:using+ option. It is not executed for a {BasicWidget Widget} # with this attribute. # # @param [Hash] options - # @option options [Symbol] :using the attribute you with to refer to in the callback + # @option options [Symbol] :using the attribute you wish to refer to in the callback # @yield [attribute] the value of the specified attribute # @yieldreturn [String, false] either return a message for the user or +false+ if # no restriction applies # # @example @@ -198,16 +198,38 @@ # def restrict_obj_publish(options, &block) restriction_set.add(options, &block) end + # + # Lets you specify the user's in-place UI language. + # + # Overrides auto-detection from browser language. + # Overrides the application-wide scrivito {Configuration.ui_locale UI locale configuration}. + # + # @api public + # + # @param [String] language a language code (e.g. 'en') + # + # @see Scrivito::User.define + # + # @example Have +robert+ use a UI with German titles: + # robert = Scrivito::User.define('robert') do |user| + # user.ui_locale('de') + # end + # + def ui_locale(language) + @ui_locale = language + end + def user User.new( id: @user_id, explicit_rules: @explicit_rules, description_proc: @description_proc, suggest_users_proc: @suggest_users_proc, - restriction_set: restriction_set + restriction_set: restriction_set, + ui_locale: @ui_locale, ) end private