def test_can_enable_personal_wiki_module(self):
        enabled_mods = get_enabled_mods_by_user(self.username)
        assert 'personal wiki' not in enabled_mods

        self.login_as(self.user)
        resp = self.client.post(self.url, {})
        self.assertEqual(200, resp.status_code)

        enabled_mods = get_enabled_mods_by_user(self.username)
        assert 'personal wiki' in enabled_mods
    def test_can_disable_personal_wiki_module(self):
        enable_mod_for_user(self.username, MOD_PERSONAL_WIKI)
        enabled_mods = get_enabled_mods_by_user(self.username)
        assert 'personal wiki' in enabled_mods

        self.login_as(self.user)
        resp = self.client.delete(self.url, {},
                                  'application/x-www-form-urlencoded')
        self.assertEqual(200, resp.status_code)

        enabled_mods = get_enabled_mods_by_user(self.username)
        assert 'personal wiki' not in enabled_mods
예제 #3
0
파일: wiki.py 프로젝트: qbi/seahub
def personal_wiki(request, page_name="home"):
    username = request.user.username
    wiki_exists = True
    try:
        content, repo, dirent = get_personal_wiki_page(username, page_name)
    except WikiDoesNotExist:
        wiki_exists = False
        # get available modules(wiki, etc)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)
        return render_to_response("wiki/personal_wiki.html", {
            "wiki_exists": wiki_exists,
            "mods_enabled": mods_enabled,
            "mods_available": mods_available,
        },
                                  context_instance=RequestContext(request))
    except WikiPageMissing:
        repo = get_personal_wiki_repo(username)
        filename = clean_page_name(page_name) + '.md'
        if not seaserv.post_empty_file(repo.id, "/", filename, username):
            return render_error(
                request, _("Failed to create wiki page. Please retry later."))
        return HttpResponseRedirect(reverse('personal_wiki', args=[page_name]))
    else:
        url_prefix = reverse('personal_wiki', args=[])
        content = convert_wiki_link(content, url_prefix, repo.id, username)

        # fetch file latest contributor and last modified
        path = '/' + dirent.obj_name
        file_path_hash = hashlib.md5(urllib2.quote(
            path.encode('utf-8'))).hexdigest()[:12]
        contributors, last_modified, last_commit_id = get_file_contributors(\
            repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id)
        latest_contributor = contributors[0] if contributors else None

        # get available modules(wiki, etc)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)

        return render_to_response("wiki/personal_wiki.html", {
            "wiki_exists": wiki_exists,
            "content": content,
            "page": os.path.splitext(dirent.obj_name)[0],
            "last_modified": last_modified,
            "latest_contributor": latest_contributor,
            "path": path,
            "repo_id": repo.id,
            "search_repo_id": repo.id,
            "search_wiki": True,
            "mods_enabled": mods_enabled,
            "mods_available": mods_available,
        },
                                  context_instance=RequestContext(request))
예제 #4
0
파일: wiki.py 프로젝트: mhltlyc/seahub
def personal_wiki(request, page_name="home"):
    username = request.user.username
    wiki_exists = True
    try:
        content, repo, dirent = get_personal_wiki_page(username, page_name)
    except WikiDoesNotExist:
        wiki_exists = False
        # get available modules(wiki, etc)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)
        return render_to_response("wiki/personal_wiki.html", {
                "wiki_exists": wiki_exists,
                "mods_enabled": mods_enabled,
                "mods_available": mods_available,
                }, context_instance=RequestContext(request))
    except WikiPageMissing:
        repo = get_personal_wiki_repo(username)
        filename = clean_page_name(page_name) + '.md'
        if not seaserv.post_empty_file(repo.id, "/", filename, username):
            return render_error(request, _("Failed to create wiki page. Please retry later."))
        return HttpResponseRedirect(reverse('personal_wiki', args=[page_name]))
    else:
        url_prefix = reverse('personal_wiki', args=[])
        content = convert_wiki_link(content, url_prefix, repo.id, username)
        
        # fetch file latest contributor and last modified
        path = '/' + dirent.obj_name
        file_path_hash = hashlib.md5(urllib2.quote(path.encode('utf-8'))).hexdigest()[:12]            
        contributors, last_modified, last_commit_id = \
            FileContributors.objects.get_file_contributors(
            repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id)
        latest_contributor = contributors[0] if contributors else None

        # get available modules(wiki, etc)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)
        
        return render_to_response("wiki/personal_wiki.html", {
                "wiki_exists": wiki_exists,
                "content": content,
                "page": os.path.splitext(dirent.obj_name)[0],
                "last_modified": last_modified,
                "latest_contributor": latest_contributor,
                "path": path,
                "repo_id": repo.id,
                "search_repo_id": repo.id,
                "search_wiki": True,
                "mods_enabled": mods_enabled,
                "mods_available": mods_available,
                }, context_instance=RequestContext(request))
예제 #5
0
def base(request):
    """
    Add seahub base configure to the context.
    
    """
    try:
        org = request.user.org
    except AttributeError:
        org = None
    try:
        base_template = request.base_template
    except AttributeError:
        base_template = 'myhome_base.html'

    username = request.user.username

    # get available modules(wiki, etc)
    mods_available = get_available_mods_by_user(username)
    mods_enabled = get_enabled_mods_by_user(username)

    # get 8 user groups
    try:
        grps = request.user.joined_groups[:8]
    except AttributeError:  # anonymous user
        grps = None

    return {
        'seafile_version': SEAFILE_VERSION,
        'site_title': SITE_TITLE,
        'branding_css': BRANDING_CSS,
        'logo_path': LOGO_PATH,
        'logo_width': LOGO_WIDTH,
        'logo_height': LOGO_HEIGHT,
        'seacloud_mode': SEACLOUD_MODE,
        'cloud_mode': request.cloud_mode,
        'org': org,
        'base_template': base_template,
        'site_name': SITE_NAME,
        'enable_signup': ENABLE_SIGNUP,
        'max_file_name': MAX_FILE_NAME,
        'has_file_search': HAS_FILE_SEARCH,
        'enable_pubfile': ENABLE_PUBFILE,
        'show_repo_download_button': SHOW_REPO_DOWNLOAD_BUTTON,
        'repo_password_min_length': REPO_PASSWORD_MIN_LENGTH,
        'events_enabled': EVENTS_ENABLED,
        'traffic_stats_enabled': TRAFFIC_STATS_ENABLED,
        'mods_available': mods_available,
        'mods_enabled': mods_enabled,
        'grps': grps,
    }
예제 #6
0
def base(request):
    """
    Add seahub base configure to the context.
    
    """
    try:
        org = request.user.org
    except AttributeError:
        org = None
    try:
        base_template = request.base_template
    except AttributeError:
        base_template = 'myhome_base.html'

    username = request.user.username

    # get available modules(wiki, etc)
    mods_available = get_available_mods_by_user(username)
    mods_enabled = get_enabled_mods_by_user(username)

    return {
        'seafile_version': SEAFILE_VERSION,
        'site_title': SITE_TITLE,
        'branding_css': BRANDING_CSS,
        'logo_path': LOGO_PATH,
        'logo_width': LOGO_WIDTH,
        'logo_height': LOGO_HEIGHT,
        'seacloud_mode': SEACLOUD_MODE,
        'cloud_mode': request.cloud_mode,
        'org': org,
        'base_template': base_template,
        'site_name': SITE_NAME,
        'enable_signup': ENABLE_SIGNUP,
        'max_file_name': MAX_FILE_NAME,
        'has_file_search': HAS_FILE_SEARCH,
        'enable_pubfile': ENABLE_PUBFILE,
        'show_repo_download_button': SHOW_REPO_DOWNLOAD_BUTTON,
        'repo_password_min_length': REPO_PASSWORD_MIN_LENGTH,
        'events_enabled': EVENTS_ENABLED,
        'mods_available': mods_available,
        'mods_enabled': mods_enabled,
        'multi_tenancy': MULTI_TENANCY,
        }
예제 #7
0
def personal_wiki_pages(request):
    """
    List personal wiki pages.
    """
    try:
        username = request.user.username
        repo = get_personal_wiki_repo(username)
        pages = get_wiki_pages(repo)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)
    except SearpcError:
        return render_error(request, _('Internal Server Error'))
    except WikiDoesNotExist:
        return render_error(request, _('Wiki does not exists.'))

    return render_to_response("wiki/personal_wiki_pages.html", {
            "pages": pages,
            "repo_id": repo.id,
            "search_repo_id": repo.id,
            "search_wiki": True,
            "mods_enabled": mods_enabled,
            "mods_available": mods_available,
            }, context_instance=RequestContext(request))
예제 #8
0
파일: wiki.py 프로젝트: qbi/seahub
def personal_wiki_pages(request):
    """
    List personal wiki pages.
    """
    try:
        username = request.user.username
        repo = get_personal_wiki_repo(username)
        pages = get_wiki_pages(repo)
        mods_available = get_available_mods_by_user(username)
        mods_enabled = get_enabled_mods_by_user(username)
    except SearpcError:
        return render_error(request, _('Internal Server Error'))
    except WikiDoesNotExist:
        return render_error(request, _('Wiki does not exists.'))

    return render_to_response("wiki/personal_wiki_pages.html", {
        "pages": pages,
        "repo_id": repo.id,
        "search_repo_id": repo.id,
        "search_wiki": True,
        "mods_enabled": mods_enabled,
        "mods_available": mods_available,
    },
                              context_instance=RequestContext(request))
예제 #9
0
파일: decorators.py 프로젝트: rominf/seahub
 def _decorated(request, *args, **kwargs):
     username = request.user.username
     request.user.mods_available = get_available_mods_by_user(username)
     request.user.mods_enabled = get_enabled_mods_by_user(username)
     return func(request, *args, **kwargs)
예제 #10
0
 def _decorated(request, *args, **kwargs):
     username = request.user.username
     request.user.mods_available = get_available_mods_by_user(username)
     request.user.mods_enabled = get_enabled_mods_by_user(username)
     return func(request, *args, **kwargs)