mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
Tag document view activity with source/referrer
This commit is contained in:
parent
663ec23c75
commit
c9e429ea1a
3 changed files with 35 additions and 4 deletions
|
@ -1236,6 +1236,9 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Who referred user this document (e.g. search page).
|
||||
source := request.Query(r, "source")
|
||||
|
||||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -1393,6 +1396,28 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// If we have source, record document access via source.
|
||||
if len(source) > 0 {
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
} else {
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
DocumentID: doc.RefID,
|
||||
Metadata: source, // deliberate
|
||||
SourceType: activity.SourceTypeSearch, // deliberate
|
||||
ActivityType: activity.TypeRead})
|
||||
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
h.Runtime.Log.Error(method, err)
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
}
|
||||
}
|
||||
|
||||
// deliver payload
|
||||
response.WriteJSON(w, model)
|
||||
}
|
||||
|
|
|
@ -20,9 +20,13 @@ export default Route.extend(AuthenticatedRouteMixin, {
|
|||
folderService: service('folder'),
|
||||
userService: service('user'),
|
||||
|
||||
beforeModel() {
|
||||
beforeModel(transition) {
|
||||
// Note the source that sent user to this document.
|
||||
let source = transition.queryParams.source;
|
||||
if (is.null(source) || is.undefined(source)) source = "";
|
||||
|
||||
return new EmberPromise((resolve) => {
|
||||
this.get('documentService').fetchPages(this.paramsFor('document').document_id, this.get('session.user.id')).then((data) => {
|
||||
this.get('documentService').fetchPages(this.paramsFor('document').document_id, this.get('session.user.id'), source).then((data) => {
|
||||
this.set('pages', data);
|
||||
resolve();
|
||||
});
|
||||
|
|
|
@ -375,7 +375,9 @@ export default Service.extend({
|
|||
// This method bulk fetches data to reduce network chatter.
|
||||
// We produce a bunch of calculated boolean's for UI display purposes
|
||||
// that can tell us quickly about pending changes for UI display.
|
||||
fetchPages(documentId, currentUserId) {
|
||||
|
||||
// Source - optional identifier of (document) referrer.
|
||||
fetchPages(documentId, currentUserId, source) {
|
||||
let constants = this.get('constants');
|
||||
let changePending = false;
|
||||
let changeAwaitingReview = false;
|
||||
|
@ -384,7 +386,7 @@ export default Service.extend({
|
|||
let userHasChangeAwaitingReview = false;
|
||||
let userHasChangeRejected = false;
|
||||
|
||||
return this.get('ajax').request(`fetch/page/${documentId}`, {
|
||||
return this.get('ajax').request(`fetch/page/${documentId}?source=${source}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = A([]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue