Project

General

Profile

HowTo access Custom_Field

Added by Tiemo Vorschuetz almost 14 years ago

Hi,

I am new here, a newbie in ruby and hope to get some answers for my concerns.

What I am looking for:
I created a boolean Custom_Field for users "Projectcreator" and assigned it to a user. Now I would like to access the value of this field from inside the redmine/app/views/projects/index.rhtml to modify the behavior of being able to create a new project.

Can anybody of you be so kind and explain in detail how to do that?

Thanks a lot
Tiemo


Replies (4)

RE: HowTo access Custom_Field - Added by James Bernard almost 14 years ago

Hi Tiemo,

I would do it like that:

custom_value = User.Current.custom_value_for(custom_field_id)
is_project_creator = custom_value.nil ? false : custom_value.true?

In the above code, custom_field_id is "Projectcreator" custom field ID, you can either hardcode it or get it by its name from CustomField model.

However what prevents you from using instead the "create projects" permission in roles and permissions ?

RE: HowTo access Custom_Field - Added by Tiemo Vorschuetz almost 14 years ago

Hi James,

thanks for the reply. I will give it a try.

The usecase I would like to cover up is as followed:

a) Redmine is setup to use SVN as the SCM system
b) Redmine should be the platform for internal and external customizing projects
c) Each project will have its own svn repository
d) A group of users should be able to create new projects to get a svn repository for their data
e) The admin should have the ability to simply add users to the group "project creators" independend whether they are already part of a project or not
f) The admin should be able to simply remove a user from this group to demote permissions for creating new projects

IMHO this cannot be done out-of-the-box even if many people have already asked for in several threads.

In my opinion setting up the permission to create projects within a role does not help in this case because the role is assigned to the user within a project and not globaly. So if I could suggest how it can be done the permission within a role should be used to manage the permissions for creating sub projects from inside the project the role is belonging to or used in only. A global right to add new root projects should be part of the global user settings and of the global group settings.

So I am looking for the possibility to adjust the behavoir on the highest level.

What do you think? Any ideas are very welcome.

Thanks
Tiemo

RE: HowTo access Custom_Field - Added by James Bernard almost 14 years ago

Thanks for the detailed explanation, I got it now.

So it looks like you need something similar to the "Administrator" flag of user properties.
I can't see a way to do that other than adding a property to users, and that's what you try to do.

If you persist in tuning the core code, I would maybe only suggest that you don't rely on a custom field because the core code is not supposed to assume that a particular custom field exists. You could instead try to implement a new property directly in User model (same as Administrator flag). This is not complex and basically consists in writing the migration file (to add a column to users table) and adding a checkbox to the user properties form, the rest should be automatic.

RE: HowTo access Custom_Field - Added by Tiemo Vorschuetz almost 14 years ago

Hi James,

just a feedback.

I decided to add a column to the users table called "projectcreator" as you suggested and modified several files to get this working.
Additionally I extended the "create project" functionality to copy the content (Wiki, etc except the repository) from a "template" project by default. This was needed to run the plugin "backlogs" with the expected wiki.

I attached a patch for this. Hope there is nothing missing in it.

Feel free to use it.

Regards
Tiemo

    (1-4/4)