def update( self, instance: Dashboard, validated_data: Dict, *args: Any, **kwargs: Any, ) -> Dashboard: user = cast(User, self.context["request"].user) can_user_restrict = instance.can_user_restrict(user.id) if "restriction_level" in validated_data and not can_user_restrict: raise exceptions.PermissionDenied( "Only the dashboard owner and project admins have the restriction rights required to change the dashboard's restriction level." ) validated_data.pop("use_template", None) # Remove attribute if present if validated_data.get("is_shared") and not instance.share_token: instance.share_token = secrets.token_urlsafe(22) instance = super().update(instance, validated_data) if "request" in self.context: report_user_action(user, "dashboard updated", instance.get_analytics_metadata()) return instance
def update( # type: ignore self, instance: Dashboard, validated_data: Dict, *args: Any, **kwargs: Any, ) -> Dashboard: validated_data.pop("use_template", None) # Remove attribute if present if validated_data.get("is_shared") and not instance.share_token: instance.share_token = secrets.token_urlsafe(22) instance = super().update(instance, validated_data) if "request" in self.context: posthoganalytics.capture( self.context["request"].user.distinct_id, "dashboard updated", instance.get_analytics_metadata() ) return instance
def get_items(self, dashboard: Dashboard): if self.context["view"].action == "list": return None if self.context["request"].GET.get("refresh"): update_dashboard_items_cache(dashboard) dashboard.refresh_from_db() items = dashboard.items.filter(deleted=False).order_by("order").all() self.context.update({"dashboard": dashboard}) dive_source_id = self.context["request"].GET.get("dive_source_id") if dive_source_id is not None: items = self.add_dive_source_item(items, int(dive_source_id)) return DashboardItemSerializer(items, many=True, context=self.context).data
def get_effective_privilege_level( self, dashboard: Dashboard) -> Dashboard.PrivilegeLevel: return dashboard.get_effective_privilege_level( self.context["request"].user.id)
def update( # type: ignore self, instance: Dashboard, validated_data: Dict, *args: Any, **kwargs: Any) -> Dashboard: if validated_data.get("is_shared") and not instance.share_token: instance.share_token = secrets.token_urlsafe(22) return super().update(instance, validated_data)