diff --git a/app/models/submission.rb b/app/models/submission.rb --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -34,8 +34,8 @@ def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id) records = Submission.where(problem_id: problem_id,user_id: user_id) - records = records.where('id >= ?',since_id) if since_id > 0 - records = records.where('id <= ?',until_id) if until_id > 0 + records = records.where('id >= ?',since_id) if since_id and since_id > 0 + records = records.where('id <= ?',until_id) if until_id and until_id > 0 records.all end @@ -137,7 +137,7 @@ # for output_only tasks return if self.problem!=nil and self.problem.output_only - + if self.language==nil errors.add('source',"Cannot detect language. Did you submit a correct source file?") unless self.language!=nil end @@ -147,8 +147,12 @@ return if self.source==nil if self.problem==nil errors.add('problem',"must be specified.") - elsif (!self.problem.available) and (self.new_record?) - errors.add('problem',"must be valid.") + else + #admin always have right + return if self.user.admin? + + #check if user has the right to submit the problem + errors.add('problem',"must be valid.") if (!self.user.available_problems.include?(self.problem)) and (self.new_record?) end end