Created
April 22, 2009 19:11
-
-
Save edavis10/99990 to your computer and use it in GitHub Desktop.
Changing or creating a User's Role in Redmine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Changing the current user's Role | |
def change_role(role, project) | |
# User logged in? | |
if User.current.logged? | |
# Will get the existing Member object or a new one if the User isn't yet a Member of the project | |
member = Member.find_or_initialize_by_user_id_and_project_id(User.current, project.id) | |
member.role = role | |
member.project = project | |
if member.save | |
# Successfully saved | |
else | |
# Had an error saving. Should inform the user and recover. | |
end | |
end | |
end | |
change_role(Project.find(params[:project_id]), Role.find(42)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment