Exemplo n.º 1
0
    def get(self, request, format=None):
        # count repos
        try:
            repos_count = seafile_api.count_repos()
        except SearpcError as e:
            logger.error(e)
            repos_count = 0

        # count groups
        try:
            groups_count = len(ccnet_api.get_all_groups(-1, -1))
        except Exception as e:
            logger.error(e)
            groups_count = 0

        # count orgs
        if MULTI_TENANCY:
            multi_tenancy_enabled = True
            try:
                org_count = ccnet_api.count_orgs()
            except Exception as e:
                logger.error(e)
                org_count = 0
        else:
            multi_tenancy_enabled = False
            org_count = 0

        # count users
        try:
            active_db_users = ccnet_api.count_emailusers('DB')
        except Exception as e:
            logger.error(e)
            active_db_users = 0

        try:
            active_ldap_users = ccnet_api.count_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            active_ldap_users = 0

        try:
            inactive_db_users = ccnet_api.count_inactive_emailusers('DB')
        except Exception as e:
            logger.error(e)
            inactive_db_users = 0

        try:
            inactive_ldap_users = ccnet_api.count_inactive_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            inactive_ldap_users = 0

        active_users = active_db_users + active_ldap_users if \
            active_ldap_users > 0 else active_db_users

        inactive_users = inactive_db_users + inactive_ldap_users if \
            inactive_ldap_users > 0 else inactive_db_users

        # get license info
        is_pro = is_pro_version()
        if is_pro:
            license_dict = parse_license()
        else:
            license_dict = {}

        if license_dict:
            with_license = True
            try:
                max_users = int(license_dict.get('MaxUsers', 3))
            except ValueError as e:
                logger.error(e)
                max_users = 0
        else:
            with_license = False
            max_users = 0

        # count total file number
        try:
            total_files_count = seafile_api.get_total_file_number()
        except Exception as e:
            logger.error(e)
            total_files_count = 0

        # count total storage
        try:
            total_storage = seafile_api.get_total_storage()
        except Exception as e:
            logger.error(e)
            total_storage = 0

        # count devices number
        try:
            total_devices_count = TokenV2.objects.get_total_devices_count()
        except Exception as e:
            logger.error(e)
            total_devices_count = 0

        # count current connected devices
        try:
            current_connected_devices_count = TokenV2.objects.\
                    get_current_connected_devices_count()
        except Exception as e:
            logger.error(e)
            current_connected_devices_count = 0

        info = {
            'users_count': active_users + inactive_users,
            'active_users_count': active_users,
            'repos_count': repos_count,
            'total_files_count': total_files_count,
            'groups_count': groups_count,
            'org_count': org_count,
            'multi_tenancy_enabled': multi_tenancy_enabled,
            'is_pro': is_pro,
            'with_license': with_license,
            'license_expiration': license_dict.get('Expiration', ''),
            'license_mode': license_dict.get('Mode', ''),
            'license_maxusers': max_users,
            'license_to': license_dict.get('Name', ''),
            'total_storage': total_storage,
            'total_devices_count': total_devices_count,
            'current_connected_devices_count': current_connected_devices_count
        }

        return Response(info)
Exemplo n.º 2
0
    def get(self, request, format=None):
        # count repos
        try:
            repos_count = seafile_api.count_repos()
        except SearpcError as e:
            logger.error(e)
            repos_count = 0

        # count groups
        try:
            groups_count = len(ccnet_api.get_all_groups(-1, -1))
        except Exception as e:
            logger.error(e)
            groups_count = 0

        # count orgs
        if MULTI_TENANCY:
            multi_tenancy_enabled = True
            try:
                org_count = ccnet_api.count_orgs()
            except Exception as e:
                logger.error(e)
                org_count = 0
        else:
            multi_tenancy_enabled = False
            org_count = 0

        # count users
        try:
            active_db_users = ccnet_api.count_emailusers('DB')
        except Exception as e:
            logger.error(e)
            active_db_users = 0

        try:
            active_ldap_users = ccnet_api.count_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            active_ldap_users = 0

        try:
            inactive_db_users = ccnet_api.count_inactive_emailusers('DB')
        except Exception as e:
            logger.error(e)
            inactive_db_users = 0

        try:
            inactive_ldap_users = ccnet_api.count_inactive_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            inactive_ldap_users = 0

        active_users = active_db_users + active_ldap_users if active_ldap_users > 0 \
                else active_db_users

        inactive_users = inactive_db_users + inactive_ldap_users if inactive_ldap_users > 0 \
                else inactive_db_users

        is_pro = is_pro_version()
        if is_pro:
            license_dict = self._get_license_dict()
        else:
            license_dict = {}

        if license_dict:
            with_license = True
            try:
                max_users = int(license_dict.get('MaxUsers', ''))
            except ValueError as e:
                logger.error(e)
                max_users = 0
        else:
            with_license = False
            max_users = 0

        info = {
            'users_count': active_users + inactive_users,
            'active_users_count': active_users,
            'repos_count': repos_count,
            'groups_count': groups_count,
            'org_count': org_count,
            'multi_tenancy_enabled': multi_tenancy_enabled,
            'is_pro': is_pro,
            'with_license': with_license,
            'license_expiration': license_dict.get('Expiration', ''),
            'license_maxusers': max_users,
            'license_to': license_dict.get('Name', ''),
        }

        return Response(info)
Exemplo n.º 3
0
    def get(self, request, format=None):
        # count repos
        try:
            repos_count = seafile_api.count_repos()
        except SearpcError as e:
            logger.error(e)
            repos_count = 0

        # count groups
        try:
            groups_count = len(ccnet_api.get_all_groups(-1, -1))
        except Exception as e:
            logger.error(e)
            groups_count = 0

        # count orgs
        if MULTI_TENANCY:
            multi_tenancy_enabled = True
            try:
                org_count = ccnet_api.count_orgs()
            except Exception as e:
                logger.error(e)
                org_count = 0
        else:
            multi_tenancy_enabled = False
            org_count = 0

        # count users
        try:
            active_db_users = ccnet_api.count_emailusers('DB')
        except Exception as e:
            logger.error(e)
            active_db_users = 0

        try:
            active_ldap_users = ccnet_api.count_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            active_ldap_users = 0

        try:
            inactive_db_users = ccnet_api.count_inactive_emailusers('DB')
        except Exception as e:
            logger.error(e)
            inactive_db_users = 0

        try:
            inactive_ldap_users = ccnet_api.count_inactive_emailusers('LDAP')
        except Exception as e:
            logger.error(e)
            inactive_ldap_users = 0

        active_users = active_db_users + active_ldap_users if active_ldap_users > 0 \
                else active_db_users

        inactive_users = inactive_db_users + inactive_ldap_users if inactive_ldap_users > 0 \
                else inactive_db_users

        is_pro = is_pro_version()
        if is_pro:
            license_file = os.path.join(seahub.settings.PROJECT_ROOT, '../../seafile-license.txt')
            license_dict = parse_license(license_file)
        else:
            license_dict = {}

        if license_dict:
            with_license = True
        else:
            with_license = False

        info = {
            'users_count': active_users + inactive_users,
            'active_users_count': active_users,
            'repos_count': repos_count,
            'groups_count': groups_count,
            'org_count': org_count,
            'multi_tenancy_enabled': multi_tenancy_enabled,
            'is_pro': is_pro,
            'with_license': with_license,
            'license': license_dict
        }

        return Response(info)
Exemplo n.º 4
0
def test_repo_manipulation():

    #test get_system_default_repo_id
    t_default_repo_id = api.get_system_default_repo_id()
    assert t_default_repo_id

    #test create_repo
    t_repo_id = api.create_repo('test_repo_manipulation',
                                '',
                                USER,
                                passwd=None)
    assert t_repo_id

    #test counts_repo
    t_repo_count = 0
    t_repo_count = api.count_repos()
    assert t_repo_count != 0

    #test get_repo ,edit_repo
    t_new_name = 'n_name'
    t_new_desc = 'n_desc'
    t_repo_version = 1
    t_repo = api.get_repo(t_repo_id)
    assert t_repo

    api.edit_repo(t_repo_id, t_new_name, t_new_desc, USER)
    t_repo = api.get_repo(t_repo_id)
    assert t_repo.name == t_new_name and t_repo.desc == t_new_desc

    #test revert_repo and get_commit
    t_commit_id_before_changing = t_repo.head_cmmt_id

    api.post_dir(t_repo_id, '/', 'dir1', USER)
    t_repo = api.get_repo(t_repo_id)

    api.revert_repo(t_repo_id, t_commit_id_before_changing, USER)

    t_repo = api.get_repo(t_repo_id)
    t_commit_id_after_revert = t_repo.head_cmmt_id

    t_commit_before_changing = api.get_commit(t_repo_id, t_repo_version,
                                              t_commit_id_before_changing)
    t_commit_after_revert = api.get_commit(t_repo_id, t_repo_version,
                                           t_commit_id_after_revert)
    assert t_commit_before_changing.root_id == t_commit_after_revert.root_id

    #test is_repo_owner
    assert api.is_repo_owner(USER, t_repo_id)
    assert api.is_repo_owner(USER2, t_repo_id) == 0

    #test get_repo_owner
    owner_get = api.get_repo_owner(t_repo_id)
    assert owner_get == USER

    #test set_repo_owner
    api.set_repo_owner(t_repo_id, USER2)
    assert api.is_repo_owner(USER2, t_repo_id)

    #test create_enc_repo
    t_enc_repo_id = '826d1b7b-f110-46f2-8d5e-7b5ac3e11f4d'
    t_enc_version = 2
    t_passwd = '123'
    magic_and_random_key = api.generate_magic_and_random_key(
        t_enc_version, t_enc_repo_id, t_passwd)
    t_magic = magic_and_random_key.magic
    t_random_key = magic_and_random_key.random_key
    t_enc_repo_id = api.create_enc_repo(t_enc_repo_id, 'test_encrypted_repo',
                                        '', USER, t_magic, t_random_key,
                                        t_enc_version)
    assert t_enc_repo_id == '826d1b7b-f110-46f2-8d5e-7b5ac3e11f4d'

    #test get_repo_list
    t_start = -1
    t_limit = -1
    t_repo_list = api.get_repo_list(t_start, t_limit)
    assert t_repo_list and len(t_repo_list)

    t_start = 1
    t_limit = 1
    t_repo_list = api.get_repo_list(t_start, t_limit)
    assert t_repo_list and len(t_repo_list) == 1

    #test get_owned_repo_list
    t_repo_list = api.get_owned_repo_list(USER2)
    assert t_repo_list and len(t_repo_list)

    #test get_commit_list
    t_offset = 0
    t_limit = 0
    t_commit_list = api.get_commit_list(t_repo_id, t_offset, t_limit)
    assert t_commit_list and len(t_commit_list) == 4

    t_offset = 1
    t_limit = 1
    t_commit_list = api.get_commit_list(t_repo_id, t_offset, t_limit)
    assert t_commit_list and len(t_commit_list) == 1

    #test remove_repo
    api.remove_repo(t_repo_id)
    t_repo = api.get_repo(t_repo_id)
    assert t_repo == None
Exemplo n.º 5
0
    def get(self, request, format=None):
        # count repos
        try:
            repos_count = seafile_api.count_repos()
        except SearpcError as e:
            logger.error(e)
            repos_count = 0

        # count groups
        try:
            groups_count = len(ccnet_api.get_all_groups(-1, -1))
        except Exception as e:
            logger.error(e)
            groups_count = 0

        # count orgs
        if MULTI_TENANCY:
            multi_tenancy_enabled = True
            try:
                org_count = ccnet_api.count_orgs()
            except Exception as e:
                logger.error(e)
                org_count = 0
        else:
            multi_tenancy_enabled = False
            org_count = 0

        # count users
        try:
            active_db_users = ccnet_api.count_emailusers("DB")
        except Exception as e:
            logger.error(e)
            active_db_users = 0

        try:
            active_ldap_users = ccnet_api.count_emailusers("LDAP")
        except Exception as e:
            logger.error(e)
            active_ldap_users = 0

        try:
            inactive_db_users = ccnet_api.count_inactive_emailusers("DB")
        except Exception as e:
            logger.error(e)
            inactive_db_users = 0

        try:
            inactive_ldap_users = ccnet_api.count_inactive_emailusers("LDAP")
        except Exception as e:
            logger.error(e)
            inactive_ldap_users = 0

        active_users = active_db_users + active_ldap_users if active_ldap_users > 0 else active_db_users

        inactive_users = inactive_db_users + inactive_ldap_users if inactive_ldap_users > 0 else inactive_db_users

        is_pro = is_pro_version()
        if is_pro:
            license_dict = self._get_license_dict()
        else:
            license_dict = {}

        if license_dict:
            with_license = True
            try:
                max_users = int(license_dict.get("MaxUsers", ""))
            except ValueError as e:
                logger.error(e)
                max_users = 0
        else:
            with_license = False
            max_users = 0

        info = {
            "users_count": active_users + inactive_users,
            "active_users_count": active_users,
            "repos_count": repos_count,
            "groups_count": groups_count,
            "org_count": org_count,
            "multi_tenancy_enabled": multi_tenancy_enabled,
            "is_pro": is_pro,
            "with_license": with_license,
            "license_expiration": license_dict.get("Expiration", ""),
            "license_maxusers": max_users,
            "license_to": license_dict.get("Name", ""),
        }

        return Response(info)