event_id = request.headers.fetch('X-Event-Id')
timestamp = request.headers.fetch('X-Signature-Timestamp').to_i
raise ActionController::BadRequest, 'stale request' if Time.now.to_i - timestamp > 300
raise ActionController::BadRequest, 'replay detected' if WebhookEvent.exists?(external_id: event_id)
class SlugValidator < ActiveModel::Validator
SLUG_REGEX = /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/
def validate(record)
slug = record.send(options[:attribute] || :slug)
<%= link_to project.name, project_path(project), data: { turbo_preload: true }, class: 'font-medium hover:underline' %>
raw_token = SecureRandom.urlsafe_base64(32)
token_digest = Digest::SHA256.hexdigest(raw_token)
PasswordReset.create!(
user: user,
token_digest: token_digest,
class CreateTopSnipsMaterializedView < ActiveRecord::Migration[6.1]
def change
execute <<~SQL
CREATE MATERIALIZED VIEW top_snips AS
SELECT id, title, score
FROM snips
<%= link_to "Show audit", audit_project_path(@project), data: { turbo_frame: "audit" }, class: "btn" %>
<%= turbo_frame_tag "audit" do %>
<p class="text-sm text-gray-500">Audit will load here.</p>
<% end %>
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :excerpt, :body, :published_at, :views, :likes_count, :comments_count
attribute :can_edit, if: :current_user_can_edit?
belongs_to :author, serializer: UserSummarySerializer
class DeadLetter < ApplicationRecord
validates :job_class, :payload, :error_class, presence: true
end
class Api::CollectionsController < ActionController::API
def show
collection = Collection.includes(snips: [:author, :code_blocks]).find(params[:id])
render json: CollectionSerializer.new(collection).as_json
end
end
class Analytics::TopAuthors
def initialize(since: 30.days.ago)
@since = since
end
def call(limit: 20)
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params.merge(author: current_member))
if @comment.save
<%= turbo_frame_tag dom_id(user) do %>
<tr>
<td><%= user.name %></td>
<td><%= user.role %></td>
<td>
<%= link_to 'Edit', edit_user_path(user), data: { turbo_frame: dom_id(user) } %>