how to

Added by Tim Aleinikoff over 11 years ago

Thank you for redmine, guys.
I try to customize different views and actions for stuff and clients.

For example in new_issue dialogue my clients can see only status and date fields.
For this goal I add string

<%if User.current.allowed_to?(:delete_issues, @project) %>
to app/views/issues/_form
Delete_issues used as flag - user is stuff member.
<div class="splitcontentleft">
<% if @issue.new_record? || @allowed_statuses.any? %>
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
<% else %>
<p><label><%= l(:field_status) %></label> <%= @issue.status.name %></p>
<% end %>
<%if User.current.allowed_to?(:delete_issues, @project) %>
<p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p>
<p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}) %></p>
<% unless @project.issue_categories.empty? %>
<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
<%= prompt_to_remote(l(:label_issue_category_new),
l(:label_issue_category_new), 'category[name]',
{:controller => 'projects', :action => 'add_issue_category', :id => @project},
:class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p>
<% end %>
<% end %>
<%= content_tag('p', f.select(:fixed_version_id,
(@project.versions.sort.collect {|v| [v.name, v.id]}),
{ :include_blank => true })) unless @project.versions.empty? %>
</div>

Help me plz. How to write this construction on Ruby.
"if current_user.boolean_custom_field.value = 1 than"
or
"case current_user.list_custom_field
1st_value do ...
2nd_value do ..."

Now, i wanna to customize actions with issues.
For example: when current_user=client make New Issue i wanna to assign it to service-manager, but if current_user=stuff, skip default assignment.

Default assigment i have done in app/models/issue

  def after_initialize
    if new_record?
      # set default values for new records only
      self.status ||= IssueStatus.default
      self.priority ||= Enumeration.default('IPRI')
#   if .....
      self.assigned_to ||= User.find_by_id(1)
#   end
    end
  end