source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/uploads_controller.rb
Ruby
apache-2.0
187
the-future
739
class UploadsController < ApplicationController include CustomControllerHelpers before_action :authenticate_user!, only: :bulk_create def bulk_create files_to_upload = params[:files].map do |file| stripped_file = ImageProcessing::MiniMagick.source(file).saver(strip: true).call { user: user, conte...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/anime_controller.rb
Ruby
apache-2.0
187
the-future
318
class AnimeController < ApplicationController def languages model = Flipper[:media_castings].enabled?(User.current) ? MediaCasting : Casting languages = model.where(media_id: params[:anime_id], media_type: 'Anime') .distinct.pluck(:language).compact render json: languages end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/typesense_keys_controller.rb
Ruby
apache-2.0
187
the-future
557
# frozen_string_literal: true class TypesenseKeysController < ApplicationController include CustomControllerHelpers def all render json: { collections: { anime: json_for(Anime), manga: json_for(Manga), users: json_for(User) }, nodes: Typesensual.client.configuration.n...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/library_entries_controller.rb
Ruby
apache-2.0
187
the-future
2,383
class LibraryEntriesController < ApplicationController include CustomControllerHelpers before_action :authenticate_user!, only: %i[issues] def index return render_jsonapi_error(400, 'No filter provided') unless params.include?(:filter) super end def authorize_operation(operation) has_permission ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/trending_controller.rb
Ruby
apache-2.0
187
the-future
1,439
class TrendingController < ApplicationController include CustomControllerHelpers before_action :authenticate_for_in_network before_action :validate_namespace def index serializer = JSONAPI::ResourceSerializer.new(resource_class) render_jsonapi serializer.serialize_to_hash(resources) end private ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/graphql_controller.rb
Ruby
apache-2.0
187
the-future
1,567
# frozen_string_literal: true class GraphqlController < ApplicationController def execute variables = ensure_hash(params[:variables]) query = params[:query] operation_name = params[:operationName] context = { token: current_user, user: current_user&.resource_owner, site_permissions:...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/sso_controller.rb
Ruby
apache-2.0
187
the-future
356
class SSOController < ApplicationController include CustomControllerHelpers before_action :authenticate! def canny token = CannyToken.new(current_user.resource_owner) render json: { token: token.to_s } end private def authenticate! render status: 403, json: serialize_error(403, 'Not authenti...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/users_controller.rb
Ruby
apache-2.0
187
the-future
3,356
class UsersController < ApplicationController include CustomControllerHelpers def create if Flipper.enabled?(:registration) super else render_jsonapi_error(403, 'Registrations are closed') end end def recover query = params[:username] Accounts::SendPasswordReset.call(email: que...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/algolia_keys_controller.rb
Ruby
apache-2.0
187
the-future
748
# frozen_string_literal: true class AlgoliaKeysController < ApplicationController include CustomControllerHelpers def all render json: { users: json_for(User), media: json_for(Anime), groups: json_for(Group), characters: json_for(Character) } end def user render json: { us...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/application_controller.rb
Ruby
apache-2.0
187
the-future
1,536
# frozen_string_literal: true class ApplicationController < JSONAPI::ResourceController include PreferredLocale::AutoLocale include DoorkeeperHelpers include Pundit::ResourceController def base_url super + '/api/edge' end # TODO: get rid of this dumb hack for pundit-resources def enforce_policy_use...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/pro_subscription_controller.rb
Ruby
apache-2.0
187
the-future
2,304
class ProSubscriptionController < ApplicationController include CustomControllerHelpers before_action :check_feature_flag! before_action :authenticate_user! def ios receipt = AppleReceiptService.new(params[:receipt]) render json: ProSubscription::AppleSubscription.create!( user: user, bill...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/posts_controller.rb
Ruby
apache-2.0
187
the-future
315
# frozen_string_literal: true class PostsController < ApplicationController include CustomControllerHelpers def create if IPFilter.by_ip(request.remote_ip).take_action?(:block_posting) render_jsonapi_error(400, 'Your IP address has been blocked from posting') else super end end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/sessions_controller.rb
Ruby
apache-2.0
187
the-future
618
class SessionsController < ActionController::Base def new @redirect_to = params[:after] end def create return render status: :forbidden, plain: 'Token missing' if params[:token].blank? token = Doorkeeper::AccessToken.by_token(params[:token]) is_admin = token.resource_owner.permissions.any? re...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/feeds_controller.rb
Ruby
apache-2.0
187
the-future
3,012
class FeedsController < ApplicationController include CustomControllerHelpers before_action :authorize_feed! def show response_json = stringify_activities(query.list) render_jsonapi response_json end def mark_read activities = feed.activities.mark(:read, params[:_json]) render_jsonapi strin...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/groups_controller.rb
Ruby
apache-2.0
187
the-future
1,110
class GroupsController < ApplicationController include CustomControllerHelpers def stats stats = { today: {}, total: {} } if has_group_permission?(:members) stats[:today][:members] = GroupMember.in_group(group).created_today.count stats[:total][:members] = GroupMember.in_group(group).count ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/webhooks/stripe_controller.rb
Ruby
apache-2.0
187
the-future
514
module Webhooks class StripeController < ApplicationController include CustomControllerHelpers SECRET = ENV['STRIPE_WEBHOOK_SECRET'] def notify payload = request.body.read signature = request.env['HTTP_STRIPE_SIGNATURE'] event = Stripe::Webhook.construct_event(payload, signature, SECRE...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/webhooks/getstream_controller.rb
Ruby
apache-2.0
187
the-future
563
module Webhooks class GetstreamController < ApplicationController include CustomControllerHelpers http_basic_authenticate_with name: ENV['STREAM_WEBHOOK_USER'], password: ENV['STREAM_WEBHOOK_PASS'] def verify render plain: StreamRails.client.api_key end de...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/webhooks/apple_ios_billing_controller.rb
Ruby
apache-2.0
187
the-future
449
module Webhooks class AppleIosBillingController < ApplicationController include CustomControllerHelpers SECRET = AppleReceiptService::SECRET def notify AppleReceiptService.new(params[:latest_receipt]).call head 204 end private def check_secret unless ActiveSupport::Securi...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/webhooks/youtube_controller.rb
Ruby
apache-2.0
187
the-future
1,253
module Webhooks class YoutubeController < ApplicationController include CustomControllerHelpers before_action :check_linked_account_param def verify mode = params['hub.mode'] topic = params['hub.topic'] challenge = params['hub.challenge'] if !linked_account && mode == 'unsubscri...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/webhooks/google_play_billing_controller.rb
Ruby
apache-2.0
187
the-future
456
module Webhooks class GooglePlayBillingController < ApplicationController include CustomControllerHelpers SECRET = ENV['GOOGLE_PLAY_BILLING_WEBHOOK_SECRET'] def notify GooglePlayNotificationService.new(params).call head 204 end private def check_secret unless ActiveSuppor...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/concerns/custom_controller_helpers.rb
Ruby
apache-2.0
187
the-future
1,141
module CustomControllerHelpers extend ActiveSupport::Concern included do include Pundit::Authorization end def serialize_error(status, message) { errors: [ { status: status, detail: message } ] } end def serialize_model(model) resource = Bas...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/concerns/doorkeeper_helpers.rb
Ruby
apache-2.0
187
the-future
867
module DoorkeeperHelpers extend ActiveSupport::Concern def store_user_on_thread Thread.current[:current_user] = doorkeeper_token&.resource_owner begin yield ensure Thread.current[:current_user] = nil end end def current_user doorkeeper_token end # Return boolean representi...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/controllers/concerns/maintain_ip_addresses.rb
Ruby
apache-2.0
187
the-future
814
# frozen_string_literal: true module MaintainIPAddresses extend ActiveSupport::Concern def maintain_ip_addresses return unless signed_in? && current_user.resource_owner # RAILS-7: Replace this with UserIpAddress.upsert(update_only:) binds = [ [nil, current_user.resource_owner.id], [nil, r...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/processors/library_entry_processor.rb
Ruby
apache-2.0
187
the-future
400
class LibraryEntryProcessor < JSONAPI::Processor def find result = super # Send filters to #section_counts method. filters = params[:filters].reject { |k, _| k == :status } verified_filters = resource_klass.verify_filters(filters, context) counts = resource_klass.status_counts(verified_filters, c...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/drama_casting.rb
Ruby
apache-2.0
187
the-future
280
class DramaCasting < ApplicationRecord validates :locale, length: { maximum: 20 } validates :notes, length: { maximum: 140 } belongs_to :drama_character, required: true belongs_to :person, required: true belongs_to :licensor, class_name: 'Producer', optional: true end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/pro_subscription.rb
Ruby
apache-2.0
187
the-future
461
class ProSubscription < ApplicationRecord class NoCancellationError < StandardError; end belongs_to :user, required: true enum tier: { pro: 1, patron: 2 } validates :type, presence: true validates :billing_id, presence: true validates :tier, presence: true def cancel! raise NoCancellation...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/character.rb
Ruby
apache-2.0
187
the-future
1,314
class Character < ApplicationRecord include LocalizableModel include Mappable include DescriptionSanitation include PortraitImageUploader::Attachment(:image) extend FriendlyId friendly_id :slug_candidates, use: %i[slugged finders history] validates :canonical_name, presence: true validates :primary_med...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_relationship.rb
Ruby
apache-2.0
187
the-future
674
class MediaRelationship < ApplicationRecord enum role: { sequel: 0, prequel: 1, alternative_setting: 2, alternative_version: 3, side_story: 4, parent_story: 5, summary: 6, full_story: 7, spinoff: 8, adaptation: 9, character: 10, other: 11 } belongs_to :source, poly...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/profile_link.rb
Ruby
apache-2.0
187
the-future
682
class ProfileLink < ApplicationRecord belongs_to :user belongs_to :profile_link_site validates :url, presence: true validate :url_formatted, if: -> { profile_link_site.present? && url.present? } validates :profile_link_site, uniqueness: { scope: :user } before_validation if: -> { profile_link_site.present...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/ama_subscriber.rb
Ruby
apache-2.0
187
the-future
442
class AMASubscriber < ApplicationRecord belongs_to :user, required: true belongs_to :ama, required: true, counter_cache: true validates :ama_id, uniqueness: { scope: :user_id } validates :ama, active_ama: { message: 'can not subscribe to this AMA', user: :user } after_commit on: :create do user...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/category.rb
Ruby
apache-2.0
187
the-future
797
# frozen_string_literal: true class Category < ApplicationRecord include Mappable include DescriptionSanitation extend FriendlyId friendly_id :title, use: %i[slugged finders history] resourcify has_ancestry has_many :category_favorite, dependent: :destroy has_many :media_categories has_many :media, ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_reaction.rb
Ruby
apache-2.0
187
the-future
1,445
# frozen_string_literal: true class MediaReaction < ApplicationRecord include WithActivity include Holdable include WithModerationScores WordfilterCallbacks.hook(self, :reaction, :reaction) acts_as_paranoid belongs_to :user, counter_cache: true belongs_to :media, polymorphic: true belongs_to :anime, ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/manga.rb
Ruby
apache-2.0
187
the-future
2,795
# frozen_string_literal: true class Manga < ApplicationRecord include Media include AgeRatings enum subtype: { manga: 0, novel: 1, manhua: 2, oneshot: 3, doujin: 4, manhwa: 5, oel: 6 } alias_attribute :progress_limit, :chapter_count alias_attribute :manga_type, :subtype rails_admin { fi...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/favorite.rb
Ruby
apache-2.0
187
the-future
470
class Favorite < ApplicationRecord include RankedModel ranks :fav_rank, with_same: %i[user_id item_type] belongs_to :user, required: true, counter_cache: true belongs_to :item, polymorphic: true, required: true validates :item, polymorphism: { type: [Media, Character, Person] } validates :user_id, uniquen...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/quote.rb
Ruby
apache-2.0
187
the-future
474
class Quote < ApplicationRecord include WithActivity belongs_to :user, counter_cache: true belongs_to :media, polymorphic: true, inverse_of: :quotes has_many :likes, class_name: 'QuoteLike', dependent: :destroy has_many :lines, -> { rank(:order) }, class_name: 'QuoteLine', dependent: :destroy, in...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/user.rb
Ruby
apache-2.0
187
the-future
17,309
# frozen_string_literal: true # == Schema Information # # Table name: users # # id :integer not null, primary key # about :string(500) default(""), not null # about_formatted :text # ao_password :string # ao_pro ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_action_log.rb
Ruby
apache-2.0
187
the-future
319
class GroupActionLog < ApplicationRecord belongs_to :target, required: true, polymorphic: true belongs_to :group, required: true belongs_to :user, required: true validates :verb, presence: true scope :visible_for, ->(user) { where(group_id: GroupMember.leaders.for_user(user).select(:group_id)) } end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_reaction_vote.rb
Ruby
apache-2.0
187
the-future
495
class MediaReactionVote < ApplicationRecord include WithActivity belongs_to :media_reaction, required: true belongs_to :user, required: true counter_culture :media_reaction, column_name: 'up_votes_count' validate :vote_on_self def vote_on_self errors.add(:user, 'You can not vote for yourself') if me...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_production.rb
Ruby
apache-2.0
187
the-future
262
class MediaProduction < ApplicationRecord enum role: %i[producer licensor studio serialization] belongs_to :media, polymorphic: true, inverse_of: :productions belongs_to :company, class_name: 'Producer' def rails_admin_label company.name end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/moderator_action_log.rb
Ruby
apache-2.0
187
the-future
242
class ModeratorActionLog < ApplicationRecord belongs_to :user, required: true belongs_to :target, polymorphic: true, required: true def self.generate!(actor, verb, target) create!(user: actor, verb: verb, target: target) end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/review.rb
Ruby
apache-2.0
187
the-future
894
class Review < ApplicationRecord include WithActivity include ContentProcessable acts_as_paranoid has_many :likes, class_name: 'ReviewLike', dependent: :destroy belongs_to :media, polymorphic: true, required: true belongs_to :user, required: true, counter_cache: true belongs_to :library_entry, required:...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/comment_like.rb
Ruby
apache-2.0
187
the-future
524
class CommentLike < ApplicationRecord include WithActivity belongs_to :user, required: true belongs_to :comment, required: true, counter_cache: :likes_count, touch: true validates :comment, uniqueness: { scope: :user_id } validates :comment, active_ama: { message: 'cannot like comments on this AMA', ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/quote_line.rb
Ruby
apache-2.0
187
the-future
217
class QuoteLine < ApplicationRecord include RankedModel ranks :order, with_same: %i[quote_id] belongs_to :quote, required: true belongs_to :character, required: true validates :content, presence: true end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_member.rb
Ruby
apache-2.0
187
the-future
1,763
class GroupMember < ApplicationRecord belongs_to :group, required: true, counter_cache: 'members_count', touch: true belongs_to :user, required: true has_many :permissions, class_name: 'GroupPermission', dependent: :destroy has_many :notes, class_name: 'GroupMemberNote', dependent: :destroy counter_culture :...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/list_import.rb
Ruby
apache-2.0
187
the-future
4,045
# frozen_string_literal: true class ListImport < ApplicationRecord include Enumerable include WithActivity belongs_to :user, optional: false enum strategy: { greater: 0, obliterate: 1 } enum status: { queued: 0, running: 1, failed: 2, completed: 3, partially_failed: 4 } alias_attribute :kind, :type va...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_invite.rb
Ruby
apache-2.0
187
the-future
2,172
class GroupInvite < ApplicationRecord include WithActivity belongs_to :group, required: true belongs_to :user, required: true belongs_to :sender, class_name: 'User', required: true # Limit to one pending invite per user per group validates :user, uniqueness: { scope: :group_id, conditions: -> { pe...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/follow.rb
Ruby
apache-2.0
187
the-future
1,244
class Follow < ApplicationRecord include WithActivity belongs_to :follower, class_name: 'User', required: true, inverse_of: :following, counter_cache: :following_count, touch: true belongs_to :followed, class_name: 'User', required: true, inverse_of: :followers, co...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_ignore.rb
Ruby
apache-2.0
187
the-future
536
class MediaIgnore < ApplicationRecord belongs_to :media, polymorphic: true, required: true belongs_to :user, required: true validates :media, polymorphism: { type: Media } scope :for_library_entry, ->(le) { where(media: le.media, user: le.user) } def library_entry LibraryEntry.find_by(user: user, media...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/block.rb
Ruby
apache-2.0
187
the-future
1,129
class Block < ApplicationRecord belongs_to :user belongs_to :blocked, class_name: 'User' scope :between, ->(user_a, user_b) { Block.where(user_id: user_a, blocked_id: user_b) .or(Block.where(user_id: user_b, blocked_id: user_a)) } validates :blocked, uniqueness: { scope: :user_id } validate ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/genre.rb
Ruby
apache-2.0
187
the-future
222
class Genre < ApplicationRecord include DescriptionSanitation extend FriendlyId friendly_id :name, use: %i[slugged finders history] resourcify has_and_belongs_to_many :anime has_and_belongs_to_many :manga end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/feed.rb
Ruby
apache-2.0
187
the-future
3,553
# This class is an abstraction on top of Stream Feeds, hiding the details of # what underlying feeds there are (some "feeds" are actually a group of 6+ # feeds!) class Feed attr_reader :id # Create a new instance of this feed for a given ID. If given multiple # parameters, concatenates them with hyphens in betw...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/notification_setting.rb
Ruby
apache-2.0
187
the-future
1,411
class NotificationSetting < ApplicationRecord NOTIFICATION_TYPES = %i[mentions replies likes follows posts reaction_votes airing].freeze DEFAULT_SETTINGS = { # FB, Mobile, Email, Web mentions: [false, true, false, true], replies: [false, true, false, true], likes: ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/pro_gift.rb
Ruby
apache-2.0
187
the-future
569
class ProGift < ApplicationRecord belongs_to :from, class_name: 'User', required: true belongs_to :to, class_name: 'User', required: true enum tier: { pro: 1, patron: 2 } validates :message, length: { maximum: 500 } after_create :send_email after_create :extend_pro def send_email ProMaile...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/post.rb
Ruby
apache-2.0
187
the-future
5,431
# frozen_string_literal: true class Post < ApplicationRecord include WithActivity include ContentProcessable include ContentEmbeddable include Holdable include WithModerationScores WordfilterCallbacks.hook(self, :post, :content) acts_as_paranoid resourcify processable :content, LongPipeline embed_...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_permission.rb
Ruby
apache-2.0
187
the-future
1,281
class GroupPermission < ApplicationRecord belongs_to :group_member, required: true validates :permission, uniqueness: { scope: %i[group_member_id] } # Specifies which permission is provided by this. Permissions are as follows: # # * owner - has all permissions, can give owner status to another leader or ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_ban.rb
Ruby
apache-2.0
187
the-future
651
class GroupBan < ApplicationRecord include ContentProcessable belongs_to :group, required: true belongs_to :user, required: true belongs_to :moderator, class_name: 'User', required: true processable :notes, InlinePipeline validates :user, uniqueness: { scope: %i[group_id] } scope :visible_for, ->(user...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/mapping.rb
Ruby
apache-2.0
187
the-future
969
class Mapping < ApplicationRecord belongs_to :item, polymorphic: true, required: true, inverse_of: :mappings validates :external_site, :external_id, presence: true # Right now, we want to ensure only one external id per item per site validates :item_id, uniqueness: { scope: %i[item_type external_site] } def...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/application_record.rb
Ruby
apache-2.0
187
the-future
1,376
# frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base self.abstract_class = true WHITELISTED_ADMIN_FIELDS = %w[episode_count chapter_count volume_count].freeze def stream_id "#{self.class.name}:#{id}" end def self.created_today where(created_at: Date.today..Date.tomorrow) en...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/community_recommendation_request.rb
Ruby
apache-2.0
187
the-future
570
class CommunityRecommendationRequest < ApplicationRecord include WithActivity include DescriptionSanitation belongs_to :user, required: true has_many :community_recommendations validates :description, presence: true validates :title, presence: true def feed @feed ||= CommunityRecommendationRequestF...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/post_follow.rb
Ruby
apache-2.0
187
the-future
449
class PostFollow < ApplicationRecord belongs_to :user, required: true belongs_to :post, required: true validates :post, uniqueness: { scope: :user_id } validates :post, active_ama: { message: 'cannot follow this AMA', user: :user } after_commit(on: :create) do user.notifications.follow(post.co...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/library_event.rb
Ruby
apache-2.0
187
the-future
821
class LibraryEvent < ApplicationRecord belongs_to :library_entry, required: true belongs_to :user, required: true belongs_to :anime, optional: true belongs_to :manga, optional: true belongs_to :drama, optional: true enum kind: %i[progressed updated reacted rated annotated] validates :kind, presence: true...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/hashtag.rb
Ruby
apache-2.0
187
the-future
306
class Hashtag < ApplicationRecord enum kind: %i[user_created character anime aozora game art music review genre news event talk] belongs_to :item, polymorphic: true def self.find_or_create(name, obj = {}) where(name: name.downcase).first_or_create({ kind: :user_created }.merge(obj)) end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/wiki_submission.rb
Ruby
apache-2.0
187
the-future
462
class WikiSubmission < ApplicationRecord belongs_to :user has_many :logs, class_name: 'WikiSubmissionLog', dependent: :destroy belongs_to :parent, inverse_of: :child, class_name: 'WikiSubmission', optional: true has_one :child, inverse_of: :parent, class_name: 'WikiSubmission', foreign_ke...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/category_favorite.rb
Ruby
apache-2.0
187
the-future
240
class CategoryFavorite < ApplicationRecord belongs_to :user, required: true belongs_to :category, required: true validates :user_id, uniqueness: { scope: :category_id, message: 'Cannot fave a category multiple times' } end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/drama_character.rb
Ruby
apache-2.0
187
the-future
225
class DramaCharacter < ApplicationRecord enum role: %i[main supporting] belongs_to :drama, required: true belongs_to :character, required: true has_many :castings, class_name: 'DramaCasting', dependent: :destroy end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/streaming_link.rb
Ruby
apache-2.0
187
the-future
374
class StreamingLink < ApplicationRecord include Streamable belongs_to :media, polymorphic: true, touch: true, optional: false, inverse_of: :streaming_links validates :url, presence: true validates :media, polymorphism: { type: Media } after_commit do media.typesense_index.index_one(media.id) end d...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/character_voice.rb
Ruby
apache-2.0
187
the-future
302
class CharacterVoice < ApplicationRecord belongs_to :media_character, inverse_of: :voices belongs_to :person, inverse_of: :voices belongs_to :licensor, class_name: 'Producer', optional: true validates :locale, presence: true def rails_admin_label "#{person.name} [#{locale}]" end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/canny_token.rb
Ruby
apache-2.0
187
the-future
676
class CannyToken ALGORITHM = 'AES-128-ECB'.freeze attr_reader :user def initialize(user) @user = user end def to_s encrypt(JSON.generate(user_data)) end def user_data { avatarURL: user.avatar(:large)&.url, name: user.name, id: user.id, email: user.email }.compac...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/ip_filter.rb
Ruby
apache-2.0
187
the-future
1,734
# frozen_string_literal: true class IPFilter < ApplicationRecord self.inheritance_column = nil enum type: { asn: 1, city: 2, country: 3 } flag :actions, %i[ require_email_validation block_posting ] scope :by_asn, ->(asn) { where(type: :asn, pattern: asn) } scope :by_city, ->(city) { ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group.rb
Ruby
apache-2.0
187
the-future
2,534
class Group < ApplicationRecord include AvatarUploader::Attachment(:avatar) include CoverImageUploader::Attachment(:cover_image) include ContentProcessable include Sluggable friendly_id :name, use: %i[slugged finders history] processable :rules, RulesPipeline enum privacy: %i[open closed restricted] u...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/casting.rb
Ruby
apache-2.0
187
the-future
411
class Casting < ApplicationRecord belongs_to :media, polymorphic: true, touch: true belongs_to :character, touch: true, optional: true belongs_to :person, touch: true, optional: true validates :media, presence: true, polymorphism: { type: Media } # Require either character or person validates :character, p...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_casting.rb
Ruby
apache-2.0
187
the-future
217
class MediaCasting < ApplicationRecord self.primary_key = :id belongs_to :media, polymorphic: true belongs_to :character, optional: true belongs_to :person, optional: true def readonly? true end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/comment.rb
Ruby
apache-2.0
187
the-future
3,223
# frozen_string_literal: true class Comment < ApplicationRecord include WithActivity include ContentProcessable include ContentEmbeddable include Holdable include WithModerationScores WordfilterCallbacks.hook(self, :comment, :content) acts_as_paranoid resourcify counter_culture :post, column_name: -...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/installment.rb
Ruby
apache-2.0
187
the-future
371
class Installment < ApplicationRecord include RankedModel ranks :release_order ranks :alternative_order enum tag: { main_story: 0, side_story: 1, spinoff: 2, crossover: 3, alternate_setting: 4, alternate_version: 5 } validates :media, polymorphism: { type: Media } belongs_to :fr...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/chapter.rb
Ruby
apache-2.0
187
the-future
775
# frozen_string_literal: true class Chapter < ApplicationRecord include Unit belongs_to :manga, inverse_of: :chapters belongs_to :volume, counter_cache: true, optional: true, inverse_of: :chapters validates :volume_number, presence: true scope :for_progress, ->(progress) do order(:volume_number, :numb...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/community_recommendation.rb
Ruby
apache-2.0
187
the-future
620
class CommunityRecommendation < ApplicationRecord include RetrieveMedia belongs_to :anime, optional: true belongs_to :manga, optional: true belongs_to :drama, optional: true belongs_to :media, polymorphic: true, required: true belongs_to :community_recommendation_request, required: true has_many :reasons...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_attribute.rb
Ruby
apache-2.0
187
the-future
433
class MediaAttribute < ApplicationRecord extend FriendlyId friendly_id :title, use: %i[slugged finders history] resourcify has_many :anime_media_attributes has_many :anime, through: :anime_media_attributes has_many :manga_media_attributes has_many :manga, through: :manga_media_attributes has_many :dram...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/linked_account.rb
Ruby
apache-2.0
187
the-future
960
class LinkedAccount < ApplicationRecord belongs_to :user has_many :library_entry_logs, dependent: :destroy # encyrpt the token attr_encrypted :token, key: Base64.decode64(ENV['ATTR_ENCRYPT_KEY']) # expose for jsonapi alias_attribute :kind, :type validates_presence_of :external_user_id, :type validate :...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/anime.rb
Ruby
apache-2.0
187
the-future
3,728
# frozen_string_literal: true class Anime < ApplicationRecord SEASONS = %w[winter spring summer fall].freeze include Media include AgeRatings include Episodic enum subtype: { TV: 0, special: 1, OVA: 2, ONA: 3, movie: 4, music: 5 } has_many :streaming_links, as: 'media', dependent: :destroy, inverse_of: :...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_report.rb
Ruby
apache-2.0
187
the-future
1,055
class GroupReport < ApplicationRecord include WithActivity belongs_to :group, required: true belongs_to :naughty, -> { with_deleted }, polymorphic: true, required: true belongs_to :user, required: true belongs_to :moderator, class_name: 'User', optional: true enum reason: Report.reasons enum status: %i[...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/episode.rb
Ruby
apache-2.0
187
the-future
1,681
# frozen_string_literal: true class Episode < ApplicationRecord include Unit belongs_to :media, polymorphic: true, inverse_of: :episodes has_many :videos accepts_nested_attributes_for :videos, allow_destroy: true validates :media, presence: true, polymorphism: { type: Media } validates :season_number, pr...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/person.rb
Ruby
apache-2.0
187
the-future
523
class Person < ApplicationRecord include Mappable include DescriptionSanitation include PortraitImageUploader::Attachment(:image) extend FriendlyId friendly_id :name, use: %i[slugged finders history] has_many :castings, dependent: :destroy has_many :anime_castings, dependent: :destroy has_many :drama_c...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/embedder.rb
Ruby
apache-2.0
187
the-future
2,667
class Embedder attr_reader :url, :body delegate :get, to: :EmbedService # @return [Integer] the version number of the Embedder class, used for cache busting def self.version self::VERSION rescue NameError 2 end # @return [String] the identifier of the Embedder class in our cache def self.cache...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/media_attribute_vote.rb
Ruby
apache-2.0
187
the-future
1,340
class MediaAttributeVote < ApplicationRecord enum vote: %i[unvoted low neutral high] belongs_to :user, required: true belongs_to :media, polymorphic: true, required: true belongs_to :anime_media_attributes, class_name: 'AnimeMediaAttribute', optional: true belongs_to :manga_media_attributes, class_name: 'Man...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/volume.rb
Ruby
apache-2.0
187
the-future
279
class Volume < ApplicationRecord include Titleable include UnitThumbnailUploader::Attachment(:thumbnail) belongs_to :manga, inverse_of: :volumes has_many :chapters, inverse_of: :volume validates :number, presence: true validates :chapters_count, presence: true end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/site_announcement.rb
Ruby
apache-2.0
187
the-future
254
class SiteAnnouncement < ApplicationRecord include WithActivity include DescriptionSanitation belongs_to :user, required: true validates :title, presence: true def stream_activity SiteAnnouncementsGlobalFeed.new.activities.new end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/upload.rb
Ruby
apache-2.0
187
the-future
440
class Upload < ApplicationRecord include RankedModel include AttachmentUploader::Attachment(:content) ranks :upload_order, with_same: %i[owner_type owner_id] belongs_to :user belongs_to :owner, polymorphic: true, optional: true validates :upload_order, presence: true, if: :owner_id? scope :orphan, -> { ...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/post_like.rb
Ruby
apache-2.0
187
the-future
1,169
class PostLike < ApplicationRecord include WithActivity belongs_to :user, required: true belongs_to :post, required: true, counter_cache: true, touch: true validates :post, uniqueness: { scope: :user_id } validates :post, active_ama: { message: 'cannot like this AMA', user: :user } counter_cult...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/report.rb
Ruby
apache-2.0
187
the-future
1,486
# == Schema Information # # Table name: reports # # id :integer not null, primary key # explanation :text # naughty_type :string not null, indexed => [naughty_id] # reason :integer not null # status :integer default(0), not null, indexed # created_at :...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_neighbor.rb
Ruby
apache-2.0
187
the-future
221
class GroupNeighbor < ApplicationRecord belongs_to :source, class_name: 'Group', required: true, counter_cache: 'neighbors_count' belongs_to :destination, class_name: 'Group', required: true end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/anime_casting.rb
Ruby
apache-2.0
187
the-future
280
class AnimeCasting < ApplicationRecord validates :locale, length: { maximum: 20 } validates :notes, length: { maximum: 140 } belongs_to :anime_character, required: true belongs_to :person, required: true belongs_to :licensor, class_name: 'Producer', optional: true end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/role.rb
Ruby
apache-2.0
187
the-future
302
class Role < ApplicationRecord has_and_belongs_to_many :users, join_table: :users_roles belongs_to :resource, polymorphic: true, optional: true has_many :user_roles, dependent: :destroy validates :resource_type, inclusion: { in: Rolify.resource_types }, allow_nil: true scopify end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_member_note.rb
Ruby
apache-2.0
187
the-future
434
class GroupMemberNote < ApplicationRecord include ContentProcessable belongs_to :group_member, required: true belongs_to :user, required: true validates :content, presence: true processable :content, InlinePipeline scope :visible_for, ->(user) { members = GroupMember.with_permission(:members).for_us...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/ama.rb
Ruby
apache-2.0
187
the-future
1,020
class AMA < ApplicationRecord include DescriptionSanitation belongs_to :author, required: true, class_name: 'User' belongs_to :original_post, required: true, class_name: 'Post' has_many :ama_subscribers, dependent: :destroy scope :for_original_post, ->(post) { where(original_post: post) } scope :past_ama,...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/producer.rb
Ruby
apache-2.0
187
the-future
293
class Producer < ApplicationRecord include Mappable extend FriendlyId friendly_id :name, use: %i[slugged finders history] has_many :anime_productions has_many :anime, through: :anime_productions has_many :productions, class_name: 'MediaProduction', foreign_key: 'company_id' end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/one_signal_player.rb
Ruby
apache-2.0
187
the-future
269
class OneSignalPlayer < ApplicationRecord belongs_to :user enum platform: %i[web mobile] validates :player_id, uniqueness: true, presence: true scope :enabled_for_setting, ->(setting) do where(platform: platforms & setting.enabled_platforms) end end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_ticket.rb
Ruby
apache-2.0
187
the-future
724
class GroupTicket < ApplicationRecord belongs_to :user, required: true belongs_to :group, required: true belongs_to :assignee, class_name: 'User', optional: true belongs_to :first_message, class_name: 'GroupTicketMessage', optional: true has_many :messages, class_name: 'GroupTicketMessage', foreign_key: 'tick...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/group_ticket_message.rb
Ruby
apache-2.0
187
the-future
634
class GroupTicketMessage < ApplicationRecord belongs_to :ticket, class_name: 'GroupTicket', required: true belongs_to :user, required: true enum kind: %i[message mod_note] update_index('group_tickets#group_ticket') { ticket } scope :visible_for, ->(user) { members = GroupMember.with_permission(:tickets)...
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/drama.rb
Ruby
apache-2.0
187
the-future
233
class Drama < ApplicationRecord include Media include AgeRatings include Episodic enum subtype: %i[drama movie special] has_many :media_attributes, through: :dramas_media_attributes has_many :dramas_media_attributes end
github
hummingbird-me/kitsu-server
https://github.com/hummingbird-me/kitsu-server
app/models/leader_chat_message.rb
Ruby
apache-2.0
187
the-future
396
class LeaderChatMessage < ApplicationRecord include ContentProcessable belongs_to :group, required: true belongs_to :user, required: true processable :content, InlinePipeline scope :visible_for, ->(user) { # has leadership where(group_id: GroupMember.leaders.for_user(user).select(:group_id)) } ...