redmine_custom_workflows icon indicating copy to clipboard operation
redmine_custom_workflows copied to clipboard

How to change the assignee to their group

Open ashrafalzyoud opened this issue 2 years ago • 7 comments

Hi all What the code if the user create issue the assignee her group

ashrafalzyoud avatar Jan 27 '23 02:01 ashrafalzyoud

Hi,

There is a logic error in this request. If I understand correctly, the request is that if a user creates an issue, the issue assignee should be the group of which the user is a member.

The problem with this is that a user can be a member of several groups, if a user is in 3 groups, which group should be assigned to the issue as assignee?

The code below assigns the first group in which the user who created the issue is included:


self.assigned_to = User.current.groups.first

I hope it helps!

AirTibu avatar Jan 28 '23 01:01 AirTibu

how i can choose (assigned_to_id) from array and this group_id and each group_id for only one project in my case

if [1, 3, 7, 8, 18, 12, 10, 6, 55, 13]  include?(status_id)
self.assigned_to = [149, 25, 27, 34, 46, 9, 18, 20, 24, 15, 14, 53] .include?(assigned_to_id)
end

the answer is one form assigned _to_id ,and this id its currently member in project thx @AirTibu for your help

ashrafalzyoud avatar Jan 28 '23 10:01 ashrafalzyoud

@AirTibu any news

ashrafalzyoud avatar Jan 31 '23 21:01 ashrafalzyoud

How I can choosing the first option group

ashrafalzyoud avatar May 05 '23 12:05 ashrafalzyoud

Hi,

I'm not sure if I understand your intent correctly, but if everything is correct, you want this:

  1. You have a user, who is the assignee.
  2. Find this user's group, which group is a member of this project
  3. Add this group to the issue as assignee

If so, then use this code


self.assigned_to_id =  = (Project.find(self.project_id).principals.pluck(:id) & User.find(assigned_to_id).group_ids).first  if assigned_to_id && project_id

I hope it helps!

AirTibu avatar May 11 '23 19:05 AirTibu

Thx for replying me In my case The user assigned for another group he not member

I'm using the JavaScript to choose first option in list groups But I need it in custom work flow

If status id 1 then assigned to id ( First option in list groups)

$('#issue_assigned_to_id').val($('#issue_assigned_to_id > optgroup > option:nth-child(1)').val());

ashrafalzyoud avatar May 11 '23 19:05 ashrafalzyoud

Hi,

Ok, I understand now. Try this code:


@my_group_ids = [149, 25, 27, 34, 46, 9, 18, 20, 24, 15, 14, 53] 

@group_to_assignee = @my_group_ids.index(status_id.to_i)

self.assigned_to = Group.find(@group_to_assignee.to_i) unless @group_to_assignee.nil?


I hope it helps!

AirTibu avatar May 12 '23 08:05 AirTibu