Author: tchemit Date: 2012-10-02 18:20:19 +0200 (Tue, 02 Oct 2012) New Revision: 331 Url: http://nuiton.org/repositories/revision/jredmine/331 Log: fixes #2330: Make jredmine plugins works with both redmine 1.x and 2.x Added: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-1.x.xml branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-2.x.xml branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-1.x/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/README.rdoc branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/helpers/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/models/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/views/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/assets/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/assets/images/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/assets/javascripts/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/assets/stylesheets/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/routes.rb branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/db/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/db/migrate/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/init.rb branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/en.yml branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lib/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lib/tasks/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/test/ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/test/functional/ Removed: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails.xml branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine/ Modified: branches/jredmine-1.x/jredmine-client/pom.xml branches/jredmine-1.x/jredmine-client/src/site/apt/index.apt branches/jredmine-1.x/jredmine-client/src/site/site_fr.xml branches/jredmine-1.x/src/site/apt/index.apt branches/jredmine-1.x/src/site/site_fr.xml Modified: branches/jredmine-1.x/jredmine-client/pom.xml =================================================================== --- branches/jredmine-1.x/jredmine-client/pom.xml 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/jredmine-client/pom.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -122,7 +122,8 @@ <properties> <!-- extra files to include in release --> <redmine.releaseFiles> - target/${project.artifactId}-${project.version}-jredmine_rails.zip, + target/${project.artifactId}-${project.version}-jredmine_rails-1.x.zip, + target/${project.artifactId}-${project.version}-jredmine_rails-2.x.zip, ${redmine.libReleaseFiles} </redmine.releaseFiles> </properties> @@ -217,7 +218,8 @@ <descriptorRef>full</descriptorRef> </descriptorRefs> <descriptors> - <descriptor>src/main/assembly/jredmine_rails.xml</descriptor> + <descriptor>src/main/assembly/jredmine_rails-1.x.xml</descriptor> + <descriptor>src/main/assembly/jredmine_rails-2.x.xml</descriptor> </descriptors> </configuration> </plugin> Copied: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-1.x.xml (from rev 326, branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails.xml) =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-1.x.xml (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-1.x.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,40 @@ +<!-- + #%L + JRedmine :: Client + + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<assembly> + <id>jredmine_rails-1.x</id> + <formats> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>src/main/redmine/jredmine-1.X</directory> + <outputDirectory>jredmine</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file Property changes on: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-1.x.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-2.x.xml =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-2.x.xml (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-2.x.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,40 @@ +<!-- + #%L + JRedmine :: Client + + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<assembly> + <id>jredmine_rails-2.x</id> + <formats> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>src/main/redmine/jredmine-2.x</directory> + <outputDirectory>jredmine</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file Property changes on: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails-2.x.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails.xml =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails.xml 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/jredmine-client/src/main/assembly/jredmine_rails.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -1,40 +0,0 @@ -<!-- - #%L - JRedmine :: Client - - $Id$ - $HeadURL$ - %% - Copyright (C) 2009 - 2010 CodeLutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> -<assembly> - <id>jredmine_rails</id> - <formats> - <format>zip</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <directory>src/main/redmine/jredmine</directory> - <outputDirectory>jredmine</outputDirectory> - <includes> - <include>**/*</include> - </includes> - </fileSet> - </fileSets> -</assembly> \ No newline at end of file Added: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/README.rdoc =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/README.rdoc (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/README.rdoc 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,38 @@ += rest + +This plugin expose some services via a the REST protocol: + +jredmine/get_projects +jredmine/get_issue_statuses +jredmine/get_issue_priorities + +jredmine/get_project/X + +jredmine/get_project_trackers/X +jredmine/get_project_issue_categories/X +jredmine/get_project_users/X +jredmine/get_project_versions/X + +jredmine/get_version/X?version_name=Y +jredmine/get_version_issues/X?version_name=Y +jredmine/get_version_attachements/X?version_name=Y + +jredmine/add_version/X?version_name=Y +jredmine/update_version/X?version_name=Y + +jredmine/add_news/X?version_name=Y +jredmine/add_attachment/X?version_name=Y + +where X is a project identifier and Y a version name + += install + +To install the plugin, just put it in the plugins directory and restart the redmine (or apache) + += configure + +Once the plugin is available in the forge, you can configure for each project +if you want to expose jredmine service. + + + Property changes on: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/README.rdoc ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,567 @@ +### +# #%L +# JRedmine :: Client +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +class JredmineController < ActionController::Base + + # post request + before_filter :check_post, :only => [:add_version, :update_version, :next_version, :add_news, :add_attachment, :add_version_attachment, :add_issue_time, :update_issue_time] + + # find user (after login) + before_filter :find_user, :only => [:get_user_projects, :add_version, :update_version, :next_version, :add_news, :add_attachment, :add_version_attachment, :add_issue_time, :update_issue_time] + + # find project and check permission + before_filter :find_project, :except => [:ping, :login, :logout, :get_projects, :get_user_projects, :get_issue_statuses, :get_issue_priorities, :get_enumeration] + + # find project's version + before_filter :find_version, :only => [:get_version, :get_version_issues, :get_version_opened_issues, :get_version_attachments, :add_version_attachment] + + # check version definition is ok in request + before_filter :check_version_definition, :only => [:add_version, :update_version, :next_version] + + # find project's issue + before_filter :find_issue, :only => [:get_issue_times, :add_issue_time, :update_time_issue] + + # ping service (just to test if service is reachable) + def ping + render :text => "ping", :status => 200 + end + + # Login request and validation + def login + if !request.post? + # Logout user : get method not possible + self.logged_user = nil + render_status 405, "POST method required" + else + # Authenticate user + user = User.try_to_login(params[:username], params[:password]) + if user.nil? + # Invalid credentials + render_status 401, "Invalid credentials" + elsif user.new_record? + # Onthefly creation failed, + render_status 401, "User not activated" + else + # Valid user + self.logged_user = user + # always generate a key and set autologin cookie + token = Token.create(:user => user, :action => 'autologin') + cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now } + render_status 200, "User logged in" + end + end + end + + # Log out current user and redirect to welcome page + def logout + cookies.delete :autologin + Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged? + # user is no more connected + self.logged_user = nil + render_status 200, "User logged out" + end + + # recuperation des projets + def get_projects + @projects = Project.find(:all) + render_array_result @projects, "projects" + end + + # recuperation des projets dont l'utilisateur connecte est membre + def get_user_projects + projectsIds = User.current.memberships.collect{|m| m.project_id} + result = [] + for id in projectsIds + p = @project = Project.find(id) + result << p + end + render_array_result result, "projects" + end + + # recuperation des priorities d'issues + def get_issue_priorities + get_enumeration "IssuePriority" + end + + # recuperation des differentes categories d'issues + def get_issue_categories + @issue_categories = @project.issue_categories.find(:all) + render_array_result @issue_categories, "issue-categories" + end + + # recuperation des differentes statuts d'issues + def get_issue_statuses + @issue_status = IssueStatus.find(:all) + render_array_result @issue_status, "issue-statuses" + end + # recuperation du projet + def get_project + render_result @project + end + + # recuperation de tous les membres d'un projet + def get_project_users + @members = @project.members.find(:all) + @r = [] + for m in @members + u = User.find(m[:user_id]) + u[:role_id] = m[:role_id] + u[:member_id] = m[:id] + #TODO - should remove the hashed password ? + @r << u + end + render_array_result @r, "users" + end + + # recuperation de toutes les annonces d'un projet + def get_project_news + @news = @project.news.find(:all) + render_array_result @news, "news" + end + + # recuperation des trakers d'un projet + def get_project_trackers + @trackers = @project.trackers.find(:all) + render_array_result @trackers, "trackers" + end + + # recuperation des versions d'un projet + def get_project_versions + @versions = @project.versions.find(:all) + render_array_result @versions, "versions" + end + + # recuperation de toutes les issues d'un projet + def get_project_issues + r =@project.issues.find(:all) + render_array_result r, "issues" + end + + # recuperation de toutes les issues ouvertes d'un projet + def get_project_opened_issues + r = [] + for i in @project.issues.find(:all) + if !i.closed? && i.status_id != 3 + r << i + end + end + render_array_result r, "issues" + end + + # recuperation de toutes les issues fermees d'un projet + def get_project_closed_issues + r = [] + for i in @project.issues.find(:all) + if i.closed? || i.status_id == 3 + r << i + end + end + render_array_result r, "issues" + end + + # recuperation des temps d'une issue + def get_issue_times + render_array_result @issue.time_entries, "time-entries" + end + + # recuperation de la version d'un projet + def get_version + render_result @version + end + + # recuperation des issues d'un projet pour une version donnee + def get_version_issues + @issues = @version.fixed_issues.find(:all) + render_array_result @issues, "issues" + end + + # recuperation des issues ouvertes d'un projet pour une version donnee + def get_version_opened_issues + issues = @version.fixed_issues.find(:all) + result = [] + issues.each do |issue| + if !issue.closed? && issue.status_id != 3 + result << issue + end + end + render_array_result result, "issues" + end + + # recuperation des pieces jointes d'un projet pour une version donnee + def get_version_attachments + @files = @version.attachments.find(:all) + render_array_result @files, "attachments" + end + + def show_permissions + allowed_permissions + render_result @allowed_permissions + end + + def show_actions + allowed_actions + render_result @allowed_actions + end + + # add a new version for a given project + def add_version(version = params["version"]) + @version = @project.versions.find_by_name(version[:name]) + if @version + # version already exists + render_status 505, "Version #{@version.name} already exists for project #{@project.name}, can not create it" + return false + end + allowed = User.current.allowed_to?(:manage_versions, @project) + if !allowed + render_status 401, "No permission to add a version in project #{@project.name}" + return false + end + + # create the new version + @version = Version.create(:project => @project, :name => version[:name]) + + # do update the version + if !update_version0(version) + # something was wrong + return false + end + render_result @version + end + + # update a existing version for a given project + def update_version(version=params["version"]) + # get version + @version = @project.versions.find_by_name(version[:name]) + if !@version + render_status 404, "#{version['name']} is not a version for project #{@project.name}" + return false + end + # check permissions + allowed = User.current.allowed_to?({:controller => 'versions', :action => "edit"}, @project) + if !allowed + render_status 401, "No permission to edit a version on project #{@project.name}" + return false + end + # do update the version + if !update_version0(version) + # something was wrong + return false + end + render_result @version + end + + # add or update a new version for a given project and move all opened issue + # to next version from a preivous version + def next_version(version = params["version"],old_version_name=params[:oldVersionName]) + # get version + @version = @project.versions.find_by_name(version[:name]) + if !@version + # version does does exists + allowed = User.current.allowed_to?(:manage_versions, @project) + if !allowed + render_status 401, "No permission to add a version on project #{@project.name}" + return false + end + + # create the new version + @version = Version.create(:project => @project, :name => version[:name]) + end + + # check update permission + allowed = User.current.allowed_to?({:controller => 'versions', :action => "edit"}, @project) + if !allowed + render_status 401, "No permission to edit a version on project #{@project.name}" + return false + end + + # do update the version + if !update_version0(version) + + # something was wrong while updating the version + return false + end + + if old_version_name + old_version = @project.versions.find_by_name(old_version_name) + if !old_version + render_status 505, "Could not find old version #{old_version_name} for project #{@project.name}" + return false + end + old_issues = old_version.fixed_issues.find(:all) + old_issues.each do |issue| + sid = issue.status_id + if !issue.closed? || ( sid == 1 || sid == 2 ) + journal = issue.init_journal(User.current, params[:notes]) + + # move to new version + issue.fixed_version_id = @version[:id] + issue.save + #Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') + end + end + end + render_result @version + end + + # add a new news for a given project + def add_news(news = params["news"]) + if !request.post? + render_status 405, "POST method required for action add_news" + return false + end + allowed = User.current.allowed_to?({:controller => 'news', :action => "new"}, @project) + if !allowed + msg = "No permission to add a news on project "+ @project.name + render_status 401, msg + else + @news = News.new(:project => @project, :author => User.current) + @news.attributes = news + if @news.save + Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') + render_result @news + else + render_status 505, "Could not add the news..." + end + end + end + + def add_version_attachment + add_attachment + end + + def add_attachment(attachment = params["attachment"]) + if !request.post? + render_status 405, "POST method required for action add_attachment" + return false + end + container = !@version ? @project : @version + if attachment + file = attachment['file'] + next unless file && file.size > 0 + a = Attachment.new(:container => container, + :file => file, + :description => attachment['description'].to_s.strip, + :author => User.current) + end + if a.save + if Setting.notified_events.include?('file_added') + array =[] + array << a + Mailer.deliver_attachments_added(array) + end + else + render_status 505, "Could not save the file " + a + end + render_result a + end + + def add_issue_time(timeEntry = params["time_entry"]) + if !request.post? + render_status 405, "POST method required for action add_issue_time" + return false + end + allowed = User.current.allowed_to?(:log_time, @project) + if !allowed + msg = "No permission to add a issue time entry on project "+ @project.name + render_status 401, msg + end + @notes = params[:notes] + journal = @issue.init_journal(User.current, @notes) + @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) + @time_entry.attributes = timeEntry + + call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) + + if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save + # Log spend time + @time_entry.save + else + render_status 505, "Could not save the time entry " + @time_entry + end + if !journal.new_record? + # Only send notification if something was actually changed + Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') + end + render_result @time_entry + end + + def update_issue_time(timeEntry = params["time_entry"]) + if !request.post? + render_status 405, "POST method required for action update_issue_time" + return false + end + + end + + # recuperation des valeurs d'une enumeration + def get_enumeration(type = params[:type]) + #@result = Enumeration.get_values(type) + @result = Enumeration.find(:all, :conditions =>["type = :sqlParamType", {:sqlParamType => type}]) + render_array_result @result, "enumerations" + end + + private + + # Checks that action is using post method + def check_post + if !request.post? + render_status 405, "POST method required for action #{params[:action]}" + end + end + + # Checks that request has a version[name] attribute + def check_version_definition(version = params[:version]) + if version.nil? + render_status 404, "No version definition in request" + else + if version[:name].nil? + render_status 404, "No version name given in request" + end + end + end + + def find_user + # Check the settings cache for each request + Setting.check_cache + # Find the current user + User.current = find_current_user + if !session[:user_id] + render_status 401, "Not connected" + end + end + + # Returns the current user or nil if no user is logged in + def find_current_user + if session[:user_id] + # existing session + (User.active.find(session[:user_id]) rescue nil) + elsif cookies[:autologin] + # auto-login feature + User.find_by_autologin_key(cookies[:autologin]) + end + end + + def find_project( pid = params[:pid] ) + begin + @project = Project.find(pid) + allowed = User.current.allowed_to?({:controller => 'jredmine', :action => "allow_jredmine"}, @project) + if !allowed + render_status 401, "No permission to access project #{pid} nor jredmine service configured for this project" + end + rescue ActiveRecord::RecordNotFound + render_status 404, "#{pid} is not a project" + return false + end + end + + def check_edit + # check if user can edit the project + allowed = User.current.allowed_to?({:controller => 'projects', :action => "edit"}, @project) + if !allowed + render_status 401, "No permission to edit the project" + end + end + + def find_version(version = params[:version_name]) + if version.nil? + render_status 404, "No version name given in request" + else + @version = @project.versions.find_by_name(version) + if !@version + render_status 404, "#{version} is not a version for project #{@project.name}" + end + end + end + + def find_issue(issue = params[:issue_id]) + @issue = @project.issues.find(issue) + if !@issue + render_status 404, "#{issue} is not an issue for project #{@project.name}" + end + end + + # Update the version with the pa given in parameters. + # To use this method the @project and @version must defined + def update_version0(version) + attributes = version.dup + attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) + begin + valid = @version.update_attributes(attributes) + if !valid + render_status 505, "Could not update the version #{@version.name} on project #{@project.name} for unknown reason..." + end + rescue => msg + valid = false + render_status 505, "Could not update the version #{@version.name} on project #{@project.name} for reason #{msg}" + end + valid + end + + def render_status(code,message) + render :text => message, :status => code + end + + def render_array_result(result,tag) + if !result.any? + respond_to do |format| + format.json { render :text => "[]" } + format.xml { render :text => "<"+tag+"></"+tag+">" } + end + else + respond_to do |format| + format.json { render :text => result.to_json } + format.xml { render :text => result.to_xml } + end + end + end + + def render_result(result) + respond_to do |format| + format.json { render :text => result.to_json } + format.xml { render :text => result.to_xml } + end + end + + def logged_user=(user) + if user && user.is_a?(User) + User.current = user + session[:user_id] = user.id + else + User.current = User.anonymous + session[:user_id] = nil + end + end + + def allowed_permissions + @allowed_permissions ||= begin + module_names = @project.enabled_modules.collect {|m| m.name} + Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} + end + end + + def allowed_actions + @allowed_actions ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten + end + +end Property changes on: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/routes.rb =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/routes.rb (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/routes.rb 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,37 @@ +### +# #%L +# JRedmine :: Client +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +RedmineApp::Application.routes.draw do + + # jredmine : actions with no project context + match 'jredmine/:action.xml', :to => 'jredmine#:action', :action => ['get_projects', 'get_user_projects', 'get_issue_statuses', 'get_issue_priorities', 'get_enumeration'], :format => 'xml', :via => ['get'] + match 'jredmine/:action.json', :to => 'jredmine#:action', :action => ['get_projects', 'get_user_projects', 'get_issue_statuses', 'get_issue_priorities', 'get_enumeration'], :format => 'json', :via => ['get'] + match 'jredmine/:action', :to => 'jredmine#:action', :action => ['ping', 'login', 'logout', 'get_projects', 'get_user_projects', 'get_issue_statuses', 'get_issue_priorities', 'get_enumeration'], :format => 'xml', :via => ['get'] + + # jredmine/action/:pid : actions with project context + match 'jredmine/:action.xml/:pid', :to=> 'jredmine#:action', :pid => /.+/, :format => 'xml', :via => ['get', 'post'] + match 'jredmine/:action/:pid', :to=> 'jredmine#:action', :pid => /.+/, :format => 'xml', :via => ['get', 'post'] + match 'jredmine/:action.json/:pid', :to=> 'jredmine#:action', :pid => /.+/, :format => 'json', :via => ['get', 'post'] + +end \ No newline at end of file Property changes on: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/config/routes.rb ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/init.rb =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/init.rb (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/init.rb 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,35 @@ +### +# #%L +# JRedmine :: Client +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +require 'redmine' + +Redmine::Plugin.register :jredmine do + name 'JRedmine Rails plugin' + author 'Tony Chemit' + description 'A plugin to expose projects in REST protocol' + version '0.0.1' + project_module :jredmine do + permission :allow_jredmine, :jredmine => :allow_jredmine + end +end Property changes on: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/init.rb ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/en.yml =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/en.yml (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/en.yml 2012-10-02 16:20:19 UTC (rev 331) @@ -0,0 +1,2 @@ +# English strings go here +my_label: "My label" Property changes on: branches/jredmine-1.x/jredmine-client/src/main/redmine/jredmine-2.x/lang/en.yml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/jredmine-1.x/jredmine-client/src/site/apt/index.apt =================================================================== --- branches/jredmine-1.x/jredmine-client/src/site/apt/index.apt 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/jredmine-client/src/site/apt/index.apt 2012-10-02 16:20:19 UTC (rev 331) @@ -32,7 +32,6 @@ Ce module contient un plugin <rails> qui permet d'ouvrir l'api de redmine au protocole <REST>, ainsi q'un client <Java> pour interroger les services <REST>. - Plugin <rails> JRedmine Le but de ce plugin est de pouvoir accéder aux données d'un serveur Redmine en @@ -42,14 +41,17 @@ La page {{{./rails_api.html}API}} détaille l'ensemble des services disponibles depuis le serveur Redmine. + Le plugin existe en deux versions (la version 2.0 de redmine utilisant Rails 3 qui rend incompatible la gestion des routes {{{http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3}pour plus de détails}}.) + * Source du plugin - Les sources du plugin <rails> sont sont dans le répertoire <<src/main/redmine>> + Les sources du plugin <rails> sont sont dans le répertoire + <<src/main/redmine/jredmine-xxx>>. -------------------------------------------------------------------------------- src/main/redmine/ -`-- jredmine +`-- jredmine-1.x |-- README.rdoc |-- app | |-- controllers @@ -72,6 +74,29 @@ | `-- tasks `-- test `-- functional +`-- jredmine-2.x + |-- README.rdoc + |-- app + | |-- controllers + | | `-- jredmine_controller.rb + | |-- helpers + | |-- models + | `-- views + |-- assets + | |-- images + | |-- javascripts + | `-- stylesheets + |-- config + | `-- routes.rb + |-- db + | `-- migrate + |-- init.rb + |-- lang + | `-- en.yml + |-- lib + | `-- tasks + `-- test + `-- functional -------------------------------------------------------------------------------- * Récupération d'une version packagée @@ -83,7 +108,7 @@ * récupération du zip du plugin - * dézippage dans le répertoire vendor/plugins + * dézippage dans le répertoire vendor/plugins (ou plugins pour redmine 2.0) * relancer votre instance de redmine (ou apache). Modified: branches/jredmine-1.x/jredmine-client/src/site/site_fr.xml =================================================================== --- branches/jredmine-1.x/jredmine-client/src/site/site_fr.xml 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/jredmine-client/src/site/site_fr.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -55,27 +55,15 @@ </menu> <menu name="Téléchargement"> - <item href="http://nuiton.org/projects/list_files/jredmine" name="Sources bundles"/> - - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}.jar" - name="Librairie (jar)"/> - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}-javadoc.jar" - name="Javadoc (jar)"/> - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}-sources.jar" - name="Sources (jar)"/> - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}-tests.jar" - name="Test Librairie (jar)"/> - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}-test-javadoc.jar" - name="Test Javadoc (jar)"/> - <item href="${repository.home.url}/org/nuiton/jredmine/jredmine-client/${project.version}/${project.build.finalName}-test-sources.jar" - name="Test Sources (jar)"/> + <item href="http://nuiton.org/projects/jredmine/files" + name="Sources bundles"/> </menu> <menu ref="reports"/> <footer> - <div id='projectMetas' locale='en' + <div id='projectMetas' locale='fr' projectversion='${project.version}' platform='${project.platform}' projectid='${project.projectId}' Modified: branches/jredmine-1.x/src/site/apt/index.apt =================================================================== --- branches/jredmine-1.x/src/site/apt/index.apt 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/src/site/apt/index.apt 2012-10-02 16:20:19 UTC (rev 331) @@ -63,6 +63,9 @@ Un soin tout particulier a été apporté pour améliorer la configuration des tests ({{{./tests.html}détails}}). + Dans cette nouvelle version, on a aussi permis l'utilisation du plugin rails + sur redmine 1 et 2. + * Version 1.3 La version <<1.3>> est compatible avec {{{http://www.redmine.org/versions/42}<redmine 1.3.2>}} après la Modified: branches/jredmine-1.x/src/site/site_fr.xml =================================================================== --- branches/jredmine-1.x/src/site/site_fr.xml 2012-10-02 14:16:44 UTC (rev 330) +++ branches/jredmine-1.x/src/site/site_fr.xml 2012-10-02 16:20:19 UTC (rev 331) @@ -93,7 +93,7 @@ <footer> - <div id='projectMetas' locale='en' + <div id='projectMetas' locale='fr' projectversion='${project.version}' platform='${project.platform}' projectid='${project.projectId}'