Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

sample_set_list.py 4.24 KB
Newer Older
1
class SampleSetList():
2 3 4 5 6
    '''
    Deals with a list of a type of sample set (either patient, run or set).

    This class is used to load all the required information for such a list.
    '''
7 8 9
    def __init__(self, helper, page=None, step=None, tags=None):
        self.type = helper.get_type()
        s_table = db[self.type]
Ryan Herbert's avatar
Ryan Herbert committed
10

Ryan Herbert's avatar
Ryan Herbert committed
11 12 13 14
        limitby = None
        if page is not None and step is not None:
            limitby = (page*step, (page+1)*step+1) # one more element to indicate if another page exists

Ryan Herbert's avatar
Ryan Herbert committed
15 16 17
        left = [db.sample_set_membership.on(s_table.sample_set_id == db.sample_set_membership.sample_set_id),
                db.sequence_file.on(db.sample_set_membership.sequence_file_id == db.sequence_file.id),
                db.fused_file.on(s_table.sample_set_id == db.fused_file.sample_set_id),
18
                db.config.on(db.fused_file.config_id == db.config.id),
19 20 21 22
                db.auth_permission.on(
                    (db.auth_permission.table_name == 'sample_set') &
                    (db.auth_permission.record_id == s_table.sample_set_id) &
                    (db.auth_permission.name == PermissionEnum.access.value)),
23
                db.auth_group.on(db.auth_permission.group_id == db.auth_group.id),
24
                db.auth_membership.on(db.auth_group.id == db.auth_membership.group_id),
25 26 27 28 29 30 31
                db.auth_permission.with_alias('anon_permission').on(
                    (db.anon_permission.table_name == self.type) &
                    (db.anon_permission.name == "anon")  &
                    (db.anon_permission.record_id == s_table.id) &
                    (db.auth_group.id == db.anon_permission.group_id ) &
                    (db.auth_membership.user_id == auth.user_id) &
                    (db.auth_membership.group_id == db.auth_group.id))
Ryan Herbert's avatar
Ryan Herbert committed
32 33 34 35 36 37 38
                ]

        group_configs = get_conf_list_select()
        group_config_ids = get_config_ids_select()
        group_config_names = get_config_names_select()
        group_group_names = get_group_names_select()

39 40 41 42
        dedicated_fields = helper.get_dedicated_fields()

        groupby = [s_table.id, s_table.sample_set_id, s_table.info, db.auth_user.last_name]
        groupby += helper.get_dedicated_group()
Ryan Herbert's avatar
Ryan Herbert committed
43

Ryan Herbert's avatar
Ryan Herbert committed
44
        query = ((auth.vidjil_accessible_query('read', db.sample_set)) &
Ryan Herbert's avatar
Ryan Herbert committed
45
            (s_table.sample_set_id == db.sample_set.id) &
Ryan Herbert's avatar
Ryan Herbert committed
46 47 48
            (s_table.creator == db.auth_user.id))

        select = [
Ryan Herbert's avatar
Ryan Herbert committed
49 50 51 52 53 54
            s_table.id.with_alias('id'),
            s_table.sample_set_id.with_alias('sample_set_id'),
            s_table.info.with_alias('info'),
            db.auth_user.last_name.with_alias('creator'),
            db.sequence_file.size_file.sum().with_alias('size'),
            db.sequence_file.id.count().with_alias('file_count'),
55
            db.anon_permission.name.with_alias('has_permission'),
Ryan Herbert's avatar
Ryan Herbert committed
56 57 58
            group_configs,
            group_config_ids,
            group_config_names,
Ryan Herbert's avatar
Ryan Herbert committed
59 60
            group_group_names
        ]
61

62 63 64 65 66 67 68 69 70
        if (tags is not None and len(tags) > 0):
            query = filter_by_tags(query, self.type, tags)
            count = db.tag.name.count()
            query_gss = db(
                query
            ).select(
                db.tag_ref.record_id,
                db.tag_ref.table_name,
                count,
Ryan Herbert's avatar
Ryan Herbert committed
71 72
                *select + dedicated_fields,
                left=left,
73
                limitby = limitby,
74
                orderby = ~db[self.type].id,
Ryan Herbert's avatar
Ryan Herbert committed
75 76 77
                groupby = groupby + [db.tag_ref.record_id|db.tag_ref.table_name],
                having = count >= len(tags),
                cacheable=True
78 79 80 81 82
            )
        else:
            query_gss = db(
                query
            ).select(
Ryan Herbert's avatar
Ryan Herbert committed
83 84
                *select + dedicated_fields,
                left=left,
85
                limitby = limitby,
Ryan Herbert's avatar
Ryan Herbert committed
86
                groupby = groupby,
87
                orderby = ~db[self.type].id,
Ryan Herbert's avatar
Ryan Herbert committed
88
                cacheable=True
89 90
            )

Ryan Herbert's avatar
Ryan Herbert committed
91
        self.result = query_gss
HERBERT Ryan's avatar
HERBERT Ryan committed
92 93

    def __len__(self):
Ryan Herbert's avatar
Ryan Herbert committed
94
        return len(self.result)
95 96 97 98

def filter_by_tags(query, table, tags):
    if tags is not None and len(tags) > 0:
        return (query
99
            & (db.tag.name.upper().belongs([t.upper() for t in tags]))
100 101 102 103
            & (db.tag_ref.tag_id == db.tag.id)
            & (db.tag_ref.table_name == table)
            & (db.tag_ref.record_id == db[table].id))
    return query