Exemplo n.º 1
0
def migrate_from_workspaces(apps, schema_editor):

    if not workspace_exists():
        return

    cursor = connection.cursor()
    cursor.execute("ALTER TABLE public.vaultier_member ALTER COLUMN workspace_id DROP NOT NULL;")
    cursor.execute("SELECT * FROM vaultier_workspace")
    nodes = []
    for w in _dictfetchall(cursor):
        node = Node(
            name=w['name'],
            meta=json.dumps({'description': w['description']}),
            created_by_id=w['created_by_id'],
            type=1


        )
        node.save()
        node.acl.initialize_node()
        node._workspace = w['id']
        nodes.append(node)
        _migrate_members(node)
        _migrate_vaults(node)
        _migrate_acl('workspace', w['id'], node)
Exemplo n.º 2
0
def logup(request):
    if request.method == 'POST':
        form = LogupForm(request.POST)
        if not form.is_valid():
            # return "form invalid"
            render(request, 'accounts/logup.html', {'form': form})
        else:

            email = form.cleaned_data.get('email')
            enterprise = form.cleaned_data.get('enterprise')
            first_name = form.cleaned_data.get('first_name')
            last_name = form.cleaned_data.get('last_name')
            password = form.cleaned_data.get('password')
            MyUser.objects.create_myuser(email=email, enterprise=enterprise, first_name=first_name, last_name=last_name,
                                         password=password,)

            myuser = authenticate(email=email, password=password)
            # myuser.backend = 'django.contrib.auth.backends.ModelBackend'
            # authenticate(email=email, password=password)
            login(request, myuser)
            welcome_post = u'{0} from {1} has joined the network.'.format(myuser.first_name, myuser.enterprise)
            node = Node(myuser=myuser, post=welcome_post)
            node.save()
            myuser.myuserprofile.notify_joined(enterprise=enterprise, node=node)
            return redirect('/enterprise/'+myuser.enterprise.slug)
    else:
        return render(request, 'accounts/logup.html', {'form': LogupForm()})
Exemplo n.º 3
0
def register(request):
    if request.method == "POST":
        form = EnterpriseRegistrationForm(request.POST)
        if not form.is_valid():
            print("form invalid")
            render(request, 'enterprise/register.html', {'form': form})
        else:
            enterprise = form.cleaned_data.get('enterprise')
            types = form.cleaned_data.get('types')
            # assets = form.cleaned_data.get('assets')

            operations = form.cleaned_data.get('operations')
            materials = form.cleaned_data.get('materials')

            # t, created= Type.objects.get_or_create(name=types)
            # a, creted = Asset.objects.get_or_create(name=assets)
            er = Enterprise.objects.create(enterprise=enterprise,)
            er.types = types
            # er.assets = assets
            er.operations = operations
            er.materials = materials

            welcome = u'{0} is now in the network, have a look at its profile.'.format(enterprise)
            node = Node(myuser=MyUser.objects.get(pk=1), post=welcome)
            node.save()

            return redirect('/accounts/logup')
    else:
        return render(request, 'enterprise/register.html', {'form': EnterpriseRegistrationForm()})
Exemplo n.º 4
0
def follow(request):
    myuser = request.user
    # to_us = MyUser.objects.get(id=request.POST['to_user'])
    if request.method == 'POST':
        to_use = MyUser.objects.get(id=request.POST['to_user'])
        to_user = MyUser.objects.get(id=request.POST['to_user']).myuserprofile
        rel, created = Relationship.objects.get_or_create(
            from_user=myuser.myuserprofile,
            to_user=to_user,
            defaults={'status': 'F'}
        )
        if created:
            follow_post = u'{0}from {1} is now following you.'.format(myuser.first_name, myuser.enterprise)

            node = Node(myuser=myuser, post=follow_post, is_active=False)
            node.save()

            myuser.myuserprofile.notify_followed(user=to_use, node=node)

        if not created:
            rel.status = 'F'
            rel.save()

        return HttpResponseRedirect('/user/'+to_use.slug)
    else:
        return HttpResponseRedirect('/')
Exemplo n.º 5
0
def enterprise_profile_edit(request, slug):
    enterprise = request.user.enterprise
    page_enterprise = get_object_or_404(Enterprise, slug=slug)    
    if request.method == 'POST':
        
        form = EnterpriseProfileForm(request.POST, request.FILES)
        print(form.errors)
        if form.is_valid():
            image = form.cleaned_data.get('image')
            about = form.cleaned_data.get('about')
            contact = form.cleaned_data.get('contact')
            website = form.cleaned_data.get('website')
            address = form.cleaned_data.get('address')
            capabilities = form.cleaned_data.get('capabilities')
            people_detail = form.cleaned_data.get('people_detail')
            product_intro = form.cleaned_data.get('product_intro')

            ep = EnterpriseProfile.objects.get(enterprise=enterprise)

            ep.image = image
            ep.image_thumbnail = image
            ep.address = address
            ep.contact = contact
            ep.about = about
            ep.website = website
            ep.capabilities = capabilities
            ep.people_detail = people_detail
            ep.product_intro = product_intro
            ep.save()

            myuser = request.user
            edit_post = u'{0} from {1} has edited the enterprise profile.'.format(myuser.first_name, myuser.enterprise)
            node = Node(myuser=myuser, post=edit_post)
            node.save()

            myuser.myuserprofile.notify_edited(enterprise=enterprise, node=node)

            return redirect('/enterprise/'+ slug)
        else:
            print('wtf')

    else:
        form = EnterpriseProfileForm(instance=enterprise, initial={
            'about': enterprise.enterpriseprofile.about,
            'address': enterprise.enterpriseprofile.address,
            'contact': enterprise.enterpriseprofile.contact,
            'website': enterprise.enterpriseprofile.website,
            'image': enterprise.enterpriseprofile.get_image,
            'capabilities': enterprise.enterpriseprofile.capabilities,
            'people_detail': enterprise.enterpriseprofile.people_detail,
            'product_intro': enterprise.enterpriseprofile.product_intro,
            })
    return render(request, 'enterprise_profile/enterprise_profile_edit.html', {'form':form,'page_enterprise':page_enterprise})
Exemplo n.º 6
0
def _migrate_secret(card_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_secret WHERE card_id = %s",
                   [card_node._card])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            created_by_id=c['created_by_id'],
            parent=card_node,
            type=2
        )
        node.save(force_insert=True)
Exemplo n.º 7
0
    def handle(self, *args, **options):
        known_nodes = set(Node.objects.values_list('id', flat=True))

        res = requests.get(URL)
        res.raise_for_status()

        reader = csv.DictReader(codecs.iterdecode(res.iter_lines(), 'utf-8'))
        for row in reader:
            if row['node_id'] not in known_nodes:
                self.stdout.write(f'Adding node {row["node_id"]}')

                vsn = row['vsn']
                location = row['location']
                description = row['description']

                if '(T)' in description or 'Returned' in location or 'RET' in vsn:
                    state = 'decommissioned'
                elif 'Surya Burn-In' in location:
                    state = 'burn in'
                elif '!' in vsn:
                    state = 'testing'
                elif vsn is not None:
                    state = 'deployed'
                else:
                    state = 'build out'

                Node(id=row['node_id'],
                     name=vsn,
                     ssh_port=row['reverse_ssh_port'],
                     address=location,
                     description=description,
                     state=state).save()
Exemplo n.º 8
0
def profile(request, slug):
    context = RequestContext(request)
    page_user = get_object_or_404(MyUser, slug=slug)
    user = request.user
    page_user_profile = page_user.myuserprofile
    all_feeds = Node.get_feeds().filter(myuser=page_user)
    # paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    # feeds = paginator.page(1)
    # from_feed = -1
    # if feeds:
    #     from_feed = feeds[0].id
    #feed_nodes = Node.objects.filter(myuser=request.user, category='F')
    skillset = page_user_profile.skillset.all()

    try:
        relationship_status = Relationship.objects.get(to_user_id=page_user.myuserprofile.id,
                                                       from_user_id=request.user.myuserprofile.id).status
    except:
        relationship_status = 'none'
    # relationship_status = Relationship.objects.get(to_user_id=page_user.myuserprofile.id,
    #                                                from_user_id=request.user.myuserprofile.id).status
    data={'skillset': skillset,
          'relationship_status': relationship_status,
          'feeds': all_feeds,
          'user': user,
          'page_user': page_user,
          'page_user_profile': page_user_profile,
        #  'nodes': feed_nodes
    }
    return render_to_response('myuserprofile/profile.html', data, context_instance=context)
Exemplo n.º 9
0
def _migrate_vaults(workspace_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_vault WHERE workspace_id = %s",
                   [workspace_node._workspace])
    for v in _dictfetchall(cursor):
        node = Node(
            name=v['name'],
            meta=json.dumps({'description': v['description']}),
            created_by_id=v['created_by_id'],
            color=v['color'],
            parent=workspace_node,
            type=1
        )
        node.save(force_insert=True)
        node._vault = v['id']
        _migrate_cards(node)
        _migrate_acl('vault', v['id'], node)
Exemplo n.º 10
0
def _migrate_cards(vault_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_card WHERE vault_id = %s",
                   [vault_node._vault])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            meta=json.dumps({'description': c['description']}),
            created_by_id=c['created_by_id'],
            parent=vault_node,
            type=1
        )
        node._card = c['id']
        node.save(force_insert=True)
        _migrate_secret(node)
        _migrate_acl('card', c['id'], node)
Exemplo n.º 11
0
def post(request):
    if request.method == 'POST':

        print("f**k")
        post = request.POST['post']

        # post = request.POST.get('post')
# >>>>>>> origin/master
        myuser = request.user

        node = Node(post=post, myuser=myuser)
        node.save()

        return HttpResponseRedirect('/')

    else:
        return HttpResponseRedirect('/')
Exemplo n.º 12
0
def nodes(request):
    all_nodes = Node.get_feeds()
    paginator = Paginator(all_nodes, NODES_NUM_PAGES)
    nodes = paginator.page(1)

    return render(request, 'nodes/nodes.html', {
        'nodes': nodes,
        'page': 1,
        })
Exemplo n.º 13
0
def activity(request):
    if request.user.is_authenticated():
        feed_nodes = Node.get_feeds()
        comment_nodes = Node.objects.filter(myuser=request.user, category='C')
        c = {'user': request.user,
             'profile': MyUserProfile.objects.get(myuser=request.user),
             'feed_nodes': feed_nodes}
        return render_to_response('user_home.html', c)
    else:
        return render(request, 'home.html')
Exemplo n.º 14
0
def home(request):
    if request.user.is_authenticated():
        all_feed_nodes = Node.get_feeds()
        paginator = Paginator(all_feed_nodes, NODES_NUM_PAGES)
        feed_nodes = paginator.page(1)
        comment_nodes = Node.objects.filter(myuser=request.user, category='C')
        all_users = MyUser.objects.all().order_by('-last_login')[:10]
        all_enterprises = Enterprise.objects.all()[:4]
        all_products = EnterpriseProduct.objects.all()[:4]
        c = {'user': request.user,
             'profile': MyUserProfile.objects.get(myuser=request.user),
             'feed_nodes': feed_nodes,
             'page': 2,
             'all_users': all_users,
             'all_enterprises': all_enterprises,
             'all_products':all_products}
        return render_to_response('user_home.html', c, context_instance=RequestContext(request))
    else:
        return render(request, 'home.html')
Exemplo n.º 15
0
    @property
    def name(self):
        return self.server.name


###  Signals  ###

# update the node set_state on tinc config update
def tinchost_changed(sender, instance, **kwargs):
    # Do nothing while loading fixtures or running migrations
    if kwargs.get('raw', False):
        return
    if hasattr(instance.content_object, 'update_set_state'): # is a node
        instance.content_object.update_set_state()

post_save.connect(tinchost_changed, sender=TincHost)
post_delete.connect(tinchost_changed, sender=TincHost)


# Monkey-Patching Section
tinc = property(get_tinc)

# Hook TincHost support to Node

Node.add_to_class('related_tinc', generic.GenericRelation('tinc.TincHost'))
Node.add_to_class('tinc', tinc)

# Hook TincHost support to Server
Server.add_to_class('related_tinc', generic.GenericRelation('tinc.TincHost'))
Server.add_to_class('tinc', tinc)