socialforge/app/models/softapplication.rb

40 lines
1.4 KiB
Ruby

class Softapplication < ActiveRecord::Base
attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id, :application_developers, :deposit_project_url, :deposit_project
acts_as_attachable :view_permission => :view_files
seems_rateable :allow_update => true, :dimensions => :quality
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :contesting_softapplications, :dependent => :destroy
#has_many :projecting_softapplications, :dependent => :destroy
belongs_to :user
belongs_to :project
has_many :contests, :through => :contesting_softapplications
validates_length_of :name, :maximum => 25
validates_length_of :application_developers, :maximum => 125
validates_length_of :android_min_version_available, :maximum => 125
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
def editable_by? usr
usr.admin? || self.user == usr
end
def destroyable_by? usr
self.user == usr || usr.admin?
end
end