mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-14 23:46:49 +00:00
add library pattern feature
This commit is contained in:
parent
72cefff03f
commit
94e91265cc
@ -619,11 +619,13 @@ class Repos(APIView):
|
||||
return api_error(HTTP_520_OPERATION_FAILED,
|
||||
'Failed to create library.')
|
||||
else:
|
||||
library_template = request.data.get("library_template", None)
|
||||
repo_created.send(sender=None,
|
||||
org_id=org_id,
|
||||
creator=username,
|
||||
repo_id=repo_id,
|
||||
repo_name=repo_name)
|
||||
repo_name=repo_name,
|
||||
library_template=library_template)
|
||||
resp = repo_download_info(request, repo_id,
|
||||
gen_sync_token=gen_sync_token)
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||
|
||||
import logging
|
||||
import settings
|
||||
from seaserv import seafile_api
|
||||
from seahub.utils import is_pro_version
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if not hasattr(settings, 'EVENTS_CONFIG_FILE'):
|
||||
def repo_created_cb(sender, **kwargs):
|
||||
@ -7,7 +12,7 @@ if not hasattr(settings, 'EVENTS_CONFIG_FILE'):
|
||||
|
||||
def repo_deleted_cb(sender, **kwargs):
|
||||
pass
|
||||
else:
|
||||
else:
|
||||
|
||||
import seafevents
|
||||
from utils import SeafEventsSession
|
||||
@ -34,6 +39,22 @@ else:
|
||||
seafevents.save_user_events (session, etype, detail, users, None)
|
||||
session.close()
|
||||
|
||||
if is_pro_version():
|
||||
LIBRARY_TEMPLATES = getattr(settings, 'LIBRARY_TEMPLATES', {})
|
||||
library_template = kwargs['library_template']
|
||||
|
||||
dir_path_list = []
|
||||
if isinstance(LIBRARY_TEMPLATES, dict) and \
|
||||
LIBRARY_TEMPLATES.has_key(library_template):
|
||||
dir_path_list = LIBRARY_TEMPLATES[library_template]
|
||||
|
||||
try:
|
||||
for dir_path in dir_path_list:
|
||||
seafile_api.mkdir_with_parents(repo_id, '/',
|
||||
dir_path.strip('/'), creator)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
def repo_deleted_cb(sender, **kwargs):
|
||||
"""When a repo is deleted, an event would be added to every user in all
|
||||
groups to which this repo is shared.
|
||||
|
@ -2,7 +2,7 @@
|
||||
import django.dispatch
|
||||
|
||||
# Use org_id = -1 if it's not an org repo
|
||||
repo_created = django.dispatch.Signal(providing_args=["org_id", "creator", "repo_id", "repo_name"])
|
||||
repo_created = django.dispatch.Signal(providing_args=["org_id", "creator", "repo_id", "repo_name", "library_template"])
|
||||
repo_deleted = django.dispatch.Signal(providing_args=["org_id", "usernames", "repo_owner", "repo_id", "repo_name"])
|
||||
upload_file_successful = django.dispatch.Signal(providing_args=["repo_id", "file_path", "owner"])
|
||||
comment_file_successful = django.dispatch.Signal(providing_args=["repo", "file_path", "comment", "author", "notify_users"])
|
||||
|
@ -4,6 +4,15 @@
|
||||
<h3 id="dialogTitle">{% trans "New Library"%}</h3>
|
||||
<label for="repo-name">{% trans "Name"%}</label><br/>
|
||||
<input id="repo-name" type="text" name="repo_name" value="" maxlength="{{max_file_name}}" class="input" /><br />
|
||||
<% if (library_templates.length > 0) { %>
|
||||
<label for="library_template">{% trans "Template"%}</label><br/>
|
||||
<select name="library_template" class="library-template w100">
|
||||
<option value="">{% trans "Select a template" %}</option>
|
||||
<% for (var i = 0, len = library_templates.length; i < len; i++) { %>
|
||||
<option value="<%- library_templates[i] %>"><%- library_templates[i] %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
<% } %>
|
||||
<% if (showSharePerm) { %>
|
||||
<label for="share-permission">{% trans "Share Permission" %}</label><br />
|
||||
<select id="share-permission" name="permission" class="perm">
|
||||
|
@ -222,6 +222,13 @@ app["pageOptions"] = {
|
||||
{% endfor %}
|
||||
return groups;
|
||||
})(),
|
||||
library_templates: (function () {
|
||||
var templates = [];
|
||||
{% for template in library_templates %}
|
||||
templates.push('{{ template }}');
|
||||
{% endfor %}
|
||||
return templates;
|
||||
})(),
|
||||
user_mods_available: (function () {
|
||||
var mods_available = [];
|
||||
{% for mod in request.user.mods_available %}
|
||||
|
@ -52,6 +52,8 @@ import seahub.settings as settings
|
||||
from seahub.settings import AVATAR_FILE_STORAGE, \
|
||||
ENABLE_SUB_LIBRARY, ENABLE_FOLDER_PERM
|
||||
|
||||
LIBRARY_TEMPLATES = getattr(settings, 'LIBRARY_TEMPLATES', {})
|
||||
|
||||
from constance import config
|
||||
|
||||
# Get an instance of a logger
|
||||
@ -821,6 +823,8 @@ def libraries(request):
|
||||
'file_audit_enabled': FILE_AUDIT_ENABLED,
|
||||
'can_add_pub_repo': can_add_pub_repo,
|
||||
'joined_groups': joined_groups,
|
||||
'library_templates': LIBRARY_TEMPLATES.keys() if \
|
||||
isinstance(LIBRARY_TEMPLATES, dict) else []
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
|
@ -31,7 +31,8 @@ define([
|
||||
templateData: function() {
|
||||
return {
|
||||
showSharePerm: false,
|
||||
enable_encrypted_library: app.pageOptions.enable_encrypted_library
|
||||
enable_encrypted_library: app.pageOptions.enable_encrypted_library,
|
||||
library_templates: app.pageOptions.library_templates
|
||||
};
|
||||
},
|
||||
|
||||
@ -47,7 +48,8 @@ define([
|
||||
encrypted: $('#encrypt-switch').prop('checked'),
|
||||
passwd1: $('input[name=passwd]', this.$el).val(),
|
||||
passwd2: $('input[name=passwd_again]', this.$el).val(),
|
||||
passwd: $('input[name=passwd]', this.$el).val()
|
||||
passwd: $('input[name=passwd]', this.$el).val(),
|
||||
library_template: $('[name="library_template"]', this.$el).val()
|
||||
};
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user