Project

General

Profile

find users manager

Added by srinath A over 13 years ago

How to find the manager for a user in the project . I didnt found any relationship in tables .

thanks.


Replies (11)

RE: find users manager - Added by Felix Schäfer over 13 years ago

What are you trying to do?

RE: find users manager - Added by srinath A over 13 years ago

Hi Felix,

I was trying to customize code according to my requirement .
I need to show users assigned to Manager(if logged in user is in Manager role).

Used :
role = Role.find(:first, :conditions => {:name => "Manager"})

But this is not correct writing role name hardcoded here .

How to find role name dynamically instead using hard coded ? I was not providing any params from page

thanks in advance.

RE: find users manager - Added by Felix Schäfer over 13 years ago

Role.find_by_name("Manager") is the best you can do, the name of the Role being totally configurable.

RE: find users manager - Added by srinath A over 13 years ago

Felix Schäfer,
Yeah, Initially the got the same idea . but if we edit "Manager" to "Manager1" , how can we change dynamically in code line .
Sorry if was bad understood .

RE: find users manager - Added by Felix Schäfer over 13 years ago

Then Role.find_by_id(1) or whatever, but you can't do it "automatically", you have to store that relation somewhere, and if you don't want to hardcode it, you'll need a setting pane somewhere.

RE: find users manager - Added by srinath A over 13 years ago

yeah right, thank you for the answers Felix,

RE: find users manager - Added by srinath A over 13 years ago

Felix,

I had roles like "Manager" and "Developer" .

For checking admin we are using is_admin?
Could you please help me how to find the logged in user is having role "Manager" or not ?

thanks.

RE: find users manager - Added by Felix Schäfer over 13 years ago

User.current.is_admin?

RE: find users manager - Added by srinath A over 13 years ago

yeah, In my case admin differs from Manager .
But how can i find the logged in user is having role "Manager" or not ?

RE: find users manager - Added by Felix Schäfer over 13 years ago

Oh, sorry, misread you. Anyway, I won't answer one-off question like that for long, you should either delve into the code yourself or hire a consultant if you have difficulties getting it done by yourself.

One way would be:

User.current.roles_for_project(Project.find(1)).include?(Role.find_by_name("Manager"))

Replace Project.find(1) with a variable containing your current project, and so on.

RE: find users manager - Added by srinath A over 13 years ago

thanks felix for answers

    (1-11/11)