Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[GDGT-2870] fix non-admins unable to create alerts on OSS jars with a paid token installed (#82555)

YBb8264901052e
diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.clj
index 8f478c6637d..e48dfe168a5 100644
--- a/src/metabase/notification/models.clj
+++ b/src/metabase/notification/models.clj
@@ -612,8 +612,10 @@
[_ notification]
(or (mi/superuser?)
(and (current-user-can-read-payload? notification)
- ;; if advanced-permissions is enabled, we require users to have subscription permissions
- (or (not (premium-features/has-feature? :advanced-permissions))
+ ;; if advanced-permissions is enabled, we require users to have subscription permissions.
+ ;; Not a bare `has-feature?`: that ignores whether EE code is present, so an OSS jar with a
+ ;; stale paid token would demand a permission it can never grant.
+ (or (not (premium-features/enable-advanced-permissions?))
(perms/current-user-has-application-permissions? :subscription)))))
(defmethod mi/can-update? :model/Notification
@@ -629,7 +631,7 @@
;; if advanced-permissions is enabled, we require users to have subscription permissions
;; and is the owner of the notification and can read the payload
(or
- (not (premium-features/has-feature? :advanced-permissions))
+ (not (premium-features/enable-advanced-permissions?))
(perms/current-user-has-application-permissions? :subscription))
(current-user-can-read-payload? instance)
(current-user-can-read-payload? (merge instance changes))))))
@@ -642,7 +644,7 @@
(and
(current-user-is-creator? notification)
(or
- (not (premium-features/has-feature? :advanced-permissions))
+ (not (premium-features/enable-advanced-permissions?))
(perms/current-user-has-application-permissions? :subscription))
(current-user-can-read-payload? notification))))
([_model pk]
diff --git a/test/metabase/notification/api/notification_test.clj b/test/metabase/notification/api/notification_test.clj
index 126872fa84e..4acec0bdf5f 100644
--- a/test/metabase/notification/api/notification_test.clj
+++ b/test/metabase/notification/api/notification_test.clj
@@ -697,6 +697,32 @@
(create-notification! user 200)
(create-notification! :rasta 403)))))))))))))
+(deftest card-notification-permissions-without-ee-code-test
+ (testing "a token advertising :advanced-permissions doesn't lock non-admins out of alerts on a jar with no EE code"
+ ;; Must stay outside `mt/when-ee-evailable`: the OSS CI jobs are the only place this regresses, and that
+ ;; macro compiles its body out of them. The explicit `:subscription` grant keeps the expected status
+ ;; identical on both matrices.
+ (mt/with-model-cleanup [:model/Notification]
+ (binding [collection/*allow-deleting-personal-collections* true]
+ (mt/with-user-in-groups [group {:name "notification perm, no ee code"}
+ user [group]]
+ (perms/grant-application-permissions! group :subscription)
+ (mt/with-temp [:model/Card {card-id :id} {:collection_id (personal-collection-id user)}]
+ (mt/with-premium-features #{:advanced-permissions}
+ (let [notification (mt/user-http-request user :post 200 "notification"
+ {:payload_type "notification/card"
+ :payload {:card_id card-id}})
+ ;; drop creator_id: echoing it back reads as a (superuser-only) owner reassignment
+ update! (fn [changes]
+ (mt/user-http-request user :put 200 (format "notification/%d" (:id notification))
+ (merge (dissoc notification :creator_id)
+ {:updated_at (t/offset-date-time)}
+ changes)))]
+ (testing "the creator can update it"
+ (update! {}))
+ (testing "and archive it"
+ (is (=? {:active false} (update! {:active false}))))))))))))
+
(deftest update-card-notification-permissions-test
(mt/with-model-cleanup [:model/Notification]
(mt/with-user-in-groups [group {:name "test notification perm"}