mirror of
https://github.com/haiwen/seahub.git
synced 2025-06-25 14:43:15 +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 { Button } from 'reactstrap';
|
||||
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 { Utils } from '../../utils/utils';
|
||||
import toaster from '../toast';
|
||||
@ -135,6 +135,12 @@ class ShareToGroup extends React.Component {
|
||||
seafileAPI.shareableGroups().then((res) => {
|
||||
let options = [];
|
||||
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 = {};
|
||||
obj.value = res.data[i].name;
|
||||
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 uploadLinkExpireDaysMax = window.app.pageOptions.uploadLinkExpireDaysMax;
|
||||
export const uploadLinkExpireDaysDefault = window.app.pageOptions.uploadLinkExpireDaysDefault;
|
||||
export const enableShareToDepartment = window.app.pageOptions.enableShareToDepartment;
|
||||
export const maxFileName = window.app.pageOptions.maxFileName;
|
||||
export const canPublishRepo = window.app.pageOptions.canPublishRepo;
|
||||
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, \
|
||||
email2contact_email
|
||||
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.utils import is_repo_admin, share_dir_to_user, \
|
||||
share_dir_to_group, update_user_dir_permission, \
|
||||
@ -37,6 +37,7 @@ from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE, \
|
||||
PERMISSION_ADMIN
|
||||
from seahub.utils.repo import get_available_repo_perms
|
||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||
from seahub.settings import ENABLE_SHARE_TO_DEPARTMENT
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -437,6 +438,17 @@ class DirSharedItemsEndpoint(APIView):
|
||||
})
|
||||
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):
|
||||
result['failed'].append({
|
||||
'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.api2.authentication import TokenAuthentication
|
||||
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
|
||||
|
||||
try:
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
seafile_conf_dir = os.path.join(current_path, \
|
||||
'../../../../../conf')
|
||||
seafile_conf_dir = os.path.join(current_path, '../../../../../conf')
|
||||
sys.path.append(seafile_conf_dir)
|
||||
from seahub_custom_functions import custom_get_groups
|
||||
CUSTOM_GET_GROUPS = True
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
CUSTOM_GET_GROUPS = False
|
||||
|
||||
|
||||
class ShareableGroups(APIView):
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
permission_classes = (IsAuthenticated,)
|
||||
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)
|
||||
group_info = {
|
||||
"id": group.id,
|
||||
@ -60,12 +61,13 @@ class ShareableGroups(APIView):
|
||||
else:
|
||||
groups = ccnet_api.get_groups(username)
|
||||
|
||||
try:
|
||||
avatar_size = int(request.GET.get('avatar_size',
|
||||
GROUP_AVATAR_DEFAULT_SIZE))
|
||||
except ValueError:
|
||||
avatar_size = GROUP_AVATAR_DEFAULT_SIZE
|
||||
filtered_groups = []
|
||||
for group in groups:
|
||||
if not ENABLE_SHARE_TO_DEPARTMENT and group.parent_group_id != 0:
|
||||
continue
|
||||
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)
|
||||
|
@ -413,6 +413,9 @@ ENABLE_TERMS_AND_CONDITIONS = False
|
||||
# Enable or disable sharing to all groups
|
||||
ENABLE_SHARE_TO_ALL_GROUPS = False
|
||||
|
||||
# Enable or disable sharing to departments
|
||||
ENABLE_SHARE_TO_DEPARTMENT = False
|
||||
|
||||
# interval for request unread notifications
|
||||
UNREAD_NOTIFICATIONS_REQUEST_INTERVAL = 3 * 60 # seconds
|
||||
|
||||
|
@ -86,7 +86,7 @@
|
||||
libraryTemplates: (function () {
|
||||
var libraryTemplates = [];
|
||||
{% for template in library_templates %}
|
||||
libraryTemplates.push("{{template}}");
|
||||
libraryTemplates.push("{{template}}");
|
||||
{% endfor %}
|
||||
return libraryTemplates;
|
||||
})(),
|
||||
|
@ -8,6 +8,7 @@
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
Object.assign(app.pageOptions, {
|
||||
enableShareToDepartment: {% if enable_share_to_department %} true {% else %} false {% endif %},
|
||||
shareLinkExpireDaysDefault: {{ share_link_expire_days_default }},
|
||||
shareLinkExpireDaysMin: {{ share_link_expire_days_min }},
|
||||
shareLinkExpireDaysMax: {{ share_link_expire_days_max }},
|
||||
|
@ -1211,4 +1211,5 @@ def react_fake_view(request, **kwargs):
|
||||
'additional_about_dialog_links': ADDITIONAL_ABOUT_DIALOG_LINKS,
|
||||
'enable_ocm': ENABLE_OCM,
|
||||
'ocm_remote_servers': OCM_REMOTE_SERVERS,
|
||||
'enable_share_to_department': settings.ENABLE_SHARE_TO_DEPARTMENT,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user