Esempio n. 1
0
 def create_action(name, type_):
     action = dbs.query(SapnsPermission).\
                 filter(and_(SapnsPermission.class_id == klass.class_id,
                             SapnsPermission.type == type_)).\
                 first()
                     
     if not action:
         action = SapnsPermission()
         action.permission_name = '%s#%s' % (klass.name, name.lower())
         action.display_name = name
         action.type = type_
         action.class_id = klass.class_id
         
         dbs.add(action)
         dbs.flush()
         
         # add this action to "managers" role
         managers.permissions_.append(action)
         dbs.flush()
         
     elif action.type == SapnsPermission.TYPE_LIST:
         for s in action.shortcuts:
             s.title = action.class_.title
             dbs.add(s)
             dbs.flush()
Esempio n. 2
0
            def create_action(name, type_):
                action = dbs.query(SapnsPermission).\
                    filter(and_(SapnsPermission.class_id == klass.class_id,
                                SapnsPermission.type == type_)).\
                    first()

                if not action:
                    action = SapnsPermission()
                    action.permission_name = u'%s#%s' % (klass.name,
                                                         name.lower())
                    action.display_name = name
                    action.type = type_
                    action.class_id = klass.class_id

                    dbs.add(action)
                    dbs.flush()

                    # add this action to "managers" role
                    managers.permissions_.append(action)
                    dbs.flush()

                elif action.type == SapnsPermission.TYPE_LIST:
                    for s in action.shortcuts:
                        s.title = action.class_.title
                        dbs.add(s)
                        dbs.flush()
Esempio n. 3
0
 def __call__(self):
     
     csfp = SapnsPermission()
     csfp.class_id = SapnsClass.by_name(u'sp_permission').class_id
     csfp.permission_name = u'sp_permission#create_shortcuts'
     csfp.display_name = u'Create shortcuts'
     csfp.type = SapnsPermission.TYPE_PROCESS
     csfp.url = u'/dashboard/permissions/create_shortcuts/'
     csfp.requires_id = True
     
     dbs.add(csfp)
     dbs.flush()
     
     managers = SapnsRole.by_name(u'managers')
     managers.permissions_.append(csfp)
     dbs.flush()
Esempio n. 4
0
    def __call__(self):

        dbs = self.dbs

        roles = dbs.query(SapnsClass).\
            filter(SapnsClass.name == u'sp_roles').\
            first()

        ap_r = SapnsPermission()
        ap_r.class_id = roles.class_id
        ap_r.permission_name = u'sp_roles#copy_privileges'
        ap_r.display_name = u'Copy privileges'
        ap_r.type = SapnsPermission.TYPE_PROCESS
        ap_r.url = u'/dashboard/privileges/copy/'

        dbs.add(ap_r)

        # "managers" role
        managers = dbs.query(SapnsRole).\
            filter(SapnsRole.group_name == u'managers').\
            first()
        managers.permissions_.append(ap_r)
Esempio n. 5
0
 def __call__(self):
     
     dbs = self.dbs
     
     roles = dbs.query(SapnsClass).\
         filter(SapnsClass.name == u'sp_roles').\
         first()
     
     ap_r = SapnsPermission()
     ap_r.class_id = roles.class_id
     ap_r.permission_name = u'sp_roles#copy_privileges'
     ap_r.display_name = u'Copy privileges'
     ap_r.type = SapnsPermission.TYPE_PROCESS
     ap_r.url = u'/dashboard/privileges/copy/'
     
     dbs.add(ap_r)
     
     # "managers" role
     managers = dbs.query(SapnsRole).\
         filter(SapnsRole.group_name == u'managers').\
         first()
     managers.permissions_.append(ap_r)
Esempio n. 6
0
def create_data_exploration():
    
    managers = SapnsRole.by_name(ROLE_MANAGERS)
    #managers = SapnsRole()
    
    logger = logging.getLogger('lib.sapns.util.create_data_exploration')
    
    tables = extract_model(all=True) #['tables']

    for us in dbs.query(SapnsUser).\
        join((SapnsUserRole,
              and_(SapnsUserRole.user_id == SapnsUser.user_id,
                   SapnsUserRole.role_id == managers.group_id,
                   ))):
        
        create_dashboards(us)
        
        data_ex = us.get_dataexploration()
        sc_sapns = data_ex.by_order(0)
        sc_project = data_ex.by_order(1)
        
        # data exploration/project       
        for i, tbl in enumerate(tables):
            
            cls = dbs.query(SapnsClass).\
                    filter(SapnsClass.name == tbl['name']).\
                    first()
            
            # look for this table "list" action
            act_table = dbs.query(SapnsPermission).\
                filter(and_(SapnsPermission.type == SapnsPermission.TYPE_LIST,
                            SapnsPermission.class_id == cls.class_id)).\
                first()
                            
            if not act_table:
                act_table = SapnsPermission()
                act_table.permission_name = '%s#%s' % (cls.name, SapnsPermission.TYPE_LIST)
                act_table.display_name = unicode(l_('List'))
                act_table.type = SapnsPermission.TYPE_LIST
                act_table.class_id = cls.class_id
                
                dbs.add(act_table)
                dbs.flush()
                
                # add to "managers" role
                managers.permissions_.append(act_table)
                dbs.flush()
                
            # project
            sc_parent = sc_project.shortcut_id
            if cls.name.startswith('sp_'):
                # sapns
                sc_parent = sc_sapns.shortcut_id
                
            sc_table = dbs.query(SapnsShortcut).\
                    filter(and_(SapnsShortcut.parent_id == sc_parent,
                                SapnsShortcut.permission_id == act_table.permission_id,
                                SapnsShortcut.user_id == us.user_id,
                                )).\
                    first()
                    
            # does this user have this class shortcut?
            if not sc_table:
                sc_table = SapnsShortcut()
                sc_table.title = tbl['name']
                sc_table.parent_id = sc_parent
                sc_table.user_id = us.user_id
                sc_table.permission_id = act_table.permission_id
                sc_table.order = i
    
                dbs.add(sc_table)
                dbs.flush()
            
            else:
                logger.info('Shortcut for "%s" already exists' % cls.title)
                
        # TODO: sort (alphabetically) shortcuts inside "data exploration"
        logger.info('Sorting shortcuts inside "data exploration"')
        i = 0
        for sc in dbs.query(SapnsShortcut).\
                filter(SapnsShortcut.parent_id == sc_project.shortcut_id).\
                order_by(SapnsShortcut.title):
            
            sc.order = i
            dbs.add(sc)
            dbs.flush()
            
            i += 1
Esempio n. 7
0
    def __call__(self):
        
        dbs = self.dbs
        
        roles = dbs.query(SapnsClass).\
            filter(SapnsClass.name == u'sp_roles').\
            first()
        
        p1 = SapnsPermission()
        p1.class_id = roles.class_id
        p1.permission_name = u'sp_roles#users'
        p1.display_name = u'Users'
        p1.type = SapnsPermission.TYPE_PROCESS
        p1.url = u'/dashboard/roles/users/'
        
        dbs.add(p1)
        
        users = dbs.query(SapnsClass).\
            filter(SapnsClass.name == u'sp_users').\
            first()

        p2 = SapnsPermission()
        p2.class_id = users.class_id
        p2.permission_name = u'sp_users#roles'
        p2.display_name = u'Roles'
        p2.type = SapnsPermission.TYPE_PROCESS
        p2.url = u'/dashboard/users/roles/'
        
        dbs.add(p2)
        dbs.flush()
        
        # "managers" role
        managers = dbs.query(SapnsRole).\
            filter(SapnsRole.group_name == u'managers').\
            first()
        managers.permissions_.append(p1)
        managers.permissions_.append(p2)
Esempio n. 8
0
    def create_data_exploration(self):

        managers = SapnsRole.by_name(ROLE_MANAGERS)
        #managers = SapnsRole()

        logger = logging.getLogger('lib.sapns.util.create_data_exploration')

        tables = self.extract_model(all_=True)

        for us in dbs.query(SapnsUser).\
            join((SapnsUserRole,
                  and_(SapnsUserRole.user_id == SapnsUser.user_id,
                       SapnsUserRole.role_id == managers.group_id,
                       ))):

            self.create_dashboards(us)

            data_ex = us.get_dataexploration()
            sc_sapns = None
            sc_project = None
            if data_ex:
                sc_sapns = data_ex.by_order(0)
                sc_project = data_ex.by_order(1)

            # data exploration/project
            for i, tbl in enumerate(tables):

                cls = dbs.query(SapnsClass).\
                    filter(SapnsClass.name == tbl['name']).\
                    first()

                # look for this table "list" action
                act_table = dbs.query(SapnsPermission).\
                    filter(and_(SapnsPermission.type == SapnsPermission.TYPE_LIST,
                                SapnsPermission.class_id == cls.class_id)).\
                    first()

                if not act_table:
                    act_table = SapnsPermission()
                    act_table.permission_name = u'%s#%s' % (
                        cls.name, SapnsPermission.TYPE_LIST)
                    act_table.display_name = u'List'
                    act_table.type = SapnsPermission.TYPE_LIST
                    act_table.class_id = cls.class_id

                    dbs.add(act_table)
                    dbs.flush()

                    # add to "managers" role
                    managers.permissions_.append(act_table)
                    dbs.flush()

                # project
                sc_parent = sc_project
                if cls.name.startswith('sp_'):
                    # sapns
                    sc_parent = sc_sapns

                if sc_parent:
                    sc_table = dbs.query(SapnsShortcut).\
                        filter(and_(SapnsShortcut.parent_id == sc_parent.shortcut_id,
                                    SapnsShortcut.permission_id == act_table.permission_id,
                                    SapnsShortcut.user_id == us.user_id,
                                    )).\
                        first()

                    # does this user have this class shortcut?
                    if not sc_table:
                        sc_table = SapnsShortcut()
                        sc_table.title = tbl['name']
                        sc_table.parent_id = sc_parent.shortcut_id
                        sc_table.user_id = us.user_id
                        sc_table.permission_id = act_table.permission_id
                        sc_table.order = i

                        dbs.add(sc_table)
                        dbs.flush()

                    else:
                        logger.info(u'Shortcut for "%s" already exists' %
                                    cls.title)

            # sort (alphabetically) shortcuts inside "data exploration"
            if sc_project:
                logger.info('Sorting shortcuts inside "data exploration"')
                i = 0
                for sc in dbs.query(SapnsShortcut).\
                        filter(SapnsShortcut.parent_id == sc_project.shortcut_id).\
                        order_by(SapnsShortcut.title):

                    sc.order = i
                    dbs.add(sc)
                    dbs.flush()

                    i += 1