diff --git a/frontend/src/pages/dashboard/files-activities.js b/frontend/src/pages/dashboard/files-activities.js index d0ff265ccb1..192a0aad4cb 100644 --- a/frontend/src/pages/dashboard/files-activities.js +++ b/frontend/src/pages/dashboard/files-activities.js @@ -40,7 +40,7 @@ class FilesActivities extends Component { componentDidMount() { let { currentPage, availableUsers } = this.state; - seafileAPI.listActivities(currentPage).then(res => { + seafileAPI.listActivities(currentPage, this.props.onlyMine ? username : '').then(res => { // {"events":[...]} let events = this.mergePublishEvents(res.data.events); events = this.mergeFileCreateEvents(events); @@ -139,7 +139,7 @@ class FilesActivities extends Component { getMore() { const { currentPage, availableUsers, targetUsers } = this.state; - seafileAPI.listActivities(currentPage).then(res => { + seafileAPI.listActivities(currentPage, this.props.onlyMine ? username : '').then(res => { // {"events":[...]} let events = this.mergePublishEvents(res.data.events); events = this.mergeFileCreateEvents(events); @@ -184,13 +184,10 @@ class FilesActivities extends Component { const { onlyMine } = this.props; const { targetUsers } = this.state; - if (onlyMine) { - return events.filter(item => item.author_email == username); - } else if (targetUsers.length) { + if (!onlyMine && targetUsers.length) { return events.filter(item => targetUsers.map(item => item.email).indexOf(item.author_email) != -1); - } else { - return events; } + return events; }; setTargetUsers = (selectedUsers) => { diff --git a/frontend/src/utils/seafile-api.js b/frontend/src/utils/seafile-api.js index 50c1867fe4a..ab80c4a1a85 100644 --- a/frontend/src/utils/seafile-api.js +++ b/frontend/src/utils/seafile-api.js @@ -1493,8 +1493,11 @@ class SeafileAPI { } // ---- Activities API - listActivities(pageNum) { - const url = this.server + '/api/v2.1/activities/?page=' + pageNum; + listActivities(pageNum, operationUser) { + let url = this.server + '/api/v2.1/activities/?page=' + pageNum; + if (operationUser) { + url += '&op_user=' + encodeURIComponent(operationUser); + } return this.req.get(url); } diff --git a/seahub/api2/endpoints/activities.py b/seahub/api2/endpoints/activities.py index 8582e3a0e8c..7500ecc007b 100644 --- a/seahub/api2/endpoints/activities.py +++ b/seahub/api2/endpoints/activities.py @@ -40,13 +40,18 @@ def get(self, request, format=None): except ValueError: per_page = 25 + try: + op_user = request.GET.get('op_user', '') + except ValueError: + op_user = '' + start = (page - 1) * per_page count = per_page email = request.user.username try: - events = get_user_activities(email, start, count) + events = get_user_activities(email, op_user, start, count) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 8df51ef19ef..17cb8bd9363 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -621,27 +621,27 @@ def _get_seafevents_session(): session.close() - def _get_activities(username, start, count): + def _get_activities(username, op_user, start, count): ev_session = SeafEventsSession() events = [] try: events = seafevents_api.get_user_activities(ev_session, - username, start, count) + username, op_user, start, count) finally: ev_session.close() return events - def get_user_activities(username, start, count): + def get_user_activities(username, op_user, start, count): """Return user events list and a new start. For example: ``get_user_activities('foo@example.com', 0, 10)`` returns the first 10 ``get_user_activities('foo@example.com', 4, 10)`` returns the 6th through 15th events. """ - return _get_activities(username, start, count) + return _get_activities(username, op_user, start, count) def get_user_activity_stats_by_day(start, end, offset): """