Ejemplo n.º 1
0
    def assign_license(self, **kwargs):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Report if computer or license don't belong to user who is logged in and available > 0
        if DBSession.query(model.Computer).filter(model.Computer.id==kwargs['computer'], model.Computer.user_id==user_id).count() < 1  or DBSession.query(model.License).filter(model.License.id==kwargs['license'], model.License.user_id==user_id).count() < 1 or DBSession.query(model.License.available).filter(model.License.id==kwargs['license'], model.License.user_id==user_id).first().available < 1:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        a = model.Assignment()
        a.user_id = user_id
        a.license_id = kwargs['license']
        a.computer_id = kwargs['computer']
        a.count = 1
        a.locked = False

        model.DBSession.add(a)

        license = DBSession.query(model.License).filter(model.License.id==a.license_id).first()
        license.available = license.available - a.count


        model.DBSession.flush()

        flash("Assignment added.")
        redirect('/manage')
Ejemplo n.º 2
0
    def get_admin_panel_data(self, **kwargs):

        user_id_query = DBSession.query(model.User.user_id)

        if 'email_filter' in kwargs:
            if kwargs['email_filter'] != '':
                user_id_query = user_id_query.filter(model.User.user_name==kwargs['email_filter'])
        else:
            kwargs['email_filter'] = ''

        if 'id_filter' in kwargs:
            if kwargs['id_filter'] != '':
                user_id_query = user_id_query.filter(model.User.user_id==kwargs['id_filter'])
        else:
            kwargs['id_filter'] = ''

        if user_id_query.first():
            user_id = user_id_query.first().user_id
        else:
            user_id = 1

        admin_license_data = DBSession.query(model.User, model.License, model.Plugin, model.LicenseType).join(model.License).join(model.Plugin).join(model.LicenseType).filter(model.User.user_id==user_id)

        admin_computer_data = DBSession.query(model.User, model.Computer).join(model.Computer).filter(model.User.user_id==user_id)


        return dict(page='admin_panel', admin_computer_data=admin_computer_data[:10], admin_license_data=admin_license_data, admin_license_grid=admin_license_grid, admin_computer_grid=admin_computer_grid, assign_licences_form=AssignLicensesForm, create_user_form=CreateUserForm, data=kwargs)
Ejemplo n.º 3
0
    def get_manage_data(self):
        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first()
        license_data = DBSession.query(model.License, model.Plugin, model.LicenseType).join(model.User).join(model.Plugin).join(model.LicenseType).filter(model.User.user_name==user_name)
        computer_data = DBSession.query(model.Computer).join(model.User).filter(model.User.user_name==user_name)
        assignment_data = DBSession.query(model.Assignment, model.Computer, model.Plugin).join(model.Computer).join(model.License).join(model.Plugin).filter(model.License.user_id==user_id.user_id)
        computer_list = DBSession.query(model.Computer).join(model.User).filter(model.User.user_name==user_name).all()

        return dict(page='manage', add_computer_form=AddComputerForm, assignment_form=AssignmentForm, license_grid=license_grid, computer_grid=computer_grid, assignment_grid=assignment_grid, license_data=license_data, computer_data=computer_data, assignment_data=assignment_data, user_id=user_id)
Ejemplo n.º 4
0
    def delete_assignment(self, **data):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Report if not user who is logged in
        if DBSession.query(model.License).join(model.Assignment).filter(model.Assignment.id==data['id'], model.License.user_id==user_id).count() < 1:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        locked = DBSession.query(model.Assignment.locked).filter(model.Assignment.id==data['id']).first().locked

        if locked == True:
            flash(_('Cannot delete. Assignment already redeemed.'), 'warning')
        else:
            license = DBSession.query(model.License).join(model.Assignment).filter(model.Assignment.id==data['id']).first()

            license.available = license.available + DBSession.query(model.Assignment).filter(model.Assignment.id==data['id']).first().count

            q = DBSession.query(model.Assignment).filter(model.Assignment.id==data['id']).delete()

            DBSession.flush()

            flash('Assignment deleted')

        redirect('/manage')
Ejemplo n.º 5
0
    def delete_computer(self, **data):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Report if no assignments and cbelongs to user who is loggned in
        if DBSession.query(model.Computer).filter(model.Computer.id==data['id'], model.Computer.user_id==user_id).count() < 1  or DBSession.query(model.Assignment).filter(model.Assignment.computer_id==data['id'], model.Assignment.user_id==user_id).count() > 0:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        name = DBSession.query(model.Computer.display_name).filter(model.Computer.id==data['id']).first()[0]

        q = DBSession.query(model.Computer).filter(model.Computer.id==data['id']).delete()

        flash("Computer deleted: '" + name + "'")
        redirect('/manage')
Ejemplo n.º 6
0
    def create_user(self, **kwargs):

        name = kwargs['name']
        email = kwargs['login_email'].lower()

        if DBSession.query(model.User).filter(model.User.user_name==email).count() > 0:
            flash(email + ' already exists!', 'error')
            kwargs['login_email']=''
            return self.admin_panel(**kwargs)
            #redirect('/admin_panel', kwargs)

        password = ''.join(random.choice(string.letters + string.digits + string.punctuation) for x in xrange(8))

        u = model.User()
        u.user_name = email
        u.display_name = name
        u.password = password

        licensing_portal_url = "licensing.authorityfx.com"

        subject = "New Authority FX Licensing Portal Account"
        body =    "Dear " + name + ",\n" \
                + "\n" \
                + "Please login into your new Authority FX licensing portal account with the following credentials: \n" \
                + "\n" \
                + licensing_portal_url + "\n" \
                + "\n" \
                + "username: "******"\n" \
                + "password: "******"\n" \
                + "\n" \
                + "We suggest that you change you password upon first login.\n" \
                + "\n" \
                + "Remember that all purchases are added into our licensing portal under the email address provided at checkout.  "\
                + "If you want to make puchases using another email address, please ensure that you change your login email via the " \
                + "settings page prior to making any new purchases.\n" \
                + "\n" \
                + "Thanks!"

        try:
            sender = SendMail()
            sender.send_mail(email, subject, body)
            DBSession.add(u)
            DBSession.flush()
            flash(email + ' added and notified via email.')
        except Exception, e:
            flash(('Could not send new login to ' + name + ", " + email + ": " + str(e)), 'error')
Ejemplo n.º 7
0
    def post_login(self, came_from=lurl('/')):

        if not request.identity:
            login_counter = request.environ.get('repoze.who.logins', 0) + 1
            redirect('/login',
                params=dict(came_from=came_from, __logins=login_counter))
        user_name = request.identity['repoze.who.userid']
        display_name = str(DBSession.query(model.User.display_name).filter(model.User.user_name==user_name).first()[0])
        flash(_('Welcome back, %s!') % display_name)
        redirect('/manage')
Ejemplo n.º 8
0
    def create_license(self, **data):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Make sure that the computer_id belongs to user who is loggned in and that it has assignments
        if DBSession.query(model.Computer).filter(model.Computer.id==data['id'], model.Computer.user_id==user_id).count() < 1  or DBSession.query(model.Assignment).filter(model.Assignment.computer_id==data['id'], model.Assignment.user_id==user_id).count() < 1:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        assignments = DBSession.query(model.Assignment.id).join(model.Computer).filter(model.Computer.id==data['id']).all()

        grouped_assignments = DBSession.query(func.sum(model.Assignment.count).label('count_sum'), model.Assignment, model.Computer, model.License).join(model.Computer).join(model.License).filter(model.Computer.id==data['id']).group_by(model.License.id).all()

        plain_license = LicenseFormat()

        for assignment in grouped_assignments:
            floating = 0
            if assignment.License.floating == True:
                floating = 1
            plain_license.add_plugin(assignment.License.plugin_id, assignment.License.l_type, assignment.count_sum, floating)

        plain_license.set_uuid1(grouped_assignments[0].Computer.uuid1)
        plain_license.set_uuid2(grouped_assignments[0].Computer.uuid2)

        plain_license.set_user_id(grouped_assignments[0].Computer.user_id)

        try:
            afx_ip = DBSession.query(model.Settings.afx_ip).first().afx_ip
            client = LicenseClient(afx_ip, 31568)
            license = client.get_license(plain_license.format_license())

            if license.find('Licensing Error') >= 0:
                flash(_("Licensing Error. Please email [email protected]"), 'warning')
                redirect('/manage')
            else:
                for assignment in assignments:
                    #Lock assignment
                    a = DBSession.query(model.Assignment).filter(model.Assignment.id==assignment.id).first()
                    a.locked = True
                    DBSession.flush()

                #Serve license file
                rh = response.headers
                rh['Content-Type'] = 'application/csv; charset=utf-8'
                disposition = 'attachment; filename="afx-license.dat"'
                rh['Content-disposition'] = disposition
                return license
        except:
            flash(_("Licensing Error. Please email [email protected]"), 'warning')
            redirect('/manage')
Ejemplo n.º 9
0
def createLicenseList(obj):
    licenses = DBSession.query(func.sum(model.Assignment.count).label('count_sum'), model.Assignment, model.Plugin, model.License, model.LicenseType).join(model.License).join(model.Plugin).join(model.LicenseType).filter(model.Assignment.computer_id==obj.id, model.Assignment.user_id==obj.user_id).group_by(model.License.id).all()

    if len(licenses) > 0:
        license_list = '(' + str(len(licenses)) + ') license' + ('s' if len(licenses) > 1 else '') + ': '
    else:
        license_list = 'No licenses assigned'
    for license in licenses:
        floating = ''
        if license.License.floating == True:
            floating = ':floating'
        license_list += license.Plugin.display_name + ":" + license.LicenseType.display_name + floating + ":" + str(license.count_sum) +  ", "

    return license_list.strip().strip(',')
Ejemplo n.º 10
0
    def add_computer(self, **kwargs):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        c = model.Computer()
        c.user_id = user_id
        c.display_name = kwargs['name']
        c.uuid1 = kwargs['mac']
        c.uuid2 = u'none'
        model.DBSession.add(c)

        model.DBSession.flush()

        flash("Computer added: '" + c.display_name + "'")
        redirect('/manage')
Ejemplo n.º 11
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Ejemplo n.º 12
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Ejemplo n.º 13
0
 def test_query_obj(self):
     """Model objects can be queried"""
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)
Ejemplo n.º 14
0
def get_licenses(user_id):
    return DBSession.query(model.License, model.Plugin, model.LicenseType).join(model.Plugin).join(model.LicenseType).filter(model.License.user_id==user_id, model.License.available > 0).all()
Ejemplo n.º 15
0
 def by_email_address(cls, email):
     """Return the user object whose email address is ``email``."""
     return DBSession.query(cls).filter_by(email_address=email).first()
Ejemplo n.º 16
0
 def by_user_name(cls, username):
     """Return the user object whose user name is ``username``."""
     return DBSession.query(cls).filter_by(user_name=username).first()
Ejemplo n.º 17
0
 def test_query_obj(self):
     """Model objects can be queried"""
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)
Ejemplo n.º 18
0
 def tearDown(self):
     """Finish model test fixture."""
     DBSession.rollback()
Ejemplo n.º 19
0
def removeAssignment(obj):
    locked = DBSession.query(model.Assignment.locked).filter(model.Assignment.id==obj.Assignment.id, model.Assignment.user_id==obj.Assignment.user_id).first().locked
    if locked == True:
        return ''
    else:
        return genshi.Markup('<a href="%s">Delete</a>' % url('/delete_assignment', params=dict(id=obj.Assignment.id)))
Ejemplo n.º 20
0
def redeemLicense(obj):
    count = DBSession.query(model.Assignment).filter(model.Assignment.computer_id==obj.id, model.Assignment.user_id==obj.user_id).count()
    if count  > 0:
        return  genshi.Markup('<form method="POST" action="%s" class="button-to"><input type="hidden" name="_method" value="DELETE" /><input class="delete-button" onclick="return confirm(\'All assignments to this computer will be locked.  Are you sure you want to redeem the assigned licenses?\');" value="Redeem" type="submit" style="background-color:transparent; float:left; border:0; color: #286571; display:inline; margin:0; padding:0;"/></form>' % url('/create_license', params=dict(id=obj.id)))
    else:
        return genshi.Markup('<a href="%s">Delete </a>' % url('/delete_computer', params=dict(id=obj.id)))
Ejemplo n.º 21
0
def get_computers(user_id):
    return DBSession.query(model.Computer).filter(model.Computer.user_id==user_id).all()
Ejemplo n.º 22
0
    def update_settings(self, **kwargs):

        fail = False
        changed = False
        update_password = False
        update_email = False
        msg = ''

        #Get user
        user_name = request.identity['repoze.who.userid']
        user = DBSession.query(model.User).filter(model.User.user_name==user_name).first()

        #Check if current password matches
        if user.validate_password(kwargs['current_password']) == False:
            fail = True
            msg = msg + "  Wrong password!"

        #Update name
        if fail != True and 'name' in kwargs:

            if len(kwargs['name']) > 0:

                #Hash new password
                user.display_name = kwargs['name']
                msg = msg + "  Successfully changed name."
                changed = True

        #Update email
        if fail != True and 'login_email' in kwargs:

            if len(kwargs['login_email']) > 0:

                new_email = kwargs['login_email'].lower()

                count = DBSession.query(model.User).filter(model.User.user_name==new_email).count()

                if count == 0:
                    user.user_name = new_email
                    msg = msg + '  Successfully changed login email.'
                    changed = True
                else:
                    fail = True
                    msg = msg + '  Email address already assigned.'


        #Update passwood
        if fail != True and 'new_password' in kwargs:

            if len(kwargs['new_password']) > 0:

                #Hash new password
                user._set_password(kwargs['new_password'])
                msg = msg + "  Successfully changed password."
                changed = True


        #if no errors write to database
        if fail != True and changed == True:
            DBSession.flush()
            flash(msg.strip())
            redirect('/logout_handler')
        elif fail != True and changed == False:
            flash('No Updates', 'warning')
            return dict(page='settings', form=SettingsForm, data=kwargs)
        else:
            flash(msg.strip(), 'error')
            return dict(page='settings', form=SettingsForm, data=kwargs)
Ejemplo n.º 23
0
 def prepare(self):
     self.child.c.licenses.options = [(i.id, i.display_name) for i in DBSession.query(model.Plugin).all()]
     self.child.c.license_type.options = [(i.id, i.display_name) for i in DBSession.query(model.LicenseType).all()]
     super(AssignLicensesForm, self).prepare()
Ejemplo n.º 24
0
def get_available(user_id):
    licenses = DBSession.query(model.License).filter(model.License.user_id==user_id, model.License.available > 0).all()

    list = []
    for i in licenses:
        list.append
Ejemplo n.º 25
0
 def tearDown(self):
     """Finish model test fixture."""
     DBSession.rollback()