Ejemplo n.º 1
0
def set_member_role(company_address, sender_id, member_id, role):
    try:
        sender = Member.objects.get(pk=sender_id)
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member not found and will not be added to company.')
    else:
        mi = MemberInterface(sender.contract_address)
        try:
            if role == 'owner':
                txn_hash = mi.new_company_owner(company_address,
                                                member.contract_address)
            elif role == 'collaborator':
                txn_hash = mi.new_company_collaborator(company_address,
                                                       member.contract_address)
            else:
                txn_hash = mi.new_company_member(company_address,
                                                 member.contract_address)
        except Exception as e:
            logger.error(
                'Error while add member to company {} {} {} {}'.format(
                    company_address, member_id, sender_id, e))
        else:
            save_txn.delay(txn_hash.hex(), 'AddCompanyMember', sender_id,
                           member_id)
            save_txn_to_history.delay(
                sender_id, txn_hash.hex(),
                'Add {} as company member'.format(member.full_name))
            return True
Ejemplo n.º 2
0
def new_vacancy(vacancy_id):
    try:
        vacancy = Vacancy.objects.get(pk=vacancy_id)
    except Vacancy.DoesNotExist:
        logger.warning('Vacancy {} not found and will not be published'.format(
            vacancy_id))
    else:
        mi = MemberInterface(
            contract_address=vacancy.created_by.contract_address)
        try:
            txn_hash = mi.new_vacancy(vacancy.company.contract_address,
                                      vacancy.uuid,
                                      int(vacancy.allowed_amount) * 10**18)
        except Exception as e:
            logger.error(
                'Error deploy new vacancy: {}, vacancy deleted'.format(e))
            vacancy.delete()
            return False
        else:
            save_txn_to_history.apply_async(
                args=(vacancy.created_by.id, txn_hash.hex(),
                      'Creation of a new vacancy: {}'.format(vacancy.title)),
                countdown=0.2)
            save_txn.apply_async(args=(txn_hash.hex(), 'NewVacancy',
                                       vacancy.created_by.id, vacancy.id),
                                 countdown=0.2)
    return True
Ejemplo n.º 3
0
def new_subscribe(member_id, vacancy_id):
    try:
        vacancy = Vacancy.objects.get(pk=vacancy_id)
    except Vacancy.DoesNotExist:
        logger.warning(
            'Vacancy {} not found, user {} will not be subscribed'.format(
                vacancy_id, member_id))
        return False
    else:
        try:
            member = Member.objects.get(pk=member_id)
        except Member.DoesNotExist:
            logger.warning(
                'Member {} not found, and will not be subscribed'.format(
                    member_id))
            return False
        else:
            mi = MemberInterface(contract_address=member.contract_address)
            try:
                txn_hash = mi.subscribe(vacancy.company.contract_address,
                                        vacancy.uuid)
            except Exception as e:
                logger.error(
                    'Error while subscribe: member {}, vacancy {}, e: {}'.
                    format(member_id, vacancy_id, e))
            else:
                save_txn_to_history.apply_async(
                    args=(member_id, txn_hash.hex(),
                          'Subscribe to vacancy: {}'.format(vacancy.title)),
                    countdown=0.1)
                save_txn.apply_async(args=(txn_hash.hex(), 'MemberSubscribe',
                                           member_id, vacancy.id),
                                     countdown=0.1)
                return True
Ejemplo n.º 4
0
def change_status(vacancy_id, member_id):
    try:
        sender = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning(
            'Member {} not found, vacancy status will not be changed'.format(
                member_id))
    else:
        try:
            vacancy = Vacancy.objects.get(pk=vacancy_id)
        except Vacancy.DoesNotExist:
            logger.warning('Vacancy {} does not exist'.format(vacancy_id))
        else:
            oracle = OracleHandler()
            allowed_for_vacancies = 0
            company = vacancy.company
            for vacancy_item in company.vacancies.all():
                allowed_for_vacancies += oracle.vacancy(
                    company.contract_address,
                    vacancy_item.uuid)['allowed_amount']

            mi = MemberInterface(contract_address=sender.contract_address)
            try:
                mi.approve_company_tokens(company.contract_address, 0)
                txn_hash = mi.approve_company_tokens(company.contract_address,
                                                     allowed_for_vacancies)
            except Exception as e:
                logger.warning('Cannot approve company tokens: {}'.format(e))
            else:
                save_txn_to_history.delay(
                    member_id, txn_hash.hex(),
                    'Approving {} tokens for platform'.format(
                        allowed_for_vacancies / 10**18))
                bch_vacancy = oracle.vacancy(vacancy.company.contract_address,
                                             vacancy.uuid)

                if bch_vacancy['enabled']:
                    method = getattr(mi, 'disable_vac')
                else:
                    method = getattr(mi, 'enable_vac')

                try:
                    txn_hash = method(company.contract_address, vacancy.uuid)
                except Exception as e:
                    logger.warning('Cant change vacancy {} status: {}'.format(
                        vacancy.id, e))
                else:
                    save_txn_to_history.apply_async(
                        args=(member_id, txn_hash.hex(),
                              'Vacancy status changed: {}'.format(
                                  vacancy.title)),
                        countdown=0.1)
                    save_txn.apply_async(args=(txn_hash.hex(), 'VacancyChange',
                                               member_id, vacancy.id),
                                         countdown=0.1)
            return True
Ejemplo n.º 5
0
def change_member_status(member_id, status):
    try:
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member {} not found. Status will not be changed.')
        return False
    else:
        mi = MemberInterface(contract_address=member.contract_address)
        try:
            txn_hash = mi.change_status(status)
        except Exception as e:
            logger.error('Error while change member {} status: {}'.format(
                member_id, e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'ChangeStatus', member_id,
                           member_id)
            save_txn_to_history.delay(
                member_id, txn_hash.hex(), 'Status changed to {}'.format(
                    OracleHandler().statuses[int(status)]))
        return True
Ejemplo n.º 6
0
def changed_action(action):
    try:
        sender = Member.objects.get(pk=action['sender_id'])
    except Member.DoesNotExist:
        logger.warning(
            'Sender {} not found, action will not be changed'.format(
                action['sender_id']))
        return False
    else:
        try:
            vacancy = Vacancy.objects.get(pk=action['vacancy_id'])
        except Vacancy.DoesNotExist:
            logger.warning(
                'Vacancy {} not found, action will not be changed'.format(
                    action['vacancy_id']))
            return False
        else:
            mi = MemberInterface(contract_address=sender.contract_address)
            try:
                txn_hash = mi.change_action(
                    company_address=vacancy.company.contract_address,
                    vac_uuid=vacancy.uuid,
                    index=action['index'],
                    title=action['title'],
                    fee=action['fee'],
                    appr=action['approvable'])
            except Exception as e:
                logger.error('Error while change pipline action {}: {}'.format(
                    action['index'], e))
                return False
            else:
                save_txn_to_history.apply_async(
                    args=(action['sender_id'], txn_hash.hex(),
                          'Changed action {} on vacancy: {}'.format(
                              action['index'], vacancy.title)),
                    countdown=0.1)
                save_txn.apply_async(args=(txn_hash.hex(), 'ActionChanged',
                                           action['sender_id'], action['id']),
                                     countdown=0.1)
                return True
Ejemplo n.º 7
0
def change_vacancy_allowed_amount(vacancy_id, sender_id):
    try:
        sender = Member.objects.get(pk=sender_id)
    except Member.DoesNotExist:
        logger.warning(
            'Member {} not found, vacancy allowed amount will not be changed'.
            format(sender_id))
        return False
    else:
        try:
            vacancy = Vacancy.objects.get(pk=vacancy_id)
        except Vacancy.DoesNotExist:
            logger.warning(
                'Vacancy {} not found, allowed will not be changed'.format(
                    vacancy_id))
            return False
        else:
            mi = MemberInterface(contract_address=sender.contract_address)

            if vacancy.chain['allowed_amount'] != int(
                    vacancy.allowed_amount) * 10**18:
                try:
                    txn_hash = mi.change_vacancy_allowance_amount(
                        vacancy.company.contract_address, vacancy.uuid,
                        int(vacancy.allowed_amount) * 10**18)
                except Exception as e:
                    logger.error(
                        'Error changing vacancy allowed amount: {}'.format(e))
                    return False
                else:
                    save_txn_to_history.apply_async(
                        args=(sender_id, txn_hash.hex(),
                              'Vacancy allowed amount changed: {}'.format(
                                  vacancy.title)),
                        countdown=0.1)
                    save_txn.apply_async(args=(txn_hash.hex(),
                                               'VacancyAllowedChanged',
                                               sender_id, vacancy.id),
                                         countdown=0.1)
                    return True
Ejemplo n.º 8
0
def new_fact_confirmation(sender_address, member_address, fact_uuid):
    try:
        sender = Member.objects.get(contract_address=sender_address)
    except Member.DoesNotExist:
        logger.warning(
            'Member with address {} not found, confirmation will not be added'.
            format(sender_address))
        return False
    else:
        mi = MemberInterface(sender_address)
        try:
            txn_hash = mi.verify_fact(member_address, fact_uuid)
        except Exception as e:
            logger.error("Cannot verify fact, e: {}".format(e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'NewFactConfirmation', sender.id,
                           fact_uuid)
            save_txn_to_history.delay(
                sender.id, txn_hash.hex(),
                'Added fact confirmation for fact {}'.format(fact_uuid))
        return True
Ejemplo n.º 9
0
def new_action(action):
    mi = MemberInterface(contract_address=action['member_address'])
    try:
        txn_hash = mi.new_action(company_address=action['company_address'],
                                 vac_uuid=action['vacancy_uuid'],
                                 title=action['title'],
                                 fee=action['fee'],
                                 appr=action['approvable'])
    except Exception as e:
        logger.warning('Cant create new action, {} {}'.format(action['id'], e))
        return False
    else:
        vacancy = Vacancy.objects.get(uuid=action['vacancy_uuid'])
        save_txn_to_history.apply_async(
            args=(action['created_by'], txn_hash.hex(),
                  'Creation of a new action for vacancy: {}'.format(
                      vacancy.title)),
            countdown=0.1)
        save_txn.apply_async(args=(txn_hash.hex(), 'NewAction',
                                   action['created_by'], action['id'],
                                   vacancy.id),
                             countdown=0.1)
        return True
Ejemplo n.º 10
0
def delete_action(action):
    try:
        sender = Member.objects.get(pk=action['sender_id'])
    except Member.DoesNotExist:
        logger.warning(
            'Sender {} not found. Action will not be deleted'.format(
                action['sender_id']))
        return False
    else:
        try:
            vacancy = Vacancy.objects.get(id=action['vacancy_id'])
        except Vacancy.DoesNotExist:
            logger.warning(
                'Action vacancy {} not found, action will not be deleted'.
                format(action['vacancy_id']))
            return False
        else:
            mi = MemberInterface(contract_address=sender.contract_address)
            try:
                txn_hash = mi.delete_action(vacancy.company.contract_address,
                                            vacancy.uuid, action['index'])
            except Exception as e:
                logger.error('Error while deleting action {}: {}'.format(
                    action['id'], e))
                return False
            else:
                save_txn_to_history.apply_async(
                    args=(action['sender_id'], txn_hash.hex(),
                          'Deleted action {} on vacancy: {}'.format(
                              action['index'], vacancy.title)),
                    countdown=0.1)
                save_txn.apply_async(args=(txn_hash.hex(), 'ActionDeleted',
                                           action['sender_id'], action['id'],
                                           vacancy.id),
                                     countdown=0.1)
                return True
Ejemplo n.º 11
0
def new_member_fact(fact, sender_address, about_address):
    try:
        member = Member.objects.get(contract_address=sender_address)
    except Member.DoesNotExist:
        logger.warning(
            'Cant find member with address {}, fact will not be added'.format(
                sender_address))
        return False
    else:
        mi = MemberInterface(sender_address)
        try:
            txn_hash = mi.new_fact(about_address, fact,
                                   Web3.toHex(os.urandom(32)))
        except Exception as e:
            logger.error('Cant add new member fact: about: {}, e: {}'.format(
                about_address, e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'AddNewFact', member.id, member.id)
            save_txn_to_history.delay(
                member.id, txn_hash.hex(), 'Added new fact about {}'.format(
                    about_address == sender_address and 'yourself'
                    or about_address))
    return True
Ejemplo n.º 12
0
def action_with_candidate(vacancy_id, candidate_id, action, sender_id):
    try:
        sender = Member.objects.get(pk=sender_id)
    except Member.DoesNotExist:
        logger.warning('Sender {} not found, candidate {} will not '
                       'be level up or reset on vacancy {}'.format(
                           sender_id, candidate_id, vacancy_id))
        return False
    try:
        vacancy = Vacancy.objects.get(pk=vacancy_id)
    except Vacancy.DoesNotExist:
        logger.warning(
            'Vacancy {} not found, action with candidate {} will not be provided'
            .format(vacancy_id, candidate_id))
        return False
    else:
        try:
            candidate = Member.objects.get(pk=candidate_id)
        except Member.DoesNotExist:
            logger.warning(
                'Candidate {} do not found, action with vacancy {} will not be provided'
                .format(candidate_id, vacancy_id))
            return False
        else:
            mi = MemberInterface(contract_address=sender.contract_address)
            if action == 'approve':
                method = getattr(mi, 'approve_level_up')
            else:
                method = getattr(mi, 'reset_candidate_action')
            try:
                txn_hash = method(vacancy.company.contract_address,
                                  vacancy.uuid, candidate.contract_address)
            except Exception as e:
                logger.error('Error {} member on vacancy {}: {}'.format(
                    action, vacancy_id, e))
            else:
                save_txn.delay(txn_hash.hex(), 'CandidateActionUpDown',
                               sender_id, candidate_id, vacancy_id)
                save_txn_to_history.delay(
                    sender_id, txn_hash.hex(),
                    'Member {} {} on vacancy {}.'.format(
                        candidate.full_name, action == 'approve' and 'approved'
                        or 'revoked', vacancy.title))
                save_txn_to_history.delay(
                    candidate_id, txn_hash.hex(),
                    '{} on vacancy {}.'.format(action.capitalize(),
                                               vacancy.title))
                return True
Ejemplo n.º 13
0
def change_member_role(company_address, member_id, sender_id, role):
    try:
        sender = Member.objects.get(pk=sender_id)
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member not found and will not be added to company.')
    else:
        mi = MemberInterface(sender.contract_address)
        c_role = company_member_role(company_address, member.contract_address)
        if role == c_role:
            logger.info('Member already {} in company {}'.format(
                role, company_address))
            return False

        if c_role == 'owner':
            try:
                mi.del_owner_member(company_address, member.contract_address)
            except Exception as e:
                logger.warning('Cant delete owner member role: {} {}'.format(
                    member_id, e))
        elif c_role == 'collaborator':
            try:
                mi.del_collaborator_member(company_address,
                                           member.contract_address)
            except Exception as e:
                logger.warning(
                    'Cant delete collaborator member role: {} {}'.format(
                        member_id, e))

        method = getattr(mi, 'new_company_{}'.format(role))
        try:
            txn_hash = method(company_address, member.contract_address)
        except Exception as e:
            logger.warning('Cant add {} member role: {} {}'.format(
                role, member_id, e))
        else:
            save_txn.delay(txn_hash.hex(), 'ChangeCompanyMember', sender_id,
                           member_id)
            save_txn_to_history.delay(
                sender_id, txn_hash.hex(),
                'Change {} as company {}'.format(member.full_name, role))
            return True