Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
d5107702
Commit
d5107702
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
begin processing dashboard events for activity feed.
parent
63929d6a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/dash.clj
+4
-2
4 additions, 2 deletions
src/metabase/api/dash.clj
src/metabase/models/activity.clj
+37
-19
37 additions, 19 deletions
src/metabase/models/activity.clj
with
41 additions
and
21 deletions
src/metabase/api/dash.clj
+
4
−
2
View file @
d5107702
...
...
@@ -61,8 +61,10 @@
"Delete a `Dashboard`."
[
id
]
(
write-check
Dashboard
id
)
(
let
[
result
(
cascade-delete
Dashboard
:id
id
)]
(
events/publish-event
:dashboard-delete
{
:id
id
:actor_id
*current-user-id*
})
;; TODO - it would be much more natural if `cascade-delete` returned the deleted entity instead of an api response
(
let
[
dashboard
(
sel
:one
Dashboard
:id
id
)
result
(
cascade-delete
Dashboard
:id
id
)]
(
events/publish-event
:dashboard-delete
(
assoc
dashboard
:actor_id
*current-user-id*
))
result
))
(
defendpoint
POST
"/:id/cards"
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/activity.clj
+
37
−
19
View file @
d5107702
...
...
@@ -46,11 +46,9 @@
:card-update
:card-delete
:dashboard-create
:dashboard-update
:dashboard-delete
:dashboard-add-cards
:dashboard-remove-cards
:dashboard-reposition-cards
:database-sync-begin
:database-sync-end
:install
...
...
@@ -82,6 +80,10 @@
(
log/error
"Unexpected error listening on activity-feed-channel"
e
)))
(
recur
)))
;;; ## ---------------------------------------- EVENT PROCESSING ----------------------------------------
(
defn-
topic->model
"Determine a valid `model` identifier for the given `topic`."
[
topic
]
...
...
@@ -97,29 +99,45 @@
(
let
[
model
(
topic->model
topic
)]
(
get
object
(
keyword
(
format
"%s_id"
model
))))))
(
defn-
object->user-id
"Determine the appropriate `user_id` (if possible) for a given `object`."
[
object
]
(
or
(
:actor_id
object
)
(
:user_id
object
)
(
:creator_id
object
)))
(
defn-
record-activity
"Simple base function for recording activity using defaults.
Allows caller to specify a custom serialization function to apply to `object` to generate the activity `:details`."
[
topic
object
object-serialize-fn
]
(
ins
Activity
:topic
topic
:model
(
topic->model
topic
)
:model_id
(
object->model-id
topic
object
)
:custom_id
(
:custom_id
object
)
:user_id
(
object->user-id
object
)
:details
(
if
(
fn?
object-serialize-fn
)
(
object-serialize-fn
object
)
object
)))
(
defn-
process-card-activity
""
[])
(
defn-
process-dashboard-activity
""
[])
(
defn-
process-dashboard-activity
[
topic
object
]
(
let
[
create-delete-details
#
(
select-keys
%
[
:description
:name
:public_perms
])]
(
case
topic
:dashboard-create
(
record-activity
topic
object
create-delete-details
)
:dashboard-delete
(
record-activity
topic
object
create-delete-details
))))
(
defn-
process-database-activity
[
topic
object
]
(
case
topic
:database-sync-begin
(
ins
Activity
:topic
:database-sync
:model
(
topic->model
topic
)
:model_id
(
object->model-id
topic
object
)
:custom_id
(
:custom_id
object
)
:details
(
->
object
(
assoc
:status
"started"
)
(
dissoc
:database_id
:custom_id
)))
:database-sync-end
(
let
[{
activity-id
:id
}
(
sel
:one
Activity
:custom_id
(
:custom_id
object
))]
(
upd
Activity
activity-id
:details
(
->
object
(
assoc
:status
"completed"
)
(
dissoc
:database_id
:custom_id
))))))
:database-sync-begin
(
record-activity
topic
object
(
fn
[
obj
]
(
->
obj
(
assoc
:status
"started"
)
(
dissoc
:database_id
:custom_id
))))
:database-sync-end
(
let
[{
activity-id
:id
}
(
sel
:one
Activity
:custom_id
(
:custom_id
object
))]
(
upd
Activity
activity-id
:details
(
->
object
(
assoc
:status
"completed"
)
(
dissoc
:database_id
:custom_id
))))))
(
defn-
process-user-activity
[
topic
object
]
;; we only care about login activity when its the users first session (a.k.a. new user!)
...
...
@@ -141,7 +159,7 @@
;; TODO - we need a protocol on our Entities for providing relevant details
(
case
(
topic->model
topic
)
"card"
(
process-card-activity
)
"dashboard"
(
process-dashboard-activity
)
"dashboard"
(
process-dashboard-activity
topic
object
)
"database"
(
process-database-activity
topic
object
)
"install"
(
when-not
(
sel
:one
:fields
[
Activity
:id
])
(
ins
Activity
:topic
:install
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment