Skip to content

Commit

Permalink
fix my activities filters (#7166)
Browse files Browse the repository at this point in the history
* fix my activities filters

* update

---------

Co-authored-by: r350178982 <[email protected]>
  • Loading branch information
Michael18811380328 and r350178982 authored Dec 13, 2024
1 parent 977aa79 commit 3a11ace
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
11 changes: 4 additions & 7 deletions frontend/src/pages/dashboard/files-activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/utils/seafile-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion seahub/api2/endpoints/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ def get(self, request, format=None):
except ValueError:
per_page = 25

op_user = request.GET.get('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, start, count, op_user)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
Expand Down
12 changes: 8 additions & 4 deletions seahub/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,27 +621,31 @@ def _get_seafevents_session():
session.close()


def _get_activities(username, start, count):
def _get_activities(username, start, count, op_user=None):
ev_session = SeafEventsSession()

events = []
try:
events = seafevents_api.get_user_activities(ev_session,
if op_user:
events = seafevents_api.get_user_activities_by_op_user(ev_session,
username, op_user, start, count)
else:
events = seafevents_api.get_user_activities(ev_session,
username, start, count)
finally:
ev_session.close()

return events


def get_user_activities(username, start, count):
def get_user_activities(username, start, count, op_user=None):
"""Return user events list and a new start.
For example:
``get_user_activities('[email protected]', 0, 10)`` returns the first 10
``get_user_activities('[email protected]', 4, 10)`` returns the 6th through
15th events.
"""
return _get_activities(username, start, count)
return _get_activities(username, start, count, op_user)

def get_user_activity_stats_by_day(start, end, offset):
"""
Expand Down

0 comments on commit 3a11ace

Please sign in to comment.