Module UsersHelper
In: app/helpers/users_helper.rb
File:users_helper.rb
(C):Hipposoft 2008, 2009
Purpose:Support functions for views related to User objects. See controllers/users_controller.rb for more.

          03-Jan-2008 (ADH): Created.

Methods

Public Instance methods

Return list actions appropriate for the given user

[Source]

     # File app/helpers/users_helper.rb, line 170
170:   def userhelp_actions( user )
171:     actions = [ 'edit' ]
172:     actions.push( 'delete' ) unless user.admin?
173:     actions.push( 'show' )
174:     return actions
175:   end

Output HTML for the given form and user which produces a selection list allowing the user‘s ‘active’ flag to be changed. It is assumed that the caller has permission to edit the user in this way.

[Source]

    # File app/helpers/users_helper.rb, line 80
80:   def userhelp_active_selector( form, user )
81:     return apphelp_select(
82:       form,
83:       :active,
84:       [
85:         [ 'Active',      true  ],
86:         [ 'Deactivated', false ]
87:       ],
88:       false
89:     )
90:   end

Output HTML for the given control panel form (fields_for…) and user which lets the user choose the default customer associated with new projects.

The including template should use appropriate container tags for the output (e.g. a paragraph or table cell).

[Source]

     # File app/helpers/users_helper.rb, line 131
131:   def userhelp_default_customer_selector( cp, user )
132:     customers = Customer.active
133: 
134:     unless( customers.empty? )
135:       output = apphelp_collection_select( cp, :customer_id, customers, :id, :title, false )
136: 
137:       if( user.restricted? )
138:         output << "\n\n"
139:         output << "          <p>\n"
140:         output << "            This list is only relevant to users with a\n"
141:         output << "            privileged account type because normal users\n"
142:         output << "            cannot create new tasks.\n"
143:         output << "          </p>"
144:       end
145:     else
146:       output  = "          There are no active customers. Please\n"
147:       output << "          #{ link_to( 'create at least one', new_customer_path() ) }."
148:     end
149: 
150:     return output
151:   end

Output HTML for the given user‘s control panel editing section within a wider user editing form, which lets the user choose the default project associated with new tasks.

The including template should use appropriate container tags for the output (e.g. a paragraph or table cell).

[Source]

     # File app/helpers/users_helper.rb, line 99
 99:   def userhelp_default_project_selector( user )
100:     unless( Project.active.count.zero? )
101:       output = apphelp_project_selector(
102:         'control_panel_project_id',
103:         'control_panel[project_id]',
104:         user.control_panel.nil? ? nil : user.control_panel.project_id,
105:         true
106:       )
107: 
108:       if( user.restricted? )
109:         output << "\n\n"
110:         output << "          <p>\n"
111:         output << "            This list is only relevant to users with a\n"
112:         output << "            privileged account type because normal users\n"
113:         output << "            cannot create new tasks.\n"
114:         output << "          </p>"
115:       end
116:     else
117:       output  = "          There are no active projects. Please\n"
118:       output << "          #{ link_to( 'create at least one', new_project_path() ) }."
119:     end
120: 
121:     return output
122:   end

List view helper - format the given user‘s e-mail address as a link; do so using auto_link so we don‘t have to worry about malformed addresses. That‘s the main reason for doing this in a helper rather than manually, within the model.

[Source]

     # File app/helpers/users_helper.rb, line 158
158:   def userhelp_email( user )
159:     return auto_link( h( user.email ) )
160:   end

As above, but for the user‘s identity URL

[Source]

     # File app/helpers/users_helper.rb, line 164
164:   def userhelp_identity_url( user )
165:     return auto_link( h( user.identity_url ) )
166:   end

Output HTML for the given form and user which produces a selection list allowing the user account type to be chosen. It is assumed that the caller has permission to edit the user in this way.

The including template should use appropriate container tags for the output (e.g. a paragraph or table cell).

[Source]

    # File app/helpers/users_helper.rb, line 20
20:   def userhelp_user_type_selector( form, user )
21:     if ( @current_user.id == user.id and user.admin? )
22: 
23:       # You can't change your own account type if you are an administrator.
24:       # This is an easy way to prevent all administrators losing privilege,
25:       # leaving no administrator in the system.
26: 
27:       output  = "          Administrators cannot change account type. If you\n"
28:       output << "          want to stop being an administrator, first assign\n"
29:       output << "          administrative rights to another account, then\n"
30:       output << "          have that user change your account type for you."
31: 
32:     elsif ( not @current_user.admin? and user.admin? )
33: 
34:       # If the editing account is administrative but the user is not,
35:       # then the account type can't be changed (managers can only assign
36:       # privilege up to manager).
37: 
38:       output  = "          Administrator. Only another administrator can change\n"
39:       output << "          this user's account type.\n"
40: 
41:     else
42: 
43:       # OK, this is your account and you're not an administrator, or
44:       # it is someone else's account and they're not an administrator.
45: 
46:       if ( @current_user.admin? )
47:         warn    = false
48:         options = [
49:                     [ 'Normal',        'Normal'  ],
50:                     [ 'Manager',       'Manager' ],
51:                     [ 'Administrator', 'Admin'   ]
52:                   ]
53:       else
54:         warn    = true
55:         options = [
56:                     [ 'Normal',  'Normal'  ],
57:                     [ 'Manager', 'Manager' ]
58:                   ]
59:       end
60: 
61:       output = apphelp_select( form, :user_type, options, false )
62: 
63:       if ( warn and @current_user.id == user.id )
64:         output << "\n\n"
65:         output << "          <p>\n"
66:         output << "            Note that if you revoke your own account privileges,\n"
67:         output << "            you will need the help of another manager or an\n"
68:         output << "            administrator if you want to restore them later.\n"
69:         output << "          </p>"
70:       end
71:     end
72: 
73:     return output
74:   end

[Validate]