rad_users 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/app/controllers/identities.rb +160 -0
- data/app/controllers/profiles.rb +61 -0
- data/app/controllers/sessions.rb +78 -0
- data/app/controllers/user_mailer.rb +30 -0
- data/app/controllers/user_management.rb +9 -0
- data/app/controllers/users_app.rb +9 -0
- data/app/helpers/users/authorization.rb +65 -0
- data/app/helpers/users/general.rb +22 -0
- data/app/models/avatar_file.rb +33 -0
- data/app/models/user.rb +105 -0
- data/app/models/user/email_verification_token.rb +20 -0
- data/app/models/user/forgot_password_token.rb +12 -0
- data/app/static/open_id.js +2 -0
- data/app/static/openid-selector/css/openid.css +45 -0
- data/app/static/openid-selector/demo.html +58 -0
- data/app/static/openid-selector/demoOpenIDClient.html +69 -0
- data/app/static/openid-selector/images/aol.gif +0 -0
- data/app/static/openid-selector/images/blogger.ico +0 -0
- data/app/static/openid-selector/images/claimid.ico +0 -0
- data/app/static/openid-selector/images/facebook.gif +0 -0
- data/app/static/openid-selector/images/flickr.ico +0 -0
- data/app/static/openid-selector/images/google.gif +0 -0
- data/app/static/openid-selector/images/livejournal.ico +0 -0
- data/app/static/openid-selector/images/myopenid.ico +0 -0
- data/app/static/openid-selector/images/openid-inputicon.gif +0 -0
- data/app/static/openid-selector/images/openid.gif +0 -0
- data/app/static/openid-selector/images/technorati.ico +0 -0
- data/app/static/openid-selector/images/verisign.gif +0 -0
- data/app/static/openid-selector/images/verisign.ico +0 -0
- data/app/static/openid-selector/images/vidoop.ico +0 -0
- data/app/static/openid-selector/images/wordpress.ico +0 -0
- data/app/static/openid-selector/images/yahoo.gif +0 -0
- data/app/static/openid-selector/js/jquery-1.2.6.min.js +32 -0
- data/app/static/openid-selector/js/openid-client/jquery.query-2.1.3.js +220 -0
- data/app/static/openid-selector/js/openid-client/openid-client-config.js +20 -0
- data/app/static/openid-selector/js/openid-client/openid-client.js +63 -0
- data/app/static/openid-selector/js/openid-jquery.js +240 -0
- data/app/static/openid-selector/openid-client/checkid_immediate_response.html +3 -0
- data/app/static/openid-selector/openid-client/checkid_setup_response.html +3 -0
- data/app/static/themes/default/users.css +947 -0
- data/app/static/themes/default/users.less +4 -0
- data/app/views/controllers/identities/enter_email_form.html.haml +6 -0
- data/app/views/controllers/identities/finish_email_registration_form.html.haml +23 -0
- data/app/views/controllers/identities/finish_open_id_registration_form.html.haml +12 -0
- data/app/views/controllers/identities/forgot_password_form.html.haml +6 -0
- data/app/views/controllers/identities/reset_password_form.html.haml +9 -0
- data/app/views/controllers/identities/update_password_form.html.haml +11 -0
- data/app/views/controllers/profiles/_form.html.haml +15 -0
- data/app/views/controllers/profiles/_roles.html.haml +6 -0
- data/app/views/controllers/profiles/_user.html.haml +24 -0
- data/app/views/controllers/profiles/actions.js.haml +12 -0
- data/app/views/controllers/profiles/all.html.haml +3 -0
- data/app/views/controllers/profiles/show.html.haml +1 -0
- data/app/views/controllers/sessions/_open_id_form.html.haml +16 -0
- data/app/views/controllers/sessions/_password_form.html.haml +13 -0
- data/app/views/controllers/sessions/login.html.haml +8 -0
- data/app/views/controllers/sessions/status.html.haml +1 -0
- data/app/views/themes/default/user.html.haml +8 -0
- data/app/views/users/_menu.html.haml +6 -0
- data/app/views/users/layout.html.haml +10 -0
- data/app/views/users/layout.js.haml +1 -0
- data/config/locales/en.yml +103 -0
- data/config/locales/ru.yml +105 -0
- data/config/routes.rb +18 -0
- metadata +71 -7
    
        data/Rakefile
    CHANGED
    
    
| @@ -0,0 +1,160 @@ | |
| 1 | 
            +
            class Identities < UserManagement
         | 
| 2 | 
            +
              # TODO3 filter password logging
         | 
| 3 | 
            +
              # filter_parameter_logging :password, :password_confirmation, :old_password
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              rad.extension :user_identities, self
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              before :login_required, only: [
         | 
| 8 | 
            +
                :update_password_form, :update_password,
         | 
| 9 | 
            +
                :destroy
         | 
| 10 | 
            +
              ]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              before :login_not_required, only: [
         | 
| 13 | 
            +
                :enter_email_form, :enter_email,
         | 
| 14 | 
            +
                :finish_email_registration_form, :finish_email_registration,
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                :finish_open_id_registration_form, :finish_open_id_registration,
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                :reset_password_form, :reset_password,
         | 
| 19 | 
            +
                :forgot_password_form, :forgot_password
         | 
| 20 | 
            +
              ]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              persist_params # only: [:finish_open_id_registration_form, :finish_open_id_registration]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              layout '/users/layout'
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              #
         | 
| 27 | 
            +
              # Email and Password
         | 
| 28 | 
            +
              #
         | 
| 29 | 
            +
              def enter_email_form
         | 
| 30 | 
            +
                @token = Models::User::EmailVerificationToken.new
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              allow_get_for :enter_email_form
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def enter_email
         | 
| 35 | 
            +
                @token = Models::User::EmailVerificationToken.new params.token
         | 
| 36 | 
            +
                @token.expires_at = 2.weeks.from_now
         | 
| 37 | 
            +
                if @token.save
         | 
| 38 | 
            +
                  UserMailer.email_verification(@token).deliver
         | 
| 39 | 
            +
                  flash.sticky_info = t :email_verification_code_sent, email: @token.email
         | 
| 40 | 
            +
                  redirect_to :follow_email_link
         | 
| 41 | 
            +
                else
         | 
| 42 | 
            +
                  render action: :enter_email_form
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def follow_email_link
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              allow_get_for :follow_email_link
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def finish_email_registration_form
         | 
| 51 | 
            +
                @token = Models::User::EmailVerificationToken.by_token params.token
         | 
| 52 | 
            +
                raise_user_error t(:invalid_email_verification_token) unless @token
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                @user = Models::User.new
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
              allow_get_for :finish_email_registration_form
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              def finish_email_registration
         | 
| 59 | 
            +
                @token = Models::User::EmailVerificationToken.by_token params.token
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                @user = Models::User.new
         | 
| 62 | 
            +
                @user.email = @token.email
         | 
| 63 | 
            +
                %w{name password password_confirmation}.each do |a|
         | 
| 64 | 
            +
                  @user.send "#{a}=", params.user[a] if params.user?
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                if @user.activate and @user.save
         | 
| 68 | 
            +
                  @token.destroy
         | 
| 69 | 
            +
                  flash.sticky_info = t :successfully_registered
         | 
| 70 | 
            +
                  redirect_to login_path #(_return_to: nil)
         | 
| 71 | 
            +
                else
         | 
| 72 | 
            +
                  render action: :finish_email_registration_form
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              def forgot_password_form
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
              allow_get_for :forgot_password_form
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              def forgot_password
         | 
| 81 | 
            +
                @email = params.email
         | 
| 82 | 
            +
                user = Models::User.first state: 'active', email: @email
         | 
| 83 | 
            +
                if user
         | 
| 84 | 
            +
                  token = Models::User::ForgotPasswordToken.create! user: user
         | 
| 85 | 
            +
                  UserMailer.forgot_password(token).deliver
         | 
| 86 | 
            +
                  flash.sticky_info = t :sucessfully_reset_password, email: @email
         | 
| 87 | 
            +
                  redirect_to default_path
         | 
| 88 | 
            +
                else
         | 
| 89 | 
            +
                  flash.sticky_error = t :failed_reset_password, email: @email
         | 
| 90 | 
            +
                  render action: :forgot_password_form
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              def reset_password_form
         | 
| 95 | 
            +
                @token = Models::User::ForgotPasswordToken.by_token params.token
         | 
| 96 | 
            +
                raise_user_error t(:invalid_reset_password_token) unless @token
         | 
| 97 | 
            +
                @user = @token.user
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
              allow_get_for :reset_password_form
         | 
| 100 | 
            +
             | 
| 101 | 
            +
              def reset_password
         | 
| 102 | 
            +
                @token = Models::User::ForgotPasswordToken.by_token params.token
         | 
| 103 | 
            +
                raise_user_error t(:invalid_reset_password_token) unless @token
         | 
| 104 | 
            +
                @user = @token.user
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                @user.password = params.user['password']
         | 
| 107 | 
            +
                @user.password_confirmation = params.user['password_confirmation']
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                if @user.save
         | 
| 110 | 
            +
                  @token.destroy
         | 
| 111 | 
            +
                  flash.sticky_info = t :password_restored
         | 
| 112 | 
            +
                  redirect_to login_path(_return_to: nil)
         | 
| 113 | 
            +
                else
         | 
| 114 | 
            +
                  render action: :reset_password_form
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
              def update_password_form
         | 
| 119 | 
            +
                @user = Models::User.current
         | 
| 120 | 
            +
                # render action: :update_password_form
         | 
| 121 | 
            +
              end
         | 
| 122 | 
            +
              allow_get_for :update_password_form
         | 
| 123 | 
            +
             | 
| 124 | 
            +
              def update_password
         | 
| 125 | 
            +
                @user = Models::User.current
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                if @user.update_password(params.user['password'], params.user['password_confirmation'], params.old_password) and @user.save
         | 
| 128 | 
            +
                  flash.sticky_info = t :password_updated
         | 
| 129 | 
            +
                  redirect_to default_path
         | 
| 130 | 
            +
                else
         | 
| 131 | 
            +
                  render action: :update_password_form
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
             | 
| 136 | 
            +
              #
         | 
| 137 | 
            +
              # Open Id
         | 
| 138 | 
            +
              #
         | 
| 139 | 
            +
              def finish_open_id_registration_form
         | 
| 140 | 
            +
                @user = Models::User.new
         | 
| 141 | 
            +
                @token = Models::SecureToken.by_token! params.token
         | 
| 142 | 
            +
              end
         | 
| 143 | 
            +
              allow_get_for :finish_open_id_registration_form
         | 
| 144 | 
            +
             | 
| 145 | 
            +
              def finish_open_id_registration
         | 
| 146 | 
            +
                @token = Models::SecureToken.by_token! params.token
         | 
| 147 | 
            +
                @user = Models::User.new
         | 
| 148 | 
            +
                @user.name = params.user['name']
         | 
| 149 | 
            +
                @user.open_ids << @token[:open_id]
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                if @user.activate and @user.save
         | 
| 152 | 
            +
                  @token.destroy
         | 
| 153 | 
            +
                  flash.sticky_info = t :successfull_open_id_registration
         | 
| 154 | 
            +
                  set_current_user_with_updating_session @user
         | 
| 155 | 
            +
                  redirect_to return_to_path_for_login
         | 
| 156 | 
            +
                else
         | 
| 157 | 
            +
                  render action: :finish_open_id_registration_form
         | 
| 158 | 
            +
                end
         | 
| 159 | 
            +
              end
         | 
| 160 | 
            +
            end
         | 
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            class Profiles < UsersApp
         | 
| 2 | 
            +
              prepare_model(
         | 
| 3 | 
            +
                Models::User, finder: :find_by_name,
         | 
| 4 | 
            +
                only: [:show, :edit, :update, :add_role, :remove_role]
         | 
| 5 | 
            +
              )
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # require_permission :view, only: :show do
         | 
| 8 | 
            +
              #   @user
         | 
| 9 | 
            +
              # end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              layout '/users/layout'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              helper Helpers::Users::Authorization
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              allow_get_for :all, :show, :edit
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def all
         | 
| 18 | 
            +
                @users = Models::User.all
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def show
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
             | 
| 25 | 
            +
              require_permission(:update_profile, only: [:edit, :update]){@user}
         | 
| 26 | 
            +
              def edit
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def update
         | 
| 30 | 
            +
                access_denied if @user.anonymous? and !Models::User.current.admin?
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                if @user.update_attributes params[:user]
         | 
| 33 | 
            +
                  flash[:info] = t :user_updated
         | 
| 34 | 
            +
                  # redirect_to action: :show
         | 
| 35 | 
            +
                else
         | 
| 36 | 
            +
                  render action: :edit
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              def add_role
         | 
| 41 | 
            +
                require_permission "add_#{params[:role]}_role"
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                @user.add_role params[:role]
         | 
| 44 | 
            +
                @user.save!
         | 
| 45 | 
            +
                @user.reload
         | 
| 46 | 
            +
                flash[:info] = t :role_granted
         | 
| 47 | 
            +
                render action: :update
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def remove_role
         | 
| 51 | 
            +
                require_permission "remove_#{params[:role]}_role"
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                @user.remove_role params[:role]
         | 
| 54 | 
            +
                @user.save!
         | 
| 55 | 
            +
                @user.reload
         | 
| 56 | 
            +
                flash[:info] = t :role_removed
         | 
| 57 | 
            +
                render action: :update
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              active_menu{:users}
         | 
| 61 | 
            +
            end
         | 
| @@ -0,0 +1,78 @@ | |
| 1 | 
            +
            class Sessions < UserManagement
         | 
| 2 | 
            +
              # TODO3 filter password logging
         | 
| 3 | 
            +
              # filter_parameter_logging :password
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              persist_params
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              include OpenIdAuthentication
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              rad.extension :user_sessions, self
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              before :login_not_required, only: :login
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              layout '/users/layout'
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              allow_get_for :login, :logout, :status
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def login
         | 
| 18 | 
            +
                if using_open_id?
         | 
| 19 | 
            +
                  open_id_authentication
         | 
| 20 | 
            +
                elsif request.post?
         | 
| 21 | 
            +
                  password_authentication
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def logout
         | 
| 26 | 
            +
                unless Models::User.current.anonymous?
         | 
| 27 | 
            +
                  set_current_user_with_updating_session Models::User.anonymous
         | 
| 28 | 
            +
                  flash.info = t :successfully_logged_out
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
                redirect_to return_to_path_for_logout
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def status; end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              protected
         | 
| 36 | 
            +
                def open_id_authentication
         | 
| 37 | 
            +
                  # params['return_to'] = request.url
         | 
| 38 | 
            +
                  # hack to save all url with :_return_to
         | 
| 39 | 
            +
                  # puts params['return_to']
         | 
| 40 | 
            +
                  # render action: 'new'
         | 
| 41 | 
            +
                  # return
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  # return_to = request.url.gsub("_ret")
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  authenticate_with_open_id nil, 'return_to' => request.url do |result, identity_url, registration|
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    if result.successful?
         | 
| 48 | 
            +
                      if @user = Models::User.authenticate_by_open_id(identity_url)
         | 
| 49 | 
            +
                        set_current_user_with_updating_session @user
         | 
| 50 | 
            +
                        flash.info = t :successfully_logged_in
         | 
| 51 | 
            +
                        redirect_to return_to_path_for_login
         | 
| 52 | 
            +
                      else
         | 
| 53 | 
            +
                        token = Models::SecureToken.new
         | 
| 54 | 
            +
                        token[:open_id] = identity_url
         | 
| 55 | 
            +
                        token.save!
         | 
| 56 | 
            +
                        flash.sticky_info = t :successfully_identified_by_open_id
         | 
| 57 | 
            +
                        redirect_to finish_open_id_registration_form_identities_path(token: token.token)
         | 
| 58 | 
            +
                      end
         | 
| 59 | 
            +
                    else
         | 
| 60 | 
            +
                      flash.error = result.message || t(:invalid_identity, identity: identity_url)
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def password_authentication
         | 
| 67 | 
            +
                  if @user = Models::User.authenticate_by_password(params.name, params.password)
         | 
| 68 | 
            +
                    set_current_user_with_updating_session @user
         | 
| 69 | 
            +
                    flash.info = t :successfully_logged_in
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    redirect_to return_to_path_for_login
         | 
| 72 | 
            +
                  else
         | 
| 73 | 
            +
                    @errors = t :invalid_login
         | 
| 74 | 
            +
                    @name = params.name
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            class UserMailer
         | 
| 2 | 
            +
              inherit Rad::Mailer::MailerController
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              def email_verification token
         | 
| 5 | 
            +
                @to = token.email
         | 
| 6 | 
            +
                @from = rad.users.email
         | 
| 7 | 
            +
                @subject = t :email_verification_title, host: rad.users.host
         | 
| 8 | 
            +
                # sent_on Time.now
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                @body = t(
         | 
| 11 | 
            +
                  :email_verification_text,
         | 
| 12 | 
            +
                  host: rad.users.host,
         | 
| 13 | 
            +
                  url: finish_email_registration_form_identities_path(host: rad.users.host, token: token.token)
         | 
| 14 | 
            +
                )
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def forgot_password token
         | 
| 18 | 
            +
                @to = token.user.email
         | 
| 19 | 
            +
                @from = rad.users.email
         | 
| 20 | 
            +
                @subject = t :forgot_password_title, name: token.user.name, host: rad.users.host
         | 
| 21 | 
            +
                # sent_on Time.now
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                @body = t(
         | 
| 24 | 
            +
                  :forgot_password_text,
         | 
| 25 | 
            +
                  name: token.user.name,
         | 
| 26 | 
            +
                  host: rad.users.host,
         | 
| 27 | 
            +
                  url: reset_password_form_identities_path(host: rad.users.host, token: token.token)
         | 
| 28 | 
            +
                )
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,65 @@ | |
| 1 | 
            +
            module Authorization
         | 
| 2 | 
            +
              def roles_control_links_for user
         | 
| 3 | 
            +
                links = []
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # Ordered Roles
         | 
| 6 | 
            +
                %w{member manager}.each do |role|
         | 
| 7 | 
            +
                  unless user.roles.include? role
         | 
| 8 | 
            +
                      if can? "add_#{role}_role"
         | 
| 9 | 
            +
                        links << add_role_link(t("add_#{role}_role"), user, role)
         | 
| 10 | 
            +
                      end
         | 
| 11 | 
            +
                    else
         | 
| 12 | 
            +
                    text = t(role)
         | 
| 13 | 
            +
                    if can? "remove_#{role}_role"
         | 
| 14 | 
            +
                      link = remove_role_link(t("remove_#{role}_role"), user, role)
         | 
| 15 | 
            +
                      links << "#{text} (#{link})"
         | 
| 16 | 
            +
                    else
         | 
| 17 | 
            +
                      links << text
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                # Custom Roles
         | 
| 23 | 
            +
                rad.config.custom_roles.each do |role|
         | 
| 24 | 
            +
                  unless user.roles.include? role
         | 
| 25 | 
            +
                      if can? "add_custom_role"
         | 
| 26 | 
            +
                        links << add_role_link(t(:add_custom_role, role: role), user, role)
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    else
         | 
| 29 | 
            +
                    text = t(:custom_role, role: role)
         | 
| 30 | 
            +
                    if can? "remove_custom_role"
         | 
| 31 | 
            +
                      link = remove_role_link(t(:remove_custom_role, role: role), user, role)
         | 
| 32 | 
            +
                      links << "#{text} (#{link})"
         | 
| 33 | 
            +
                    else
         | 
| 34 | 
            +
                      links << text
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                # Admin Roles
         | 
| 40 | 
            +
                unless user.roles.include? 'admin'
         | 
| 41 | 
            +
                    if can? "add_admin_role"
         | 
| 42 | 
            +
                      links << add_role_link(t(:add_admin_role), user, 'admin')
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  else
         | 
| 45 | 
            +
                  text = t(:admin)
         | 
| 46 | 
            +
                  if can? "remove_admin_role"
         | 
| 47 | 
            +
                    link = remove_role_link(t(:remove_admin_role), user, 'admin')
         | 
| 48 | 
            +
                    links << "#{text} (#{link})"
         | 
| 49 | 
            +
                  else
         | 
| 50 | 
            +
                    links << text
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                links
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              protected
         | 
| 58 | 
            +
                def add_role_link text, user, role
         | 
| 59 | 
            +
                  link_to text, add_role_profile_path(user, role: role, format: :js), method: :post
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                def remove_role_link text, user, role
         | 
| 63 | 
            +
                  link_to text, remove_role_profile_path(user, role: role, format: :js), method: :post
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # TODO3 'unite this with SaaS '
         | 
| 2 | 
            +
            module General
         | 
| 3 | 
            +
              def main_menu
         | 
| 4 | 
            +
                @@menu ||= [
         | 
| 5 | 
            +
                  # [:home, all_pages_path],
         | 
| 6 | 
            +
                  # [:accounts, all_accounts_path, :global_administration],
         | 
| 7 | 
            +
                  [:users, all_profiles_path],
         | 
| 8 | 
            +
                ]
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                unless @active_menu.blank?
         | 
| 11 | 
            +
                  (@@menu.collect do |key, link, permission|
         | 
| 12 | 
            +
                    unless permission and !can?(permission)
         | 
| 13 | 
            +
                      [t(key), link, key == @active_menu]
         | 
| 14 | 
            +
                    else
         | 
| 15 | 
            +
                      nil
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end).compact
         | 
| 18 | 
            +
                else
         | 
| 19 | 
            +
                  []
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         |