/[pupa]/bugcomm/lib/bugcomm/database.rb
ViewVC logotype

Diff of /bugcomm/lib/bugcomm/database.rb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by okuji, Thu Sep 26 10:19:27 2002 UTC revision 1.7 by okuji, Fri Sep 27 10:34:06 2002 UTC
# Line 376  module BugCommunicator Line 376  module BugCommunicator
376          end          end
377        end        end
378      end      end
379    
380        def change_bug(project, bug_id, actions)
381          unless include?(project)
382            raise MalformedRequestError,
383              "the project `#{project}' doesn't exist any longer"
384          end
385          
386          bug = bug(project, bug_id, true)
387          selection_fields = selection_fields(project)
388          text_fields = text_fields(project)
389          
390          actions.each do |action|
391            f = selection_fields.detect {|f| f.name == action.name} or
392              text_fields.detect {|f| f.name == action.name}
393            if f.nil?
394              raise MalformedRequestError,
395                "the field `#{action.name}' doesn't exist any longer"
396            end
397    
398            if bug[action.name] != action.old_val
399              raise MalformedRequestError,
400                "the field `#{action.name}' was modified after the request"
401            end
402    
403            val = action.new_val
404            
405            case f
406            when SelectionField
407              unless (val == 'none' and (not f.always_set?)) or
408                  f.keywords.include?(val)
409                raise MalformedRequestError,
410                  "invalid value `#{val}' for the selection field `#{f.name}'"
411              end
412              q("UPDATE #{e(bug_table(project))} SET sf_#{e(f.name)}='#{e(val)}' \
413                   WHERE bug_id = #{e(bug_id.to_s)}")
414              
415            when TextField
416              if val.empty? and (not f.can_be_empty?)
417                raise MalformedRequestError,
418                  "the text field `#{f.name}' cannot be empty"
419              end
420    
421              unless f.regexp.empty?
422                if /\#\{/ =~ f.regexp
423                  raise MalformedRequestError,
424                    "dangerous regular expression `#{f.regexp}'"
425                end
426                if Regexp.new(f.regexp) !~ val
427                  raise MalformedRequestError,
428                    "invalid text `#{val}' for `#{f.name}'"
429                end
430              end
431    
432              unless f.multiple_lines?
433                val.gsub!(/[\r\n]/, ' ')
434                val.strip!
435                if val.length > 255
436                  raise MalformedRequestError,
437                    "too long text for the text field `#{f.name}'"
438                end
439              end
440              q("UPDATE #{e(bug_table(project))} SET tf_#{e(f.name)}='#{e(val)}' \
441                   WHERE bug_id = #{e(bug_id.to_s)}")
442            end
443          end
444        end
445            
446      def selection_field(project, name)      def selection_field(project, name)
447        q("SELECT * FROM #{e(sf_table(project))} WHERE name = '#{e(name)}' \        q("SELECT * FROM #{e(sf_table(project))} WHERE name = '#{e(name)}' \
# Line 470  module BugCommunicator Line 536  module BugCommunicator
536            remove_project(action.project)            remove_project(action.project)
537          when ConfigProjectAction          when ConfigProjectAction
538            config_project(action.project, action.actions)            config_project(action.project, action.actions)
539            when ChangeBugAction
540              change_bug(action.project, action.bug.bug_id, action.actions)
541          else          else
542            raise MalformedDataError, "unknown action `#{action.inspect}'"            raise MalformedDataError, "unknown action `#{action.inspect}'"
543          end          end
# Line 642  module BugCommunicator Line 710  module BugCommunicator
710        r().collect {|a| a[0]}        r().collect {|a| a[0]}
711      end      end
712    
713      def bug(project, bug_id)      def bug(project, bug_id, exclusive = false)
714        q("SELECT * FROM #{e(bug_table(project))} WHERE \        q("SELECT * FROM #{e(bug_table(project))} WHERE \
715             bug_id = #{e(bug_id.to_s)} LOCK IN SHARE MODE")             bug_id = #{e(bug_id.to_s)} " +
716            if exclusive then 'FOR UPDATE' else 'LOCK IN SHARE MODE' end)
717        h = r().fetch_hash()        h = r().fetch_hash()
718        if h.nil?        if h.nil?
719          raise MalformedRequestError, "no such bug `#{bug_id}'"          raise MalformedRequestError, "no such bug `#{bug_id}'"

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26