mirror of
https://github.com/haiwen/seahub.git
synced 2025-06-27 07:28:42 +00:00
[department] added an option to control if libraries can be shared in… (#4778)
* [department] added an option to control if libraries can be shared into a department * update seahub web api Co-authored-by: lian <lian@seafile.com>
This commit is contained in:
parent
ae9874c84f
commit
2db2c08032
@ -2,7 +2,7 @@ import React, { Fragment } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Button } from 'reactstrap';
|
import { Button } from 'reactstrap';
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
import { gettext, isPro } from '../../utils/constants';
|
import { gettext, isPro, enableShareToDepartment } from '../../utils/constants';
|
||||||
import { seafileAPI } from '../../utils/seafile-api.js';
|
import { seafileAPI } from '../../utils/seafile-api.js';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
import toaster from '../toast';
|
import toaster from '../toast';
|
||||||
@ -135,6 +135,12 @@ class ShareToGroup extends React.Component {
|
|||||||
seafileAPI.shareableGroups().then((res) => {
|
seafileAPI.shareableGroups().then((res) => {
|
||||||
let options = [];
|
let options = [];
|
||||||
for (let i = 0 ; i < res.data.length; i++) {
|
for (let i = 0 ; i < res.data.length; i++) {
|
||||||
|
const item = res.data[i];
|
||||||
|
if (item.parent_group_id != 0) { // it's a department
|
||||||
|
if (!enableShareToDepartment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj.value = res.data[i].name;
|
obj.value = res.data[i].name;
|
||||||
obj.id = res.data[i].id;
|
obj.id = res.data[i].id;
|
||||||
|
@ -53,6 +53,7 @@ export const shareLinkExpireDaysDefault = window.app.pageOptions.shareLinkExpire
|
|||||||
export const uploadLinkExpireDaysMin = window.app.pageOptions.uploadLinkExpireDaysMin;
|
export const uploadLinkExpireDaysMin = window.app.pageOptions.uploadLinkExpireDaysMin;
|
||||||
export const uploadLinkExpireDaysMax = window.app.pageOptions.uploadLinkExpireDaysMax;
|
export const uploadLinkExpireDaysMax = window.app.pageOptions.uploadLinkExpireDaysMax;
|
||||||
export const uploadLinkExpireDaysDefault = window.app.pageOptions.uploadLinkExpireDaysDefault;
|
export const uploadLinkExpireDaysDefault = window.app.pageOptions.uploadLinkExpireDaysDefault;
|
||||||
|
export const enableShareToDepartment = window.app.pageOptions.enableShareToDepartment;
|
||||||
export const maxFileName = window.app.pageOptions.maxFileName;
|
export const maxFileName = window.app.pageOptions.maxFileName;
|
||||||
export const canPublishRepo = window.app.pageOptions.canPublishRepo;
|
export const canPublishRepo = window.app.pageOptions.canPublishRepo;
|
||||||
export const enableEncryptedLibrary = window.app.pageOptions.enableEncryptedLibrary;
|
export const enableEncryptedLibrary = window.app.pageOptions.enableEncryptedLibrary;
|
||||||
|
@ -24,7 +24,7 @@ from seahub.api2.endpoints.utils import is_org_user
|
|||||||
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
||||||
email2contact_email
|
email2contact_email
|
||||||
from seahub.base.accounts import User
|
from seahub.base.accounts import User
|
||||||
from seahub.group.utils import is_group_member
|
from seahub.group.utils import is_group_member, is_group_admin
|
||||||
from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission
|
from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission
|
||||||
from seahub.share.utils import is_repo_admin, share_dir_to_user, \
|
from seahub.share.utils import is_repo_admin, share_dir_to_user, \
|
||||||
share_dir_to_group, update_user_dir_permission, \
|
share_dir_to_group, update_user_dir_permission, \
|
||||||
@ -37,6 +37,7 @@ from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE, \
|
|||||||
PERMISSION_ADMIN
|
PERMISSION_ADMIN
|
||||||
from seahub.utils.repo import get_available_repo_perms
|
from seahub.utils.repo import get_available_repo_perms
|
||||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||||
|
from seahub.settings import ENABLE_SHARE_TO_DEPARTMENT
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -437,6 +438,17 @@ class DirSharedItemsEndpoint(APIView):
|
|||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# is sharing repo to department
|
||||||
|
if group.parent_group_id != 0:
|
||||||
|
|
||||||
|
if not ENABLE_SHARE_TO_DEPARTMENT or \
|
||||||
|
ENABLE_SHARE_TO_DEPARTMENT and not is_group_admin(gid, username):
|
||||||
|
result['failed'].append({
|
||||||
|
'group_name': group.group_name,
|
||||||
|
'error_msg': 'Permission denied.'
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
|
||||||
if self.has_shared_to_group(request, repo_id, path, gid):
|
if self.has_shared_to_group(request, repo_id, path, gid):
|
||||||
result['failed'].append({
|
result['failed'].append({
|
||||||
'group_name': group.group_name,
|
'group_name': group.group_name,
|
||||||
|
@ -13,26 +13,27 @@ from seahub.utils import is_org_context
|
|||||||
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
from seahub.avatar.settings import GROUP_AVATAR_DEFAULT_SIZE
|
|
||||||
|
from seahub.settings import ENABLE_SHARE_TO_DEPARTMENT
|
||||||
|
|
||||||
from constance import config
|
from constance import config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
seafile_conf_dir = os.path.join(current_path, \
|
seafile_conf_dir = os.path.join(current_path, '../../../../../conf')
|
||||||
'../../../../../conf')
|
|
||||||
sys.path.append(seafile_conf_dir)
|
sys.path.append(seafile_conf_dir)
|
||||||
from seahub_custom_functions import custom_get_groups
|
from seahub_custom_functions import custom_get_groups
|
||||||
CUSTOM_GET_GROUPS = True
|
CUSTOM_GET_GROUPS = True
|
||||||
except ImportError as e:
|
except ImportError:
|
||||||
CUSTOM_GET_GROUPS = False
|
CUSTOM_GET_GROUPS = False
|
||||||
|
|
||||||
|
|
||||||
class ShareableGroups(APIView):
|
class ShareableGroups(APIView):
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
throttle_classes = (UserRateThrottle, )
|
throttle_classes = (UserRateThrottle, )
|
||||||
|
|
||||||
def _get_group_info(self, request, group, avatar_size):
|
def _get_group_info(self, request, group):
|
||||||
isoformat_timestr = timestamp_to_isoformat_timestr(group.timestamp)
|
isoformat_timestr = timestamp_to_isoformat_timestr(group.timestamp)
|
||||||
group_info = {
|
group_info = {
|
||||||
"id": group.id,
|
"id": group.id,
|
||||||
@ -60,12 +61,13 @@ class ShareableGroups(APIView):
|
|||||||
else:
|
else:
|
||||||
groups = ccnet_api.get_groups(username)
|
groups = ccnet_api.get_groups(username)
|
||||||
|
|
||||||
try:
|
filtered_groups = []
|
||||||
avatar_size = int(request.GET.get('avatar_size',
|
for group in groups:
|
||||||
GROUP_AVATAR_DEFAULT_SIZE))
|
if not ENABLE_SHARE_TO_DEPARTMENT and group.parent_group_id != 0:
|
||||||
except ValueError:
|
continue
|
||||||
avatar_size = GROUP_AVATAR_DEFAULT_SIZE
|
else:
|
||||||
|
filtered_groups.append(group)
|
||||||
|
|
||||||
result = [self._get_group_info(request, group, avatar_size) for group in groups]
|
result = [self._get_group_info(request, group) for group in filtered_groups]
|
||||||
|
|
||||||
return Response(result)
|
return Response(result)
|
||||||
|
@ -413,6 +413,9 @@ ENABLE_TERMS_AND_CONDITIONS = False
|
|||||||
# Enable or disable sharing to all groups
|
# Enable or disable sharing to all groups
|
||||||
ENABLE_SHARE_TO_ALL_GROUPS = False
|
ENABLE_SHARE_TO_ALL_GROUPS = False
|
||||||
|
|
||||||
|
# Enable or disable sharing to departments
|
||||||
|
ENABLE_SHARE_TO_DEPARTMENT = False
|
||||||
|
|
||||||
# interval for request unread notifications
|
# interval for request unread notifications
|
||||||
UNREAD_NOTIFICATIONS_REQUEST_INTERVAL = 3 * 60 # seconds
|
UNREAD_NOTIFICATIONS_REQUEST_INTERVAL = 3 * 60 # seconds
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
libraryTemplates: (function () {
|
libraryTemplates: (function () {
|
||||||
var libraryTemplates = [];
|
var libraryTemplates = [];
|
||||||
{% for template in library_templates %}
|
{% for template in library_templates %}
|
||||||
libraryTemplates.push("{{template}}");
|
libraryTemplates.push("{{template}}");
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
return libraryTemplates;
|
return libraryTemplates;
|
||||||
})(),
|
})(),
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Object.assign(app.pageOptions, {
|
Object.assign(app.pageOptions, {
|
||||||
|
enableShareToDepartment: {% if enable_share_to_department %} true {% else %} false {% endif %},
|
||||||
shareLinkExpireDaysDefault: {{ share_link_expire_days_default }},
|
shareLinkExpireDaysDefault: {{ share_link_expire_days_default }},
|
||||||
shareLinkExpireDaysMin: {{ share_link_expire_days_min }},
|
shareLinkExpireDaysMin: {{ share_link_expire_days_min }},
|
||||||
shareLinkExpireDaysMax: {{ share_link_expire_days_max }},
|
shareLinkExpireDaysMax: {{ share_link_expire_days_max }},
|
||||||
|
@ -1211,4 +1211,5 @@ def react_fake_view(request, **kwargs):
|
|||||||
'additional_about_dialog_links': ADDITIONAL_ABOUT_DIALOG_LINKS,
|
'additional_about_dialog_links': ADDITIONAL_ABOUT_DIALOG_LINKS,
|
||||||
'enable_ocm': ENABLE_OCM,
|
'enable_ocm': ENABLE_OCM,
|
||||||
'ocm_remote_servers': OCM_REMOTE_SERVERS,
|
'ocm_remote_servers': OCM_REMOTE_SERVERS,
|
||||||
|
'enable_share_to_department': settings.ENABLE_SHARE_TO_DEPARTMENT,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user