Example #1
0
    def post(self):

        ID = self.get_argument('id', '')
        if not ID:
            return self.myfinish(
                _('Please give me the appliance id.') )

        ID_LIST = [ self.get_int(x) for x in ID.split(',') ]

        attr = self.get_argument('attr', None)
        value = self.get_argument('value', '').lower().strip()

        if not attr:
            return self.myfinish( _('No attr find.') )

        if attr not in ['isprivate', 'isuseable']:
            return self.myfinish( _('Can not support attr: %s') % attr )

        if not value:
            return self.myfinish( _('No value find.') )

        self.attr = attr
        self.value = value

        isadmin = has_permission('admin')
        myid = self.current_user.id

        data = []
        for ID in ID_LIST:
            
            d = { 'code': 1, 'id': ID }

            A = self.db.query(Appliance).get(ID)

            if A:

                if ( myid == A.user_id or isadmin ):
                    _call = getattr(self, 'set_' + attr)
                    r = _call( A )
                    if r:
                        d['string'] = r
                    else:
                        d['code'] = 0
                else:
                    d['string'] = _('No permissions to set attr')
            else:
                d['string'] = _('Can not find instance %s.') % ID

            data.append( d )

        self.db.commit()

        code = 0
        string = _('Set attr (%s) success.') % attr
        for x in data:
            if d['code']:
                string = _('Have something failed.')
                code = 1

        self.myfinish(string = string, code = code, data = data)
Example #2
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        I = self.db2.query(Instance).get(ID)

        if I:
            if not ( self.current_user.id == I.user_id or
                     has_permission('admin') ):
                return self.write( self.trans(_('No permissions !')) )

            msg = None
            target = self.get_argument('target', None)
            if not target:
                msg = self.trans(_('No target found !'))
            elif target == 'use_global_passwd':
                msg = self.toggle_use_global_passwd(I)
            else:
                msg = self.trans(_('Not support target: %s')) % target

            if msg: return self.write( msg )

            self.db2.commit()
            # no news is good news

        else:
            self.write( self.trans(_('Can not find instance %s.')) % ID )
Example #3
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        I = self.db2.query(Instance).get(ID)

        if I:
            if not (self.current_user.id == I.user_id
                    or has_permission('admin')):
                return self.write(self.trans(_('No permissions !')))

            msg = None
            target = self.get_argument('target', None)
            if not target:
                msg = self.trans(_('No target found !'))
            elif target == 'use_global_passwd':
                msg = self.toggle_use_global_passwd(I)
            else:
                msg = self.trans(_('Not support target: %s')) % target

            if msg: return self.write(msg)

            self.db2.commit()
            # no news is good news

        else:
            self.write(self.trans(_('Can not find instance %s.')) % ID)
Example #4
0
    def post(self):

        ID = self.get_argument('id', '')
        if not ID:
            return self.myfinish(
                _('Please give me the appliance id.') )

        ID_LIST = [ self.get_int(x) for x in ID.split(',') ]

        attr = self.get_argument('attr', None)
        value = self.get_argument('value', '').lower().strip()

        if not attr:
            return self.myfinish( _('No attr find.') )

        if attr not in ['isprivate', 'isuseable']:
            return self.myfinish( _('Can not support attr: %s') % attr )

        if not value:
            return self.myfinish( _('No value find.') )

        self.attr = attr
        self.value = value

        isadmin = has_permission('admin')
        myid = self.current_user.id

        data = []
        for ID in ID_LIST:
            
            d = { 'code': 1, 'id': ID }

            A = self.db.query(Appliance).get(ID)

            if A:

                if ( myid == A.user_id or isadmin ):
                    _call = getattr(self, 'set_' + attr)
                    r = _call( A )
                    if r:
                        d['string'] = r
                    else:
                        d['code'] = 0
                else:
                    d['string'] = _('No permissions to set attr')
            else:
                d['string'] = _('Can not find instance %s.') % ID

            data.append( d )

        self.db.commit()

        code = 0
        string = _('Set attr (%s) success.') % attr
        for x in data:
            if d['code']:
                string = _('Have something failed.')
                code = 1

        self.myfinish(string = string, code = code, data = data)
Example #5
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        A = self.db.query(Appliance).get(ID)

        if A:
            if not ( self.current_user.id == A.user_id or
                     has_permission('admin') ):
                return self.write( self.trans(_('No permissions !')) )

            A.isuseable = not A.isuseable
            self.db.commit()
            # no news is good news

        else:
            self.write( self.trans(_('Can not find appliance %s.')) % ID )
Example #6
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        I = self.db2.query(Instance).get(ID)

        if I:
            if not ( self.current_user.id == I.user_id or
                     has_permission('admin') ):
                return self.write( self.trans(_('No permissions !')) )

            I.isprivate = not I.isprivate
            self.db2.commit()
            # no news is good news

        else:
            self.write( self.trans(_('Can not find instance %s.')) % ID )
Example #7
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        I = self.db2.query(Instance).get(ID)

        if I:
            if not (self.current_user.id == I.user_id
                    or has_permission('admin')):
                return self.write(self.trans(_('No permissions !')))

            I.isprivate = not I.isprivate
            self.db2.commit()
            # no news is good news

        else:
            self.write(self.trans(_('Can not find instance %s.')) % ID)
Example #8
0
    def get(self, ID):

        self.set_header("Cache-Control", "no-cache")
        self.set_header("Pragma", "no-cache")
        self.set_header("Expires", "-1")

        A = self.db2.query(Appliance).get(ID)

        if A:
            if not (self.current_user.id == A.user_id
                    or has_permission('admin')):
                return self.write(self.trans(_('No permissions !')))

            A.isuseable = not A.isuseable
            self.db2.commit()
            # no news is good news

        else:
            self.write(self.trans(_('Can not find appliance %s.')) % ID)