checks if a current user received invitation from given user
554694
def invited_by?(user)
      user.friend_ids.include?(self.id) or user.pending_friend_ids.include?(self.id)
    end
1353278
def invite(user, reason='')
      response = self.class.post(@api.invite_config[:url]+"/#{user}",
        :query => { :auth_token => @token },
        :body => {
          :reason => reason
        }.to_json,
        :headers => @api.headers)

      ErrorHandler.response_code_to_exception_for :room, room_id, response
      true
    end
86899
def accept_invite(invite)
      resolved = invite(invite).code
      API::Invite.accept(token, resolved)
    end
85129
def accept(self, request, uuid=None):
        
        invitation = self.get_object()

        if invitation.state != models.Invitation.State.PENDING:
            raise ValidationError(_('Only pending invitation can be accepted.'))
        elif invitation.civil_number and invitation.civil_number != request.user.civil_number:
            raise ValidationError(_('User has an invalid civil number.'))

        if invitation.project:
            if invitation.project.has_user(request.user):
                raise ValidationError(_('User already has role within this project.'))
        elif invitation.customer.has_user(request.user):
            raise ValidationError(_('User already has role within this customer.'))

        if settings.WALDUR_CORE['VALIDATE_INVITATION_EMAIL'] and invitation.email != request.user.email:
            raise ValidationError(_('Invitation and user emails mismatch.'))

        replace_email = bool(request.data.get('replace_email'))
        invitation.accept(request.user, replace_email=replace_email)
        return Response({'detail': _('Invitation has been successfully accepted.')},
                        status=status.HTTP_200_OK)
653225
def claim_invitations(user):
    """"""
    # See if there are any build invitations present for the user with this
    # email address. If so, replace all those invitations with the real user.
    invitation_user_id = '%s:%s' % (
        models.User.EMAIL_INVITATION, user.email_address)
    invitation_user = models.User.query.get(invitation_user_id)
    if invitation_user:
        invited_build_list = list(invitation_user.builds)
        if not invited_build_list:
            return

        db.session.add(user)
        logging.debug('Found %d build admin invitations for id=%r, user=%r',
                      len(invited_build_list), invitation_user_id, user)

        for build in invited_build_list:
            build.owners.remove(invitation_user)
            if not build.is_owned_by(user.id):
                build.owners.append(user)
                logging.debug('Claiming invitation for build_id=%r', build.id)
                save_admin_log(build, invite_accepted=True)
            else:
                logging.debug('User already owner of build. '
                              'id=%r, build_id=%r', user.id, build.id)
            db.session.add(build)

        db.session.delete(invitation_user)
        db.session.commit()
        # Re-add the user to the current session so we can query with it.
        db.session.add(current_user)
1106341
def invite(invite)
      code = resolve_invite_code(invite)
      Invite.new(JSON.parse(API::Invite.resolve(token, code)), self)
    end
1331914
def accept(self, event):
        """"""

        self.log('Invitation accepted:', event.__dict__, lvl=debug)
        try:
            uuid = event.data
            enrollment = objectmodels['enrollment'].find_one({
                'uuid': uuid
            })

            if enrollment is not None:
                self.log('Enrollment found', lvl=debug)
                if enrollment.status == 'Open':
                    self.log('Enrollment is still open', lvl=debug)
                    if enrollment.method == 'Invited' and self.config.auto_accept_invited:
                        enrollment.status = 'Accepted'

                        data = 'You should have received an email with your new password ' \
                               'and can now log in to the system and start to use it. <br/>' \
                               'Please change your password immediately after logging in'
                        password = std_human_uid().replace(" ", '')

                        self._create_user(enrollment.name, password, enrollment.email, enrollment.method, uuid)
                        self._send_acceptance(enrollment, password, event)
                    elif enrollment.method == 'Enrolled' and self.config.auto_accept_enrolled:
                        enrollment.status = 'Accepted'
                        data = 'Your account is now activated.'

                        self._create_user(enrollment.name, enrollment.password, enrollment.email, enrollment.method,
                                          uuid)

                        # TODO: Evaluate if sending an acceptance mail makes sense
                        # self._send_acceptance(enrollment, "", event)
                    else:
                        enrollment.status = 'Pending'
                        data = 'Someone has to confirm your enrollment ' \
                               'first. Thank you, for your patience.'
                        # TODO: Alert admin users
                    enrollment.save()

                # Reaffirm acceptance to end user, when clicking on the link multiple times
                elif enrollment.status == 'Accepted':
                    data = 'You can now log in to the system and start to use it.'
                elif enrollment.status == 'Pending':
                    data = 'Someone has to confirm your enrollment ' \
                           'first. Thank you, for your patience.'
                else:
                    self.log('Enrollment has been closed already!', lvl=warn)
                    self._fail(event)
                    return
                packet = {
                    'component': 'hfos.enrol.enrolmanager',
                    'action': 'accept',
                    'data': {True: data}
                }
                self.fireEvent(send(event.client.uuid, packet))
            else:
                self.log('No enrollment available.', lvl=warn)
                self._fail(event)
        except Exception as e:
            self.log('Error during invitation accept handling:', e, type(e),
                     lvl=warn, exc=True)
545475
def _is_current_user(self, some_user):
        
        current_user = self.remote_store.get_current_user()
        return current_user.id == some_user.id
495361
def getGuestList(request):
    '''
    
    '''
    if not (
        request.method == 'POST' and
        request.POST.get('guestlist_id') and
        request.POST.get('event_id') and
        request.user.is_authenticated and
        request.user.has_perm('guestlist.view_guestlist')
    ):
        return JsonResponse({})

    guestList = GuestList.objects.filter(id=request.POST.get('guestlist_id')).first()
    event = Event.objects.filter(id=request.POST.get('event_id')).first()

    if not guestList or not event:
        return JsonResponse({})

    return JsonResponse({
        'names': guestList.getListForEvent(event),
    })
1138032
def post(self, request, *args, **kwargs):
        
        status = 201
        accepted = {"accepted": True}
        send_invite_messages.apply_async()
        return Response(accepted, status=status)
411043
def check_user(self, user_id):
        

        if self.hidden == 'N':
            return True

        for owner in self.owners:
            if int(owner.user_id) == int(user_id):
                if owner.view == 'Y':
                    return True
        return False
212326
def invite_user(self, room_id, user_id):
        
        body = {
            "user_id": user_id
        }
        return self._send("POST", "/rooms/" + room_id + "/invite", body)
553248
def approve(user)
      friendship = find_any_friendship_with(user)
      return false if friendship.nil? || invited?(user)
      friendship.update_attribute(:pending, false)
    end
273851
def is_member(self, m):
        """"""
        if not m:
            return False
        elif isinstance(m, basestring):
            jid = m
        else:
            jid = m['JID']

        is_member = len(filter(lambda m: m['JID'] == jid and m.get('STATUS') in ('ACTIVE', 'INVITED'), self.params['MEMBERS'])) > 0

        return is_member
954613
def notify_created(room, event, user):
    
    tpl = get_plugin_template_module('emails/created.txt', chatroom=room, event=event, user=user)
    _send(event, tpl)
165196
def _send_invitation(request, project):
    
    form = forms.InviteUserApplicationForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():

            email = form.cleaned_data['email']
            applicant, existing_person = get_applicant_from_email(email)

            # If applicant is None then there were multiple persons found.
            if applicant is None:
                return render(
                    template_name='kgapplications/'
                                  'project_common_invite_multiple.html',
                    context={'form': form, 'email': email},
                    request=request)

            if existing_person and 'existing' not in request.POST:
                return render(
                    template_name='kgapplications/'
                                  'project_common_invite_existing.html',
                    context={'form': form, 'person': applicant},
                    request=request)

            application = form.save(commit=False)
            application.applicant = applicant
            application.project = project
            application.save()
            state_machine = get_application_state_machine()
            response = state_machine.start(request, application)
            return response

    return render(
        template_name='kgapplications/project_common_invite_other.html',
        context={'form': form, 'project': project, },
        request=request)
986798
def invite(body)
      raise ArgumentError unless body.is_a?(Array)
      raise ArgumentError unless body.first.is_a?(Hash)
      api.post('invite', body, 'application/json')
    end