annikoff / redmine_plugin_computed_custom_field

Computed Custom Field for Redmine
https://www.redmine.org/plugins/computed_custom_field
MIT License
80 stars 51 forks source link

Is it possible to add to your custom field current user value #103

Closed Warlib1975 closed 7 years ago

Warlib1975 commented 7 years ago

Hi,

is it possible to add current user name (who authorized) as value for your custom fields.

There is plugins http://www.redmine.org/plugins/assign_current_user, but its too simple and work only with one field.

Thank you.

annikoff commented 7 years ago

Hi. Try to use user field format and put this code in formula field User.current.id

Warlib1975 commented 7 years ago

Hi,

cool! It works! Thank you.

Is it possible to "freeze" this field corresponding state and/or tracker? E.g. supporter with specific role (e.g. tester) change tracker to "Testing" and change state to "New testing" and pickup issue to workout. I need to fill field "Tested by:" with value of current user. Then approver change tracker to "Approve" and change the state to "Start approving" and gets the issue. And field "Approved by" should be filled by current user value, but the field "Tested by" should be "freezed". Then state can be returned back to Tracker "Testing" and new tester test the issue and in this case the new value should be place to field "Tested by:".

Thank you.

annikoff commented 7 years ago

In "Tested by" field you should check if the current user has role "Tester":

if User.current.roles_for_project(project).include? TESTER_ROLE_ID
  User.current.id
else
  custom_field_value TESTED_BY_CF_ID
end 

In "Approved by" field you should check if the current user has role "Approver":

if User.current.roles_for_project(project).include? APPROVER_ROLE_ID
  User.current.id
else
  custom_field_value APPROVED_BY_CF_ID
end 
Warlib1975 commented 7 years ago

Hi,

thank you. That's perfect. Could you explain how I can get ID of statuses or roles?

Thank you.

annikoff commented 7 years ago

http://yourhost/roles http://yourhost/issue_statuses

Warlib1975 commented 7 years ago

Thank you. I thought that TESTER_ROLE_ID and APPROVER_ROLE_ID - it's unique database ID, but not symbolic name. So, in case of renaming statuses or roles calculated custom field will stop working. :-(

Warlib1975 commented 7 years ago

How to get the current issue status? I would like to change calculated custom field if user change status to some specific value.

annikoff commented 7 years ago

If you rename a custom field its ID does not change. Issue has a field status_id.

Warlib1975 commented 7 years ago

Hm, at the page http://yourhost/roles only symbolic names of roles. E.g. if I make expression

if User.current.roles_for_project(project).include? 'Tester' User.current.id end

it doesn't work and I don't know how to debug it. :-(

annikoff commented 7 years ago

_010 I made a mistake in a previous formula.

# In my case Tester role ID is 4
if User.current.roles_for_project(project).map(&:id).include? 4
  User.current.id
end
Warlib1975 commented 7 years ago

Hi,

Thank you. Now I understand.

Is it possible to get info concerning current status? If I use expression Issue.status_id I immediately get error: undefined method `status_id' for #

annikoff commented 7 years ago

Hi. status_id is not a class method, it is an instance method. In the formulas for IssueCustomField you should use just status_id or self.status_id.

Warlib1975 commented 7 years ago

Hi,

thank you. Now everything works perfect.

annikoff commented 7 years ago

You're welcome. If you have no more questions, please close the issue.

Warlib1975 commented 7 years ago

One another thing. If I use expression if self.status_id == 10 User.current.id end

Practically everything works ok, except one thing, if the condition is false, the custom field value is emptied. As far as I understand I should return current value of custom field, but I don't know how to gets it.

if self.status_id == 10 User.current.id else .. end

Thank you.

Warlib1975 commented 7 years ago

I found the solution, but not perfect, I think

if self.status_id == 10 User.current.id else cfs[23] end

where 23 - is id of the current custom field. It would be nice to get current value of the custom field without using ID, or get current custom ID.

annikoff commented 7 years ago

Your solution is correct.

Warlib1975 commented 7 years ago

Thank you

The solution is described here: http://www.bizkit.ru/2017/07/19/4582/