Class Invitation
In: app/models/invitation.rb
Parent: ActiveRecord::Base

Methods

Attributes

user_name  [RW]  Attributes

Public Instance methods

Admits the given user to the peergroup.

Does not check the user signed up with the email address he was invited on.

[Source]

    # File app/models/invitation.rb, line 56
56:   def admit(user)
57:     if self.user and user != self.user
58:       return false
59:     end
60:     membership = self.peer_group.membership_for(user)
61:     if self.role == Const::PeerGroupMembership::ADMIN
62:       membership.admin_settings = true
63:     end
64:     return membership.save
65:   end

Sends out the invitation. Must be called after the invitation is saved.

[Source]

    # File app/models/invitation.rb, line 47
47:   def deliver_invitation!
48:     Notifier.deliver_invitation(self)
49:   end

[Source]

    # File app/models/invitation.rb, line 73
73:   def find_and_set_user
74:     if !self.user_name.nil? and !self.user_name.empty?
75:       self.user_name.gsub!('_', ' ')
76:       self.user = User.find_by_name(self.user_name)
77:     elsif !self.email.nil? and !self.email.empty?
78:       self.user = User.find_by_email(self.email)
79:     end
80:     if !self.user.nil?
81:       self.email = self.user.email
82:     end
83:   end

Filter-methods

[Source]

    # File app/models/invitation.rb, line 69
69:   def set_token
70:     self.token = Authlogic::Random.friendly_token
71:   end

Validation-methods

[Source]

    # File app/models/invitation.rb, line 87
87:   def validate
88:     # check that either email or user name given
89:     if (self.user_name.nil? or self.user_name.empty?) and 
90:         (self.email.nil? or self.email.empty?)
91:       self.errors.add(:email, t('m.invitation.provide_email'))
92:     end
93:     if (self.role == Const::PeerGroupMembership::ADMIN) and
94:         !self.peer_group.admin_permissions?(self.creator_user)
95:       self.errors.add(:permission, t('m.invitation.not_permitted'))
96:     elsif self.peer_group.membership_for(self.creator_user).new_record?
97:       self.errors.add(:permission, t('m.invitation.no_member'))
98:     end
99:   end

[Validate]