суббота, 26 ноября 2016 г.

RedMine. How to add user to default group after self registration.

You must change core file, it's not good, but fast solution. Find register method in account_controller.rb. Typically location in /app/controllers.
Add code in register method. Example bellow use 72 as default group. You can find the number in the URL if you log into the redmine web UI with an admin account, and go to Administration->Groups.
After changes you must restart redmine daemon, e.g. httpd.


 # User self-registration
  def register
    (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration]
    if request.get?
      session[:auth_source_registration] = nil
      @user = User.new(:language => current_language.to_s)
    else
      user_params = params[:user] || {}
      @user = User.new
      @user.safe_attributes = user_params
      @user.pref.attributes = params[:pref] if params[:pref]
      @user.admin = false
      @user.register
      if session[:auth_source_registration]
        @user.activate
        @user.login = session[:auth_source_registration][:login]
        @user.auth_source_id = session[:auth_source_registration][:auth_source_id]
        if @user.save
          session[:auth_source_registration] = nil
          self.logged_user = @user
          #my def group

          group = Group.find(72)

          group.users << @user

          #my def group
          flash[:notice] = l(:notice_account_activated)
          redirect_to my_account_path
        end
      else
        @user.login = params[:user][:login]


 

пятница, 4 ноября 2016 г.