├── .editorconfig ├── .env.example ├── .gitignore ├── .hound.yml ├── .hound_defaults.yml ├── .rspec ├── .rubocop.yml ├── .ruby-version ├── CONTRIBUTING.md ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── LICENSE.txt ├── Procfile ├── Procfile.dev ├── README.md ├── Rakefile ├── app ├── assets │ └── images │ │ └── .keep ├── controllers │ ├── application_controller.rb │ ├── categories_controller.rb │ ├── comment_images_controller.rb │ ├── comment_user_mentions_controller.rb │ ├── comments_controller.rb │ ├── concerns │ │ └── .keep │ ├── ember_index_controller.rb │ ├── github_repositories_controller.rb │ ├── import_skill_failures_controller.rb │ ├── imports_controller.rb │ ├── organization_memberships_controller.rb │ ├── organizations_controller.rb │ ├── ping_controller.rb │ ├── post_images_controller.rb │ ├── post_likes_controller.rb │ ├── post_user_mentions_controller.rb │ ├── posts_controller.rb │ ├── preview_user_mentions_controller.rb │ ├── previews_controller.rb │ ├── project_categories_controller.rb │ ├── project_roles_controller.rb │ ├── project_skills_controller.rb │ ├── projects_controller.rb │ ├── role_skills_controller.rb │ ├── roles_controller.rb │ ├── skills_controller.rb │ ├── slugged_routes_controller.rb │ ├── tokens_controller.rb │ ├── user_categories_controller.rb │ ├── user_roles_controller.rb │ ├── user_skills_controller.rb │ └── users_controller.rb ├── mailers │ ├── .keep │ ├── notification_mailer.rb │ └── passwords_mailer.rb ├── models │ ├── .keep │ ├── application_record.rb │ ├── category.rb │ ├── comment.rb │ ├── comment_image.rb │ ├── comment_user_mention.rb │ ├── concerns │ │ └── .keep │ ├── github_repository.rb │ ├── import.rb │ ├── import_skill_failure.rb │ ├── notification.rb │ ├── organization.rb │ ├── organization_membership.rb │ ├── post.rb │ ├── post_image.rb │ ├── post_like.rb │ ├── post_user_mention.rb │ ├── preview.rb │ ├── preview_user_mention.rb │ ├── project.rb │ ├── project_category.rb │ ├── project_role.rb │ ├── project_skill.rb │ ├── role.rb │ ├── role_skill.rb │ ├── skill.rb │ ├── slugged_route.rb │ ├── user.rb │ ├── user_category.rb │ ├── user_relationship.rb │ ├── user_role.rb │ └── user_skill.rb ├── policies │ ├── category_policy.rb │ ├── comment_image_policy.rb │ ├── comment_policy.rb │ ├── comment_user_mention_policy.rb │ ├── github_repository_policy.rb │ ├── import_policy.rb │ ├── import_skill_failure_policy.rb │ ├── organization_membership_policy.rb │ ├── organization_policy.rb │ ├── post_image_policy.rb │ ├── post_like_policy.rb │ ├── post_policy.rb │ ├── post_user_mention_policy.rb │ ├── preview_user_mention_policy.rb │ ├── project_category_policy.rb │ ├── project_policy.rb │ ├── project_role_policy.rb │ ├── project_skill_policy.rb │ ├── role_policy.rb │ ├── role_skill_policy.rb │ ├── skill_policy.rb │ ├── slugged_route_policy.rb │ ├── user_category_policy.rb │ ├── user_policy.rb │ ├── user_role_policy.rb │ └── user_skill_policy.rb ├── serializers │ ├── category_serializer.rb │ ├── comment_image_serializer.rb │ ├── comment_serializer.rb │ ├── comment_user_mention_serializer.rb │ ├── error_serializer.rb │ ├── github_repository_serializer.rb │ ├── import_serializer.rb │ ├── import_skill_failure_serializer.rb │ ├── organization_membership_serializer.rb │ ├── organization_serializer.rb │ ├── post_image_serializer.rb │ ├── post_like_serializer.rb │ ├── post_serializer.rb │ ├── post_serializer_without_includes.rb │ ├── post_user_mention_serializer.rb │ ├── preview_serializer.rb │ ├── preview_user_mention_serializer.rb │ ├── project_category_serializer.rb │ ├── project_role_serializer.rb │ ├── project_serializer.rb │ ├── project_serializer_without_includes.rb │ ├── project_skill_serializer.rb │ ├── role_serializer.rb │ ├── role_serializer_without_includes.rb │ ├── role_skill_serializer.rb │ ├── skill_serializer.rb │ ├── skill_serializer_without_includes.rb │ ├── slugged_route_serializer.rb │ ├── user_category_serializer.rb │ ├── user_role_serializer.rb │ ├── user_serializer.rb │ ├── user_serializer_without_includes.rb │ └── user_skill_serializer.rb ├── services │ └── analytics.rb ├── validators │ ├── base64_photo_data_validator.rb │ └── slug_validator.rb ├── views │ └── notification_mailer │ │ ├── notify.html.erb │ │ └── notify.text.erb └── workers │ ├── add_facebook_friends_worker.rb │ ├── add_facebook_profile_picture_worker.rb │ ├── add_organization_icon_worker.rb │ ├── add_profile_picture_from_gravatar_worker.rb │ ├── add_project_icon_worker.rb │ ├── generate_comment_user_notifications_worker.rb │ ├── generate_post_user_notifications_worker.rb │ ├── notify_pusher_of_comment_image_worker.rb │ ├── notify_pusher_of_post_image_worker.rb │ ├── perform_import_worker.rb │ ├── subscribe_to_mailing_list_worker.rb │ └── update_profile_picture_worker.rb ├── bin ├── bundle ├── colors ├── development ├── migrate ├── production ├── rails ├── rake ├── reseed ├── setup ├── spring └── staging ├── blueprint ├── Dockerfile ├── api.apib ├── docker-compose.yml └── generate ├── circle.yml ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── active_model_serializers.rb │ ├── application_controller_renderer.rb │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── clearance.rb │ ├── cookies_serializer.rb │ ├── doorkeeper.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── new_framework_defaults.rb │ ├── pusher.rb │ ├── redis.rb │ ├── reserved_routes.rb │ ├── secret_token.rb │ ├── sentry.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ ├── doorkeeper.en.yml │ └── en.yml ├── newrelic.yml ├── puma.rb ├── routes.rb ├── secrets.yml ├── sidekiq.yml └── spring.rb ├── db ├── fixtures │ ├── 001_users.rb │ ├── 002_organizations.rb │ ├── 003_projects.rb │ ├── 004_posts.rb │ ├── 005_categories.rb │ ├── 006_roles.rb │ └── 007_skills.rb ├── migrate │ ├── 20150623143430_create_users.rb │ ├── 20150623143522_create_doorkeeper_tables.rb │ ├── 20150623144945_add_username_to_users.rb │ ├── 20150628202953_add_admin_to_users.rb │ ├── 20151119113429_create_project_related_tables.rb │ ├── 20151124121656_add_twitter_website_biography_to_user.rb │ ├── 20151124130003_create_posts.rb │ ├── 20151124130007_create_comments.rb │ ├── 20151124205005_add_icon_columns_to_projects.rb │ ├── 20151124222923_add_icon_data_to_projects.rb │ ├── 20151125120623_rename_posts_type.rb │ ├── 20151125134242_add_foreign_keys_to_posts.rb │ ├── 20151125142534_make_comment_body_not_nullable.rb │ ├── 20151125142551_add_foreign_keys_to_comments.rb │ ├── 20151126094430_create_skill_categories.rb │ ├── 20151126094437_create_skills.rb │ ├── 20151126100212_create_user_skills.rb │ ├── 20151126133741_create_post_likes.rb │ ├── 20151130085255_make_posts_body_not_nullable.rb │ ├── 20151130204153_add_markdown_to_posts.rb │ ├── 20151201091555_create_contributors.rb │ ├── 20151201175725_add_markdown_to_comments.rb │ ├── 20151201201552_create_post_user_mentions.rb │ ├── 20151202083431_add_facebook_to_users.rb │ ├── 20151203125938_create_github_repositories.rb │ ├── 20151203174346_create_slug_routes.rb │ ├── 20151203181837_add_slug_to_organizations.rb │ ├── 20151203191921_add_contributors_count_to_projects.rb │ ├── 20151204234343_add_number_to_posts.rb │ ├── 20151205212042_create_members.rb │ ├── 20151205223211_drop_slug_routes.rb │ ├── 20151207101527_add_slug_to_projects.rb │ ├── 20151207192647_add_photo_to_users.rb │ ├── 20151207224048_addphotocolumnstousers.rb │ ├── 20151208115704_create_user_relationships.rb │ ├── 20151208214105_create_comment_user_mentions.rb │ ├── 20151208225204_create_notifications.rb │ ├── 20151209065037_add_state_to_posts.rb │ ├── 20151209065652_allow_skipping_number_on_posts.rb │ ├── 20151209222143_add_state_to_comments.rb │ ├── 20151209234741_create_post_images.rb │ ├── 20151209235804_add_attachment_to_post_images.rb │ ├── 20151211200152_rename_base64_columns.rb │ ├── 20151212172654_create_comment_images.rb │ ├── 20151212172744_add_attachment_to_comment_images.rb │ ├── 20151227182138_create_team_projects.rb │ ├── 20160115233549_rename_members_to_slugged_routes.rb │ ├── 20160115233646_rename_model_in_slugged_routes_to_owner.rb │ ├── 20160116192724_drop_team_project.rb │ ├── 20160116192734_drop_team.rb │ ├── 20160116192810_drop_contributor.rb │ ├── 20160116193005_drop_team_membership.rb │ ├── 20160116200428_remove_contributors_count_from_projects.rb │ ├── 20160116201731_change_default_for_organization_memberships_to_pending.rb │ ├── 20160116232700_add_organization_to_projects.rb │ ├── 20160116232718_remove_owner_from_projects.rb │ ├── 20160119181706_add_name_to_users.rb │ ├── 20160119230937_add_comments_count_to_post.rb │ ├── 20160204223535_add_icon_columns_to_organizations.rb │ ├── 20160204223727_add_icon_data_to_organizations.rb │ ├── 20160209170316_add_body_preview_markdown_preview_to_posts.rb │ ├── 20160210140342_add_body_preview_markdown_preview_to_comments.rb │ ├── 20160212102442_allow_null_on_post_title.rb │ ├── 20160215223422_add_description_to_organizations.rb │ ├── 20160225201529_add_status_to_user_mentions.rb │ ├── 20160517230704_rename_skill_category_to_role.rb │ ├── 20160517231457_add_name_and_ability_to_roles.rb │ ├── 20160518050009_change_skills_to_reference_roles.rb │ ├── 20160518205433_create_role_skills.rb │ ├── 20160518210630_remove_role_id_from_skills.rb │ ├── 20160518211037_create_user_roles.rb │ ├── 20160519061004_create_categories.rb │ ├── 20160519181120_create_project_categories.rb │ ├── 20160520010146_add_description_to_categories.rb │ ├── 20160520040950_add_indexes_and_foreign_keys_to_project_categories.rb │ ├── 20160520222346_create_project_roles.rb │ ├── 20160520231546_create_project_skills.rb │ ├── 20160520235218_create_user_categories.rb │ ├── 20160602211946_add_state_to_users.rb │ ├── 20160609202045_add_kind_to_roles.rb │ ├── 20160621003651_create_previews.rb │ ├── 20160621003916_create_preview_user_mentions.rb │ ├── 20160621024455_remove_preview_fields_from_posts.rb │ ├── 20160621024928_remove_preview_fields_from_comments.rb │ ├── 20160621031228_remove_status_from_user_mentions.rb │ ├── 20160621203648_add_long_description_to_projects.rb │ ├── 20160623044025_add_open_and_closed_posts_count_to_projects.rb │ ├── 20160624065209_create_imports.rb │ ├── 20160625224912_add_code_theme_to_users.rb │ ├── 20160626043812_add_mapping_to_skills_and_roles.rb │ ├── 20160626075820_add_slug_to_skills.rb │ ├── 20160626090623_create_import_skill_failures.rb │ ├── 20160705042501_split_names.rb │ ├── 20160705185815_add_url_protocol_to_user_websites.rb │ └── 20160911211503_migrate_images_and_slugged_routes_for_phoenix.rb ├── schema.rb └── seeds.rb ├── docker-compose.yml ├── docs ├── API.md ├── INSTALLING.md ├── SQUASHING.md └── USAGE.md ├── lib ├── assets │ └── .keep ├── code_corps │ ├── adapters │ │ └── mailing_list.rb │ ├── base64_image_decoder.rb │ ├── base64_image_matcher.rb │ ├── github_repository_url_parser.rb │ ├── scenario │ │ ├── generate_notifications_for_comment_user_mentions.rb │ │ ├── generate_notifications_for_post_user_mentions.rb │ │ ├── generate_preview_mentions.rb │ │ ├── generate_user_mentions_for_comment.rb │ │ ├── generate_user_mentions_for_post.rb │ │ ├── notify_pusher_of_comment_image.rb │ │ ├── notify_pusher_of_post_image.rb │ │ └── send_notification_emails.rb │ └── slug_matcher.rb └── tasks │ ├── .keep │ ├── db_exists.rake │ └── subscribe_users_to_mailing_list.rake ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico └── robots.txt └── spec ├── factories ├── category_factory.rb ├── comment_factory.rb ├── comment_image_factory.rb ├── comment_user_mention_factory.rb ├── github_repository_factory.rb ├── import_factory.rb ├── import_skill_failure_factory.rb ├── notification_factory.rb ├── oauth_application_factory.rb ├── oauth_token_factory.rb ├── organization_factory.rb ├── organization_membership_factory.rb ├── post_factory.rb ├── post_image_factory.rb ├── post_like_factory.rb ├── post_user_mention_factory.rb ├── preview_factory.rb ├── preview_user_mention.rb ├── project_category_factory.rb ├── project_factory.rb ├── project_role.rb ├── project_skill_factory.rb ├── role_factory.rb ├── role_skill_factory.rb ├── skill_factory.rb ├── user_category_factory.rb ├── user_factory.rb ├── user_relationship_factory.rb ├── user_role_factory.rb └── user_skill_factory.rb ├── lib └── code_corps │ ├── adapters │ └── mailing_list_spec.rb │ ├── base64_image_decoder_spec.rb │ ├── base64_image_matcher_spec.rb │ ├── scenario │ ├── generate_notifications_for_comment_user_mentions_spec.rb │ ├── generate_notifications_for_post_user_mentions_spec.rb │ ├── generate_preview_mentions_spec.rb │ ├── generate_user_mentions_for_comment_spec.rb │ ├── generate_user_mentions_for_post_spec.rb │ ├── notify_pusher_of_comment_image_spec.rb │ ├── notify_pusher_of_post_image_spec.rb │ └── send_notification_emails_spec.rb │ └── slug_matcher_spec.rb ├── mailers └── notification_mailer_spec.rb ├── models ├── category_spec.rb ├── comment_image_spec.rb ├── comment_spec.rb ├── comment_user_mention_spec.rb ├── github_repository_spec.rb ├── import_skill_failure_spec.rb ├── import_spec.rb ├── notification_spec.rb ├── organization_membership_spec.rb ├── organization_spec.rb ├── post_image_spec.rb ├── post_like_spec.rb ├── post_spec.rb ├── post_user_mention_spec.rb ├── preview_spec.rb ├── preview_user_mention_spec.rb ├── project_category_spec.rb ├── project_role_spec.rb ├── project_skill_spec.rb ├── project_spec.rb ├── role_skill_spec.rb ├── role_spec.rb ├── skill_spec.rb ├── slugged_route_spec.rb ├── user_category_spec.rb ├── user_relationship_spec.rb ├── user_role_spec.rb ├── user_skill_spec.rb └── user_spec.rb ├── policies ├── category_policy_spec.rb ├── comment_image_policy_spec.rb ├── comment_policy_spec.rb ├── comment_user_mention_policy_spec.rb ├── github_repository_policy_spec.rb ├── import_policy_spec.rb ├── import_skill_failure_policy_spec.rb ├── organization_membership_policy_spec.rb ├── organization_policy_spec.rb ├── post_policy_spec.rb ├── post_user_mention_policy_spec.rb ├── preview_user_mention_policy_spec.rb ├── project_category_policy_spec.rb ├── project_policy_spec.rb ├── project_role_policy_spec.rb ├── project_skill_policy_spec.rb ├── role_policy_spec.rb ├── role_skill_policy_spec.rb ├── skill_policy_spec.rb ├── slugged_route_policy_spec.rb ├── user_category_policy_spec.rb ├── user_policy_spec.rb ├── user_role_policy_spec.rb └── user_skill_policy_spec.rb ├── rails_helper.rb ├── requests └── api │ ├── categories_spec.rb │ ├── comment_images_spec.rb │ ├── comment_user_mentions_spec.rb │ ├── comments_spec.rb │ ├── ember_index_spec.rb │ ├── github_repositories_spec.rb │ ├── import_skill_failures_spec.rb │ ├── imports_spec.rb │ ├── oauth_applications_spec.rb │ ├── organization_memberships_spec.rb │ ├── organizations_spec.rb │ ├── ping_spec.rb │ ├── post_images_spec.rb │ ├── post_likes_spec.rb │ ├── post_user_mentions_spec.rb │ ├── posts_spec.rb │ ├── preview_user_mentions_spec.rb │ ├── previews_spec.rb │ ├── project_categories_spec.rb │ ├── project_roles_spec.rb │ ├── project_skills_spec.rb │ ├── projects_spec.rb │ ├── role_skills_spec.rb │ ├── roles_spec.rb │ ├── skills_spec.rb │ ├── slugged_routes_spec.rb │ ├── tokens_spec.rb │ ├── user_categories_spec.rb │ ├── user_roles_spec.rb │ ├── user_skills_spec.rb │ └── users_spec.rb ├── sample_data ├── base64_images │ ├── gif.txt │ ├── jpeg.txt │ ├── jpeg_without_data_string.txt │ └── png.txt ├── default-avatar.png └── import.csv ├── serializers ├── category_serializer_spec.rb ├── comment_image_serializer_spec.rb ├── comment_serializer_spec.rb ├── comment_user_mention_serializer_spec.rb ├── error_serializer_spec.rb ├── github_repository_serializer_spec.rb ├── import_serializer_spec.rb ├── import_skill_failure_serializer_spec.rb ├── organization_serializer_spec.rb ├── post_image_serializer_spec.rb ├── post_like_serializer_spec.rb ├── post_serializer_spec.rb ├── post_serializer_without_includes_spec.rb ├── post_user_mention_serializer_spec.rb ├── project_category_serializer_spec.rb ├── project_role_serializer_spec.rb ├── project_serializer_spec.rb ├── project_serializer_without_includes_spec.rb ├── project_skill_serializer_spec.rb ├── role_serializer_spec.rb ├── role_serializer_without_includes_spec.rb ├── role_skill_serializer_spec.rb ├── skill_serializer_spec.rb ├── slugged_route_serializer_spec.rb ├── user_category_serializer_spec.rb ├── user_role_serializer_spec.rb ├── user_serializer_spec.rb ├── user_serializer_without_includes_spec.rb └── user_skill_serializer_spec.rb ├── spec_helper.rb ├── support ├── aws.rb ├── helpers │ ├── api_helpers.rb │ ├── json_api_helpers.rb │ └── request_helpers.rb ├── matchers │ ├── cors_matchers.rb │ ├── error_format_matchers.rb │ ├── serializer_matchers.rb │ └── time_matchers.rb ├── shared_examples │ └── slug.rb └── vcr.rb ├── validators ├── base64_photo_data_validator_spec.rb └── slug_validator_spec.rb ├── vcr ├── lib │ └── code_corps │ │ └── scenario │ │ └── notify_pusher_of_post_image.yml ├── models │ ├── comment_image │ │ ├── aws-upload.yml │ │ └── validation.yml │ ├── organization │ │ └── validation.yml │ ├── post_image │ │ ├── aws-upload.yml │ │ └── validation.yml │ ├── project │ │ └── validation.yml │ └── user │ │ └── validation.yml ├── requests │ └── api │ │ ├── tokens │ │ ├── facebook_user_found.yml │ │ └── facebook_user_not_found.yml │ │ └── users │ │ └── valid_facebook_request.yml └── workers │ ├── add_facebook_friends │ └── adds_friends_from_facebook.yml │ ├── add_facebook_profile_picture_worker │ └── adds_a_profile_picture_from_facebook.yml │ └── add_gravatar_image_worker │ ├── adds_the_gravatar.yml │ └── does_not_add_the_gravatar.yml └── workers ├── add_facebook_friends_worker_spec.rb ├── add_facebook_profile_picture_worker_spec.rb ├── add_organization_icon_worker_spec.rb ├── add_profile_picture_from_gravatar_worker_spec.rb ├── add_project_icon_worker_spec.rb ├── generate_comment_user_notifications_worker_spec.rb ├── generate_post_user_notifications_worker_spec.rb ├── notify_pusher_of_comment_image_worker_spec.rb ├── notify_pusher_of_post_image_worker_spec.rb ├── perform_import_worker_spec.rb ├── subscribe_to_mailing_list_worker_spec.rb └── update_profile_picture_worker_spec.rb /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.apib] 12 | indent_size = 4 13 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | AWS_ACCESS_KEY_ID= 2 | AWS_SECRET_ACCESS_KEY= 3 | CLOUDFRONT_DOMAIN= 4 | FACEBOOK_APP_ID= 5 | FACEBOOK_APP_SECRET= 6 | FACEBOOK_REDIRECT_URL=http://localhost:3000/ 7 | MAILCHIMP_API_KEY= 8 | MAILCHIMP_LIST_ID= 9 | PUSHER_APP_ID= 10 | PUSHER_FAKE=true 11 | PUSHER_KEY= 12 | PUSHER_SECRET= 13 | S3_BUCKET_NAME= 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | !/log/.keep 17 | /tmp 18 | 19 | # .env, local environment variables for use with foreman 20 | .env 21 | 22 | # ignore the Ruby Version manager (rvm) 23 | .rvmrc 24 | .ruby-gemset 25 | .rbenv 26 | bundler_stubs/* 27 | 28 | vendor/bundle/* 29 | 30 | .DS_Store 31 | 32 | dump.rdb 33 | 34 | coverage 35 | 36 | /imports 37 | /organizations 38 | /projects 39 | /users 40 | 41 | # Ignore vagrant VMs 42 | .vagrant/* 43 | 44 | # Ignore generated API Blueprint 45 | /blueprint/index.html 46 | -------------------------------------------------------------------------------- /.hound.yml: -------------------------------------------------------------------------------- 1 | ruby: 2 | config_file: .rubocop.yml 3 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --tty 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .hound_defaults.yml 2 | 3 | Documentation: 4 | Enabled: false 5 | Style/StringLiterals: 6 | EnforcedStyle: double_quotes 7 | Style/IndentationConsistency: 8 | EnforcedStyle: rails 9 | Metrics/LineLength: 10 | Max: 100 11 | Metrics/CyclomaticComplexity: 12 | Max: 12 13 | Metrics/PerceivedComplexity: 14 | Max: 12 15 | Metrics/AbcSize: 16 | Max: 20 17 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.2.5 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.2.5 2 | 3 | RUN gem update --system 2.6.1 4 | RUN gem install bundler --version $BUNDLER_VERSION 5 | 6 | RUN apt-get update -qq && apt-get install -y build-essential 7 | 8 | # ImageMagick 9 | RUN apt-get install -y imagemagick 10 | 11 | # PostgreSQL 12 | RUN apt-get install -y libpq-dev 13 | 14 | # Node.js runtime 15 | RUN apt-get install -y nodejs 16 | 17 | # Set directory for our app 18 | ENV APP_HOME /code-corps-api 19 | RUN mkdir $APP_HOME 20 | 21 | # Copy Gemfile and bundle 22 | WORKDIR $APP_HOME 23 | COPY Gemfile $APP_HOME/Gemfile 24 | COPY Gemfile.lock $APP_HOME/Gemfile.lock 25 | RUN bundle install 26 | 27 | # Copy code 28 | ADD . $APP_HOME 29 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2016 Code Corps PBC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec puma -C config/puma.rb 2 | worker: bundle exec sidekiq 3 | -------------------------------------------------------------------------------- /Procfile.dev: -------------------------------------------------------------------------------- 1 | web: bundle exec puma -C config/puma.rb 2 | worker: bundle exec sidekiq -q high -q default -q low 3 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/app/assets/images/.keep -------------------------------------------------------------------------------- /app/controllers/categories_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: categories 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # slug :string not null 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # description :text 11 | # 12 | 13 | class CategoriesController < ApplicationController 14 | before_action :doorkeeper_authorize!, only: [:create] 15 | 16 | def index 17 | authorize Category 18 | render json: Category.all 19 | end 20 | 21 | def show 22 | category = Category.find(params[:id]) 23 | 24 | authorize category 25 | 26 | render json: category 27 | end 28 | 29 | def create 30 | category = Category.new(permitted_params) 31 | 32 | authorize category 33 | 34 | if category.save 35 | render json: category 36 | else 37 | render_validation_errors category.errors 38 | end 39 | end 40 | 41 | private 42 | 43 | def permitted_params 44 | record_attributes.permit(:name, :description) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /app/controllers/comment_user_mentions_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # post_id :integer not null 9 | # username :string not null 10 | # start_index :integer not null 11 | # end_index :integer not null 12 | # created_at :datetime not null 13 | # updated_at :datetime not null 14 | # 15 | 16 | class CommentUserMentionsController < ApplicationController 17 | def index 18 | authorize CommentUserMention 19 | mentions = CommentUserMention.includes(:user, :comment).where(filter_params) 20 | render json: mentions 21 | end 22 | 23 | private 24 | 25 | def filter_params 26 | { 27 | comment_id: params[:comment_id] 28 | } 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/import_skill_failures_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: import_skill_failures 4 | # 5 | # id :integer not null, primary key 6 | # import_id :integer not null 7 | # skill_id :integer 8 | # data :json not null 9 | # issues :text not null, is an Array 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | class ImportSkillFailuresController < ApplicationController 15 | before_action :doorkeeper_authorize! 16 | 17 | def index 18 | authorize ImportSkillFailure 19 | render json: ImportSkillFailure.includes(:import, :skill).all 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/controllers/imports_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: imports 4 | # 5 | # id :integer not null, primary key 6 | # file_file_name :string 7 | # file_content_type :string 8 | # file_file_size :integer 9 | # file_updated_at :datetime 10 | # status :integer default(0) 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class ImportsController < ApplicationController 16 | before_action :doorkeeper_authorize! 17 | 18 | def create 19 | import = Import.new(import_params) 20 | 21 | authorize import 22 | 23 | if import.save 24 | render json: import 25 | else 26 | render_validation_errors import.errors 27 | end 28 | end 29 | 30 | private 31 | 32 | def import_params 33 | params.require(:import).permit(:file) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/controllers/ping_controller.rb: -------------------------------------------------------------------------------- 1 | class PingController < ApplicationController 2 | 3 | def index 4 | if signed_in? 5 | json = {"ping" => current_user.email} 6 | else 7 | json = {"ping" => "pong"} 8 | end 9 | render json: json 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /app/controllers/post_likes_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_likes 4 | # 5 | # id :integer not null, primary key 6 | # post_id :integer 7 | # user_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class PostLikesController < ApplicationController 13 | before_action :doorkeeper_authorize! 14 | 15 | def create 16 | authorize PostLike 17 | 18 | post_like = PostLike.new(create_params) 19 | 20 | if post_like.valid? 21 | post_like.save! 22 | render json: post_like, include: [:user, :post] 23 | else 24 | render_validation_errors post_like.errors 25 | end 26 | end 27 | 28 | def destroy 29 | post_like = PostLike.find(params[:id]) 30 | 31 | authorize post_like 32 | 33 | post_like.destroy! 34 | 35 | render json: :nothing, status: :no_content 36 | end 37 | 38 | private 39 | 40 | def create_params 41 | params_for_user( 42 | parse_params(params, only: [:post]) 43 | ) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /app/controllers/post_user_mentions_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PostUserMentionsController < ApplicationController 16 | def index 17 | authorize PostUserMention 18 | mentions = PostUserMention.includes(:user, :post).where(filter_params) 19 | render json: mentions 20 | end 21 | 22 | private 23 | 24 | def filter_params 25 | { 26 | post_id: params[:post_id] 27 | } 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /app/controllers/preview_user_mentions_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: preview_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # preview_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PreviewUserMentionsController < ApplicationController 16 | def index 17 | authorize PreviewUserMention 18 | mentions = PreviewUserMention.includes(:user, :preview).where(filter_params) 19 | render json: mentions 20 | end 21 | 22 | private 23 | 24 | def filter_params 25 | { preview_id: params[:preview_id] } 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /app/controllers/previews_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: previews 4 | # 5 | # id :integer not null, primary key 6 | # body :text not null 7 | # markdown :text not null 8 | # user_id :integer 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class PreviewsController < ApplicationController 14 | before_action :doorkeeper_authorize!, only: [:create] 15 | 16 | def create 17 | preview = Preview.new(create_params) 18 | 19 | if preview.save 20 | render json: preview 21 | else 22 | render_validation_errors preview.errors 23 | end 24 | end 25 | 26 | private 27 | 28 | def create_params 29 | params_for_user(permitted_params) 30 | end 31 | 32 | def permitted_params 33 | parse_params(params, only: [:markdown]) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/controllers/project_roles_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_roles 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectRolesController < ApplicationController 13 | before_action :doorkeeper_authorize! 14 | before_action :require_params, only: [:create] 15 | 16 | def create 17 | project_role = ProjectRole.new(create_params) 18 | 19 | if project_role.valid? 20 | authorize project_role 21 | project_role.save! 22 | render json: project_role, include: [:role, :project] 23 | else 24 | render_validation_errors project_role.errors 25 | end 26 | end 27 | 28 | def destroy 29 | project_role = ProjectRole.find(params[:id]) 30 | 31 | authorize project_role 32 | 33 | project_role.destroy! 34 | 35 | render json: :nothing, status: :no_content 36 | end 37 | 38 | private 39 | 40 | def require_params 41 | require_param :role_id 42 | require_param :project_id 43 | end 44 | 45 | def create_params 46 | parse_params(params) 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /app/controllers/project_skills_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_skills 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectSkillsController < ApplicationController 13 | before_action :doorkeeper_authorize! 14 | before_action :require_params, only: [:create] 15 | 16 | def create 17 | project_skill = ProjectSkill.new(create_params) 18 | 19 | if project_skill.valid? 20 | authorize project_skill 21 | project_skill.save! 22 | render json: project_skill, include: [:skill, :project] 23 | else 24 | render_validation_errors project_skill.errors 25 | end 26 | end 27 | 28 | def destroy 29 | project_skill = ProjectSkill.find(params[:id]) 30 | 31 | authorize project_skill 32 | 33 | project_skill.destroy! 34 | 35 | render json: :nothing, status: :no_content 36 | end 37 | 38 | private 39 | 40 | def require_params 41 | require_param :skill_id 42 | require_param :project_id 43 | end 44 | 45 | def create_params 46 | parse_params(params) 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /app/controllers/role_skills_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: role_skills 4 | # 5 | # id :integer not null, primary key 6 | # role_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # cat :integer 11 | # 12 | 13 | class RoleSkillsController < ApplicationController 14 | before_action :doorkeeper_authorize! 15 | 16 | def create 17 | role_skill = RoleSkill.new(create_params) 18 | 19 | authorize role_skill 20 | 21 | if role_skill.valid? 22 | role_skill.save! 23 | render json: role_skill, include: [:role, :skill] 24 | else 25 | render_validation_errors role_skill.errors 26 | end 27 | end 28 | 29 | private 30 | 31 | def create_params 32 | parse_params(params, only: [:role, :skill]) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /app/controllers/roles_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: roles 4 | # 5 | # id :integer not null, primary key 6 | # created_at :datetime not null 7 | # updated_at :datetime not null 8 | # name :string not null 9 | # ability :string not null 10 | # kind :string not null 11 | # 12 | 13 | class RolesController < ApplicationController 14 | before_action :doorkeeper_authorize!, only: [:create] 15 | 16 | def index 17 | authorize Role 18 | render json: Role.all 19 | end 20 | 21 | def create 22 | role = Role.new(permitted_params) 23 | 24 | authorize role 25 | 26 | if role.save 27 | render json: role 28 | else 29 | render_validation_errors role.errors 30 | end 31 | end 32 | 33 | private 34 | 35 | def permitted_params 36 | parse_params(params, only: [:name, :ability, :kind]) 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /app/controllers/slugged_routes_controller.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: slugged_routes 4 | # 5 | # id :integer not null, primary key 6 | # slug :string not null 7 | # owner_id :integer 8 | # owner_type :string 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class SluggedRoutesController < ApplicationController 14 | def show 15 | slugged_route = SluggedRoute.where("lower(slug) = ?", downcased_slug).first! 16 | 17 | authorize slugged_route 18 | 19 | render json: slugged_route 20 | end 21 | 22 | private 23 | 24 | def downcased_slug 25 | slug.downcase 26 | end 27 | 28 | def slug 29 | params[:id] 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/app/mailers/.keep -------------------------------------------------------------------------------- /app/mailers/notification_mailer.rb: -------------------------------------------------------------------------------- 1 | class NotificationMailer < ActionMailer::Base 2 | default from: "notifications@example.com" 3 | 4 | def notify(notification) 5 | @user = notification.user 6 | @notifiable = notification.notifiable 7 | @author = @notifiable.user 8 | @type = @notifiable.class.to_s.downcase 9 | 10 | mail to: to_address, subject: subject 11 | end 12 | 13 | private 14 | 15 | def to_address 16 | @user.email 17 | end 18 | 19 | def subject 20 | "You have been mentioned in a #{@type}" 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/mailers/passwords_mailer.rb: -------------------------------------------------------------------------------- 1 | class PasswordsMailer < ActionMailer::Base 2 | def change_password(user) 3 | @user = user 4 | mail from: "team@codecorps.org", to: @user.email, 5 | subject: "Code Corps Reset Password" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/app/models/.keep -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/category.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: categories 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # slug :string not null 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # description :text 11 | # 12 | 13 | class Category < ApplicationRecord 14 | has_many :project_categories 15 | has_many :projects, through: :project_categories 16 | 17 | before_validation :add_slug_if_blank 18 | 19 | validates :name, presence: true 20 | validates :slug, presence: true, 21 | slug: true, 22 | uniqueness: { case_sensitive: false } 23 | 24 | private 25 | 26 | def add_slug_if_blank 27 | self.slug = name.try(:parameterize) unless slug.present? 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /app/models/comment_user_mention.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # post_id :integer not null 9 | # username :string not null 10 | # start_index :integer not null 11 | # end_index :integer not null 12 | # created_at :datetime not null 13 | # updated_at :datetime not null 14 | # 15 | 16 | class CommentUserMention < ApplicationRecord 17 | belongs_to :user 18 | belongs_to :comment 19 | belongs_to :post 20 | 21 | validates_presence_of :user 22 | validates_presence_of :comment 23 | validates_presence_of :post 24 | validates_presence_of :username 25 | validates_presence_of :start_index 26 | validates_presence_of :end_index 27 | 28 | before_validation :add_username_from_user 29 | 30 | def indices 31 | [start_index, end_index] 32 | end 33 | 34 | private 35 | 36 | def add_username_from_user 37 | self.username = user.username if user.present? 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/github_repository.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: github_repositories 4 | # 5 | # id :integer not null, primary key 6 | # repository_name :string not null 7 | # owner_name :string not null 8 | # project_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class GithubRepository < ApplicationRecord 14 | belongs_to :project 15 | 16 | validates_presence_of :project 17 | validates_presence_of :repository_name 18 | validates_presence_of :owner_name 19 | end 20 | -------------------------------------------------------------------------------- /app/models/import.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: imports 4 | # 5 | # id :integer not null, primary key 6 | # file_file_name :string 7 | # file_content_type :string 8 | # file_file_size :integer 9 | # file_updated_at :datetime 10 | # status :integer default(0) 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class Import < ApplicationRecord 16 | has_attached_file :file, 17 | path: "imports/:id/:style.:extension" 18 | 19 | validates_attachment_file_name :file, matches: [/\.csv\Z/] 20 | validates_attachment_content_type :file, content_type: %r{^text\/(csv|plain)} 21 | 22 | enum status: [:unprocessed, :processed, :failed] 23 | 24 | after_create :perform! 25 | 26 | private 27 | 28 | def perform! 29 | PerformImportWorker.perform_async(id) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /app/models/import_skill_failure.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: import_skill_failures 4 | # 5 | # id :integer not null, primary key 6 | # import_id :integer not null 7 | # skill_id :integer 8 | # data :json not null 9 | # issues :text not null, is an Array 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | class ImportSkillFailure < ApplicationRecord 15 | belongs_to :import 16 | belongs_to :skill 17 | 18 | validates :import, presence: true 19 | validates :issues, presence: true 20 | validates :data, presence: true 21 | end 22 | -------------------------------------------------------------------------------- /app/models/notification.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: notifications 4 | # 5 | # id :integer not null, primary key 6 | # notifiable_id :integer not null 7 | # notifiable_type :string not null 8 | # user_id :integer not null 9 | # aasm_state :string 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | class Notification < ApplicationRecord 15 | include AASM 16 | 17 | belongs_to :notifiable, polymorphic: true 18 | belongs_to :user 19 | 20 | validates_presence_of :notifiable 21 | validates_presence_of :user 22 | validates_uniqueness_of :user_id, scope: :notifiable 23 | 24 | aasm do 25 | state :pending, initial: true 26 | state :sent 27 | state :read 28 | 29 | event :dispatch do 30 | transitions from: :pending, to: :sent 31 | end 32 | 33 | event :mark_as_read do 34 | transitions from: [:pending, :sent], to: :read 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /app/models/post_like.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_likes 4 | # 5 | # id :integer not null, primary key 6 | # post_id :integer 7 | # user_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class PostLike < ApplicationRecord 13 | belongs_to :user 14 | belongs_to :post, counter_cache: true 15 | 16 | validates_presence_of :user 17 | validates_presence_of :post 18 | validates_uniqueness_of :post_id, scope: :user_id 19 | end 20 | 21 | -------------------------------------------------------------------------------- /app/models/post_user_mention.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PostUserMention < ApplicationRecord 16 | belongs_to :user 17 | belongs_to :post 18 | 19 | validates_presence_of :user 20 | validates_presence_of :post 21 | validates_presence_of :username 22 | validates_presence_of :start_index 23 | validates_presence_of :end_index 24 | 25 | before_validation :add_username_from_user 26 | 27 | def indices 28 | [start_index, end_index] 29 | end 30 | 31 | private 32 | 33 | def add_username_from_user 34 | self.username = user.username if user.present? 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/models/preview.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: previews 4 | # 5 | # id :integer not null, primary key 6 | # body :text not null 7 | # markdown :text not null 8 | # user_id :integer 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | require "html/pipeline" 14 | require "html/pipeline/rouge_filter" 15 | require "code_corps/scenario/generate_preview_mentions" 16 | 17 | class Preview < ApplicationRecord 18 | belongs_to :user 19 | 20 | has_many :preview_user_mentions 21 | 22 | validates :body, presence: true 23 | validates :markdown, presence: true 24 | validates :user, presence: true 25 | 26 | before_validation :render_markdown_to_body 27 | 28 | after_save :generate_mentions 29 | 30 | private 31 | 32 | def generate_mentions 33 | CodeCorps::Scenario::GeneratePreviewMentions.new(self).call 34 | end 35 | 36 | def pipeline 37 | @pipeline ||= HTML::Pipeline.new [ 38 | HTML::Pipeline::MarkdownFilter, 39 | HTML::Pipeline::RougeFilter 40 | ], gfm: true # Github-flavored markdown 41 | end 42 | 43 | def render_markdown_to_body 44 | html = pipeline.call(markdown) 45 | self.body = html[:output].to_s 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /app/models/preview_user_mention.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: preview_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # preview_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PreviewUserMention < ApplicationRecord 16 | belongs_to :preview 17 | belongs_to :user 18 | 19 | before_validation :add_username_from_user 20 | 21 | validates :end_index, presence: true 22 | validates :preview, presence: true 23 | validates :start_index, presence: true 24 | validates :user, presence: true 25 | validates :username, presence: true 26 | 27 | def indices 28 | [start_index, end_index] 29 | end 30 | 31 | private 32 | 33 | def add_username_from_user 34 | self.username = user.username if user.present? 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/models/project_category.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_categories 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectCategory < ApplicationRecord 13 | belongs_to :project 14 | belongs_to :category 15 | 16 | validates :project_id, uniqueness: { scope: :category_id } 17 | validates :project, presence: true 18 | validates :category, presence: true 19 | end 20 | -------------------------------------------------------------------------------- /app/models/project_role.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_roles 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectRole < ApplicationRecord 13 | belongs_to :project 14 | belongs_to :role 15 | 16 | validates :project_id, uniqueness: { scope: :role_id } 17 | validates :project, presence: true 18 | validates :role, presence: true 19 | end 20 | -------------------------------------------------------------------------------- /app/models/project_skill.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_skills 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectSkill < ApplicationRecord 13 | belongs_to :project 14 | belongs_to :skill 15 | 16 | validates :project_id, uniqueness: { scope: :skill_id } 17 | validates :project, presence: true 18 | validates :skill, presence: true 19 | end 20 | -------------------------------------------------------------------------------- /app/models/role.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: roles 4 | # 5 | # id :integer not null, primary key 6 | # created_at :datetime not null 7 | # updated_at :datetime not null 8 | # name :string not null 9 | # ability :string not null 10 | # kind :string not null 11 | # 12 | 13 | class Role < ApplicationRecord 14 | has_many :role_skills 15 | has_many :skills, through: :role_skills 16 | 17 | validates_presence_of :name 18 | validates_presence_of :ability 19 | validates_presence_of :kind 20 | 21 | enum kind: { 22 | technology: "technology", 23 | creative: "creative", 24 | support: "support" 25 | } 26 | end 27 | -------------------------------------------------------------------------------- /app/models/role_skill.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: role_skills 4 | # 5 | # id :integer not null, primary key 6 | # role_id :integer 7 | # skill_id :integer 8 | # cat :integer 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class RoleSkill < ApplicationRecord 14 | belongs_to :role 15 | belongs_to :skill 16 | 17 | validates_presence_of :role 18 | validates_presence_of :skill 19 | validates_uniqueness_of :role_id, scope: :skill_id 20 | 21 | enum cat: [:cat1, :cat2, :cat3, :cat4, :cat5, :cat6] 22 | end 23 | -------------------------------------------------------------------------------- /app/models/skill.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: skills 4 | # 5 | # id :integer not null, primary key 6 | # title :string not null 7 | # description :string 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # original_row :integer 11 | # slug :string not null 12 | # 13 | 14 | class Skill < ApplicationRecord 15 | searchkick match: :word_start, searchable: [:title] 16 | 17 | has_many :role_skills 18 | has_many :roles, through: :role_skills 19 | 20 | validates_presence_of :title 21 | 22 | before_validation :update_slug 23 | 24 | validates :slug, presence: true 25 | validates :slug, obscenity: { message: "may not be obscene" } 26 | validates :slug, exclusion: { in: Rails.configuration.x.reserved_routes } 27 | validates :slug, slug: true 28 | validates :slug, uniqueness: { case_sensitive: false } 29 | 30 | def self.autocomplete(query) 31 | results = search query 32 | results.take(5) 33 | end 34 | 35 | private 36 | 37 | def update_slug 38 | self.slug = title.try(:parameterize) if title_changed? 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /app/models/slugged_route.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: slugged_routes 4 | # 5 | # id :integer not null, primary key 6 | # slug :string not null 7 | # owner_id :integer 8 | # owner_type :string 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class SluggedRoute < ApplicationRecord 14 | belongs_to :owner, polymorphic: true 15 | 16 | validates_presence_of :slug 17 | validates_exclusion_of :slug, in: Rails.configuration.x.reserved_routes 18 | validates :slug, slug: true 19 | validates :slug, uniqueness: { case_sensitive: false } 20 | end 21 | -------------------------------------------------------------------------------- /app/models/user_category.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_categories 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserCategory < ApplicationRecord 13 | belongs_to :user 14 | belongs_to :category 15 | 16 | validates :user_id, uniqueness: { scope: :category_id } 17 | validates :user, presence: true 18 | validates :category, presence: true 19 | end 20 | -------------------------------------------------------------------------------- /app/models/user_relationship.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_relationships 4 | # 5 | # id :integer not null, primary key 6 | # follower_id :integer 7 | # following_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserRelationship < ApplicationRecord 13 | belongs_to :follower, class_name: "User" 14 | belongs_to :following, class_name: "User" 15 | 16 | validates_presence_of :follower 17 | validates_presence_of :following 18 | validates_uniqueness_of :follower_id, scope: :following_id 19 | end 20 | -------------------------------------------------------------------------------- /app/models/user_role.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_roles 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserRole < ApplicationRecord 13 | belongs_to :user 14 | belongs_to :role 15 | 16 | validates_presence_of :user 17 | validates_presence_of :role 18 | validates_uniqueness_of :user_id, scope: :role_id 19 | end 20 | -------------------------------------------------------------------------------- /app/models/user_skill.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_skills 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserSkill < ApplicationRecord 13 | belongs_to :user 14 | belongs_to :skill 15 | 16 | validates_presence_of :user 17 | validates_presence_of :skill 18 | validates_uniqueness_of :user_id, scope: :skill_id 19 | end 20 | -------------------------------------------------------------------------------- /app/policies/category_policy.rb: -------------------------------------------------------------------------------- 1 | class CategoryPolicy 2 | attr_reader :user, :category 3 | 4 | def initialize(user, category) 5 | @user = user 6 | @category = category 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user.admin? 20 | end 21 | 22 | def update? 23 | return unless user.present? 24 | user.admin? 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/policies/comment_image_policy.rb: -------------------------------------------------------------------------------- 1 | class CommentImagePolicy 2 | attr_reader :user, :comment_image 3 | 4 | def initialize(user, comment_image) 5 | @user = user 6 | @comment_image = comment_image 7 | end 8 | 9 | def create? 10 | # Cannot create if there's no user 11 | return false unless user.present? 12 | 13 | # Cannot create if they're not the same user 14 | return false unless comment.user_id == user.id 15 | 16 | # Can create comments for any user 17 | true 18 | end 19 | 20 | private 21 | 22 | def comment 23 | @comment ||= comment_image.comment 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/policies/comment_policy.rb: -------------------------------------------------------------------------------- 1 | class CommentPolicy 2 | attr_reader :user, :comment 3 | 4 | def initialize(user, comment) 5 | @user = user 6 | @comment = comment 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def post_index? 14 | true 15 | end 16 | 17 | def show? 18 | true 19 | end 20 | 21 | def create? 22 | user.present? 23 | end 24 | 25 | def update? 26 | return false if user.nil? 27 | return false if user != comment.user 28 | return true 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/policies/comment_user_mention_policy.rb: -------------------------------------------------------------------------------- 1 | class CommentUserMentionPolicy 2 | attr_reader :user, :comment_user_mention 3 | 4 | def initialize(user, comment_user_mention) 5 | @user = user 6 | @comment_user_mention = comment_user_mention 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/policies/github_repository_policy.rb: -------------------------------------------------------------------------------- 1 | class GithubRepositoryPolicy 2 | attr_reader :user, :github_repository 3 | 4 | def initialize(user, github_repository) 5 | @user = user 6 | @github_repository = github_repository 7 | end 8 | 9 | def create? 10 | return false unless @user.present? 11 | return true if current_user_is_at_least_admin_in_organization? 12 | end 13 | 14 | private 15 | 16 | def project 17 | @project ||= github_repository.project 18 | end 19 | 20 | def organization_member_for_user 21 | @organization_member_for_user ||= OrganizationMembership.find_by( 22 | member_id: user.id, organization_id: project.organization_id) 23 | end 24 | 25 | def current_user_is_at_least_admin_in_organization? 26 | return false unless organization_member_for_user 27 | return true if organization_member_for_user.admin? or organization_member_for_user.owner? 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /app/policies/import_policy.rb: -------------------------------------------------------------------------------- 1 | class ImportPolicy 2 | attr_reader :user, :import 3 | 4 | def initialize(user, import) 5 | @user = user 6 | @import = import 7 | end 8 | 9 | def create? 10 | # Cannot create if there's no user 11 | return false unless user.present? 12 | 13 | # Cannot create if they're not an admin. 14 | return false unless user.admin? 15 | 16 | # Can create import. 17 | true 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/policies/import_skill_failure_policy.rb: -------------------------------------------------------------------------------- 1 | class ImportSkillFailurePolicy 2 | attr_reader :user, :import_skill_failure 3 | 4 | def initialize(user, import_skill_failure) 5 | @user = user 6 | @import = import_skill_failure 7 | end 8 | 9 | def index? 10 | return true if user.admin? 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/policies/organization_policy.rb: -------------------------------------------------------------------------------- 1 | class OrganizationPolicy 2 | attr_reader :organization, :user 3 | 4 | def initialize(user, organization) 5 | @user = user 6 | @organization = organization 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless @user.present? 19 | user.admin? 20 | end 21 | 22 | def update? 23 | return unless @user.present? 24 | return true if current_user_is_at_least_admin_in_organization? 25 | end 26 | 27 | private 28 | 29 | def organization_member_for_user 30 | @organization_member_for_user ||= 31 | OrganizationMembership.find_by(member: user, organization: organization) 32 | end 33 | 34 | def current_user_is_at_least_admin_in_organization? 35 | return false unless organization_member_for_user 36 | return true if organization_member_for_user.admin? || organization_member_for_user.owner? 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /app/policies/post_image_policy.rb: -------------------------------------------------------------------------------- 1 | class PostImagePolicy 2 | attr_reader :user, :post_image 3 | 4 | def initialize(user, post_image) 5 | @user = user 6 | @post_image = post_image 7 | end 8 | 9 | def create? 10 | return false unless user.present? 11 | return false unless post.user_id == user.id 12 | return true 13 | end 14 | 15 | private 16 | def post 17 | @post ||= post_image.post 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/policies/post_like_policy.rb: -------------------------------------------------------------------------------- 1 | class PostLikePolicy 2 | attr_reader :user, :post_like 3 | 4 | def initialize(user, post_like) 5 | @user = user 6 | @post_like = post_like 7 | end 8 | 9 | def create? 10 | user.present? 11 | end 12 | 13 | def destroy? 14 | post_like.user_id == user.id 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/policies/post_user_mention_policy.rb: -------------------------------------------------------------------------------- 1 | class PostUserMentionPolicy 2 | attr_reader :user, :post_user_mention 3 | 4 | def initialize(user, post_user_mention) 5 | @user = user 6 | @post_user_mention = post_user_mention 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/policies/preview_user_mention_policy.rb: -------------------------------------------------------------------------------- 1 | class PreviewUserMentionPolicy 2 | attr_reader :user, :preview_user_mention 3 | 4 | def initialize(user, preview_user_mention) 5 | @user = user 6 | @preview_user_mention = preview_user_mention 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/policies/role_policy.rb: -------------------------------------------------------------------------------- 1 | class RolePolicy 2 | attr_reader :user, :role 3 | 4 | def initialize(user, role) 5 | @user = user 6 | @role = role 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def create? 14 | return unless user.present? 15 | user.admin? 16 | end 17 | 18 | def update? 19 | return unless user.present? 20 | user.admin? 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/policies/role_skill_policy.rb: -------------------------------------------------------------------------------- 1 | class RoleSkillPolicy 2 | attr_reader :user, :role_skill 3 | 4 | def initialize(user, role_skill) 5 | @user = user 6 | @role_skill = role_skill 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user.admin? 20 | end 21 | 22 | def destroy? 23 | return unless user.present? 24 | user.admin? 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/policies/skill_policy.rb: -------------------------------------------------------------------------------- 1 | class SkillPolicy 2 | attr_reader :user, :skill 3 | 4 | def initialize(user, skill) 5 | @user = user 6 | @skill = skill 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user.admin? 20 | end 21 | 22 | def update? 23 | return unless user.present? 24 | user.admin? 25 | end 26 | 27 | def search? 28 | true 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/policies/slugged_route_policy.rb: -------------------------------------------------------------------------------- 1 | class SluggedRoutePolicy 2 | def initialize (user, slugged_route) 3 | @user = user 4 | @slugged_route = slugged_route 5 | end 6 | 7 | def show? 8 | true 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/policies/user_category_policy.rb: -------------------------------------------------------------------------------- 1 | class UserCategoryPolicy 2 | attr_reader :user, :user_category 3 | 4 | def initialize(user, user_category) 5 | @user = user 6 | @user_category = user_category 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user_category.user_id == user.id 20 | end 21 | 22 | def destroy? 23 | return unless user.present? 24 | user_category.user_id == user.id 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/policies/user_policy.rb: -------------------------------------------------------------------------------- 1 | class UserPolicy 2 | attr_reader :current_user, :user 3 | 4 | def initialize(current_user, user) 5 | @current_user = current_user 6 | @user = user 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | true 19 | end 20 | 21 | def update? 22 | current_user == user || current_user.admin? 23 | end 24 | 25 | def forgot_password? 26 | true 27 | end 28 | 29 | def reset_password? 30 | true 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/policies/user_role_policy.rb: -------------------------------------------------------------------------------- 1 | class UserRolePolicy 2 | attr_reader :user, :user_role 3 | 4 | def initialize(user, user_role) 5 | @user = user 6 | @user_role = user_role 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user_role.user_id == user.id 20 | end 21 | 22 | def destroy? 23 | return unless user.present? 24 | user_role.user_id == user.id 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/policies/user_skill_policy.rb: -------------------------------------------------------------------------------- 1 | class UserSkillPolicy 2 | attr_reader :user, :user_skill 3 | 4 | def initialize(user, user_skill) 5 | @user = user 6 | @user_skill = user_skill 7 | end 8 | 9 | def index? 10 | true 11 | end 12 | 13 | def show? 14 | true 15 | end 16 | 17 | def create? 18 | return unless user.present? 19 | user_skill.user_id == user.id 20 | end 21 | 22 | def destroy? 23 | return unless user.present? 24 | user_skill.user_id == user.id 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/serializers/category_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: categories 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # slug :string not null 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # description :text 11 | # 12 | 13 | class CategorySerializer < ActiveModel::Serializer 14 | attributes :id, :name, :slug, :description 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/comment_image_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_images 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # filename :text not null 9 | # base64_photo_data :text not null 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # image_file_name :string 13 | # image_content_type :string 14 | # image_file_size :integer 15 | # image_updated_at :datetime 16 | # 17 | 18 | class CommentImageSerializer < ActiveModel::Serializer 19 | attributes :id, :filename 20 | 21 | belongs_to :user 22 | belongs_to :comment 23 | end 24 | -------------------------------------------------------------------------------- /app/serializers/comment_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comments 4 | # 5 | # id :integer not null, primary key 6 | # body :text 7 | # user_id :integer not null 8 | # post_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # markdown :text 12 | # aasm_state :string 13 | # 14 | 15 | class CommentSerializer < ActiveModel::Serializer 16 | attributes :id, :state, :body, :markdown, :edited_at, :created_at 17 | 18 | belongs_to :post 19 | belongs_to :user 20 | 21 | has_many :comment_user_mentions 22 | end 23 | -------------------------------------------------------------------------------- /app/serializers/comment_user_mention_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # post_id :integer not null 9 | # username :string not null 10 | # start_index :integer not null 11 | # end_index :integer not null 12 | # created_at :datetime not null 13 | # updated_at :datetime not null 14 | # 15 | 16 | class CommentUserMentionSerializer < ActiveModel::Serializer 17 | attributes :id, :indices, :username 18 | 19 | belongs_to :user 20 | belongs_to :comment, serializer: CommentSerializer 21 | end 22 | -------------------------------------------------------------------------------- /app/serializers/github_repository_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: github_repositories 4 | # 5 | # id :integer not null, primary key 6 | # repository_name :string not null 7 | # owner_name :string not null 8 | # project_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class GithubRepositorySerializer < ActiveModel::Serializer 14 | attributes :id, :owner_name, :repository_name 15 | 16 | belongs_to :project 17 | end 18 | -------------------------------------------------------------------------------- /app/serializers/import_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: imports 4 | # 5 | # id :integer not null, primary key 6 | # file_file_name :string 7 | # file_content_type :string 8 | # file_file_size :integer 9 | # file_updated_at :datetime 10 | # status :integer default(0) 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class ImportSerializer < ActiveModel::Serializer 16 | attributes :id, :file_name, :status 17 | 18 | def file_name 19 | @object.file_file_name 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/serializers/import_skill_failure_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: import_skill_failures 4 | # 5 | # id :integer not null, primary key 6 | # import_id :integer not null 7 | # skill_id :integer 8 | # data :json not null 9 | # issues :text not null, is an Array 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | class ImportSkillFailureSerializer < ActiveModel::Serializer 15 | attributes :id, :issues, :data 16 | 17 | belongs_to :skill 18 | belongs_to :import 19 | end 20 | -------------------------------------------------------------------------------- /app/serializers/organization_membership_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: organization_memberships 4 | # 5 | # id :integer not null, primary key 6 | # role :string default("pending"), not null 7 | # created_at :datetime not null 8 | # updated_at :datetime not null 9 | # member_id :integer 10 | # organization_id :integer 11 | # 12 | 13 | class OrganizationMembershipSerializer < ActiveModel::Serializer 14 | attributes :id, :role 15 | 16 | belongs_to :member 17 | belongs_to :organization 18 | end 19 | -------------------------------------------------------------------------------- /app/serializers/organization_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: organizations 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # created_at :datetime not null 8 | # updated_at :datetime not null 9 | # slug :string not null 10 | # icon_file_name :string 11 | # icon_content_type :string 12 | # icon_file_size :integer 13 | # icon_updated_at :datetime 14 | # base64_icon_data :text 15 | # description :text 16 | # 17 | 18 | class OrganizationSerializer < ActiveModel::Serializer 19 | attributes :id, :name, :slug, :description, :icon_thumb_url, :icon_large_url 20 | 21 | has_many :projects 22 | has_many :members 23 | has_many :organization_memberships 24 | 25 | def icon_thumb_url 26 | object.icon.url(:thumb) 27 | end 28 | 29 | def icon_large_url 30 | object.icon.url(:large) 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/serializers/post_image_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_images 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # filename :text not null 9 | # base64_photo_data :text not null 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # image_file_name :string 13 | # image_content_type :string 14 | # image_file_size :integer 15 | # image_updated_at :datetime 16 | # 17 | 18 | class PostImageSerializer < ActiveModel::Serializer 19 | attributes :id, :filename 20 | 21 | belongs_to :user 22 | belongs_to :post 23 | end 24 | -------------------------------------------------------------------------------- /app/serializers/post_like_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_likes 4 | # 5 | # id :integer not null, primary key 6 | # post_id :integer 7 | # user_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class PostLikeSerializer < ActiveModel::Serializer 13 | belongs_to :user 14 | belongs_to :post, serializer: PostSerializerWithoutIncludes 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/post_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: posts 4 | # 5 | # id :integer not null, primary key 6 | # status :string default("open") 7 | # post_type :string default("task") 8 | # title :string 9 | # body :text 10 | # user_id :integer not null 11 | # project_id :integer not null 12 | # created_at :datetime not null 13 | # updated_at :datetime not null 14 | # post_likes_count :integer default(0) 15 | # markdown :text 16 | # number :integer 17 | # aasm_state :string 18 | # comments_count :integer default(0) 19 | # 20 | 21 | class PostSerializer < ActiveModel::Serializer 22 | attributes :id, :number, :post_type, :state, :status, 23 | :title, :body, :markdown, :likes_count, :comments_count, 24 | :created_at, :edited_at 25 | 26 | has_many :comments 27 | has_many :post_user_mentions 28 | has_many :comment_user_mentions 29 | 30 | belongs_to :user 31 | belongs_to :project 32 | 33 | def likes_count 34 | object.post_likes_count 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/serializers/post_serializer_without_includes.rb: -------------------------------------------------------------------------------- 1 | class PostSerializerWithoutIncludes < ActiveModel::Serializer 2 | attributes :id, :number, :post_type, :state, :status, 3 | :title, :body, :markdown, :likes_count, :comments_count, 4 | :edited_at 5 | 6 | def likes_count 7 | object.post_likes_count 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/serializers/post_user_mention_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PostUserMentionSerializer < ActiveModel::Serializer 16 | attributes :id, :indices, :username 17 | 18 | belongs_to :user 19 | belongs_to :post, serializer: PostSerializerWithoutIncludes 20 | end 21 | -------------------------------------------------------------------------------- /app/serializers/preview_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: previews 4 | # 5 | # id :integer not null, primary key 6 | # body :text not null 7 | # markdown :text not null 8 | # user_id :integer 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class PreviewSerializer < ActiveModel::Serializer 14 | attributes :id, :body, :markdown 15 | 16 | has_many :preview_user_mentions 17 | end 18 | -------------------------------------------------------------------------------- /app/serializers/preview_user_mention_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: preview_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # preview_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | class PreviewUserMentionSerializer < ActiveModel::Serializer 16 | attributes :id, :indices, :username 17 | 18 | belongs_to :preview 19 | belongs_to :user 20 | end 21 | -------------------------------------------------------------------------------- /app/serializers/project_category_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_categories 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectCategorySerializer < ActiveModel::Serializer 13 | belongs_to :project, serializer: ProjectSerializerWithoutIncludes 14 | belongs_to :category 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/project_role_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_roles 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectRoleSerializer < ActiveModel::Serializer 13 | belongs_to :project, serializer: ProjectSerializerWithoutIncludes 14 | belongs_to :role, serializer: RoleSerializerWithoutIncludes 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/project_serializer_without_includes.rb: -------------------------------------------------------------------------------- 1 | class ProjectSerializerWithoutIncludes < ActiveModel::Serializer 2 | attributes :id, :title, :description, :icon_thumb_url, :icon_large_url, 3 | :long_description_body, :long_description_markdown, 4 | :open_posts_count, :closed_posts_count 5 | 6 | def icon_thumb_url 7 | object.icon.url(:thumb) 8 | end 9 | 10 | def icon_large_url 11 | object.icon.url(:large) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/serializers/project_skill_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_skills 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class ProjectSkillSerializer < ActiveModel::Serializer 13 | belongs_to :project, serializer: ProjectSerializerWithoutIncludes 14 | belongs_to :skill, serializer: SkillSerializerWithoutIncludes 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/role_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: roles 4 | # 5 | # id :integer not null, primary key 6 | # created_at :datetime not null 7 | # updated_at :datetime not null 8 | # name :string not null 9 | # ability :string not null 10 | # kind :string not null 11 | # 12 | 13 | class RoleSerializer < ActiveModel::Serializer 14 | attributes :id, :name, :ability, :kind 15 | 16 | has_many :skills 17 | end 18 | -------------------------------------------------------------------------------- /app/serializers/role_serializer_without_includes.rb: -------------------------------------------------------------------------------- 1 | class RoleSerializerWithoutIncludes < ActiveModel::Serializer 2 | attributes :id, :name, :ability 3 | end 4 | -------------------------------------------------------------------------------- /app/serializers/role_skill_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: role_skills 4 | # 5 | # id :integer not null, primary key 6 | # role_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # cat :integer 11 | # 12 | 13 | class RoleSkillSerializer < ActiveModel::Serializer 14 | belongs_to :role, serializer: RoleSerializerWithoutIncludes 15 | belongs_to :skill, serializer: SkillSerializerWithoutIncludes 16 | end 17 | -------------------------------------------------------------------------------- /app/serializers/skill_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: skills 4 | # 5 | # id :integer not null, primary key 6 | # title :string not null 7 | # description :string 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # original_row :integer 11 | # slug :string not null 12 | # 13 | 14 | class SkillSerializer < ActiveModel::Serializer 15 | attributes :id, :title, :description 16 | 17 | has_many :roles 18 | end 19 | -------------------------------------------------------------------------------- /app/serializers/skill_serializer_without_includes.rb: -------------------------------------------------------------------------------- 1 | class SkillSerializerWithoutIncludes < ActiveModel::Serializer 2 | attributes :id, :title, :description 3 | end 4 | -------------------------------------------------------------------------------- /app/serializers/slugged_route_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: slugged_routes 4 | # 5 | # id :integer not null, primary key 6 | # slug :string not null 7 | # owner_id :integer 8 | # owner_type :string 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | class SluggedRouteSerializer < ActiveModel::Serializer 14 | attributes :id, :slug, :owner_type 15 | 16 | belongs_to :owner, polymorphic: true 17 | end 18 | -------------------------------------------------------------------------------- /app/serializers/user_category_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_categories 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserCategorySerializer < ActiveModel::Serializer 13 | belongs_to :user 14 | belongs_to :category 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/user_role_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_roles 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserRoleSerializer < ActiveModel::Serializer 13 | belongs_to :user 14 | belongs_to :role, serializer: RoleSerializerWithoutIncludes 15 | end 16 | -------------------------------------------------------------------------------- /app/serializers/user_serializer_without_includes.rb: -------------------------------------------------------------------------------- 1 | class UserSerializerWithoutIncludes < ActiveModel::Serializer 2 | attributes :id, :created_at, :email, :first_name, :last_name, :name, 3 | :username, :twitter, :biography, :website, 4 | :facebook_id, :facebook_access_token, :photo_thumb_url, 5 | :photo_large_url, :state, :theme 6 | 7 | def photo_thumb_url 8 | object.photo.url(:thumb) 9 | end 10 | 11 | def photo_large_url 12 | object.photo.url(:large) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/serializers/user_skill_serializer.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_skills 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | class UserSkillSerializer < ActiveModel::Serializer 13 | belongs_to :user 14 | belongs_to :skill 15 | end 16 | -------------------------------------------------------------------------------- /app/validators/base64_photo_data_validator.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/base64_image_matcher" 2 | 3 | class Base64PhotoDataValidator < ActiveModel::EachValidator 4 | 5 | def validate_each(record, attribute, value) 6 | return validate_property(record, attribute, value) 7 | end 8 | 9 | private 10 | 11 | def validate_property(record, attribute, value) 12 | unless valid_base64_image_string?(value) 13 | record.errors[attribute] = "must be a valid data URI for a jpeg, png, or gif image" 14 | end 15 | end 16 | 17 | def valid_base64_image_string?(base64_image_string) 18 | base64_image_matcher.match?(base64_image_string) 19 | end 20 | 21 | def base64_image_matcher 22 | @base64_image_matcher ||= Base64ImageMatcher.new 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/validators/slug_validator.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/slug_matcher" 2 | 3 | class SlugValidator < ActiveModel::EachValidator 4 | def validate_each(record, attribute, value) 5 | validate_property(record, attribute, value) 6 | end 7 | 8 | private 9 | 10 | def validate_property(record, attribute, value) 11 | unless valid_slug?(value) 12 | record.errors[attribute] = "may only contain alphanumeric characters, underscores, or single hyphens, and cannot begin or end with a hyphen or underscore" 13 | end 14 | end 15 | 16 | def valid_slug?(slug) 17 | slug_matcher.match?(slug) 18 | end 19 | 20 | def slug_matcher 21 | @slug_matcher ||= SlugMatcher.new 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /app/views/notification_mailer/notify.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |9 | You can take a look at the <%= @type %> by clicking here 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /app/views/notification_mailer/notify.text.erb: -------------------------------------------------------------------------------- 1 | User @<%= @author.username %> has mentioned you in a <%= @type %> 2 | =============================================== 3 | 4 | You can view this <%= @type %> by visiting the following link: 5 | 6 | <%= @link %> 7 | -------------------------------------------------------------------------------- /app/workers/add_facebook_friends_worker.rb: -------------------------------------------------------------------------------- 1 | class AddFacebookFriendsWorker 2 | include Sidekiq::Worker 3 | 4 | def perform(user_id) 5 | user = User.find(user_id) 6 | 7 | facebook_access_token = user.facebook_access_token 8 | graph = Koala::Facebook::API.new(facebook_access_token, ENV["FACEBOOK_APP_SECRET"]) 9 | friends = graph.get_connections("me", "friends") 10 | 11 | still_has_friends = friends.present? 12 | friends_to_add = friends 13 | 14 | while still_has_friends 15 | add_friends(friends_to_add, user) 16 | 17 | next_page_of_friends = friends.next_page 18 | 19 | if next_page_of_friends.present? 20 | friends_to_add = next_page_of_friends 21 | else 22 | still_has_friends = false 23 | end 24 | end 25 | end 26 | 27 | def add_friends(facebook_friends, user) 28 | facebook_friends.each do |facebook_friend| 29 | friend = User.find_by(facebook_id: facebook_friend["id"]) 30 | if friend 31 | friend.follow(user) unless friend.following?(user) 32 | user.follow(friend) unless user.following?(friend) 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/workers/add_facebook_profile_picture_worker.rb: -------------------------------------------------------------------------------- 1 | class AddFacebookProfilePictureWorker 2 | include Sidekiq::Worker 3 | 4 | def perform(user_id) 5 | user = User.find(user_id) 6 | photo_url = facebook_photo_url(user) 7 | return unless photo_url 8 | user.photo = URI.parse(photo_url) 9 | user.save 10 | analytics_for(user).track_added_profile_picture_from_facebook 11 | end 12 | 13 | private 14 | 15 | def analytics_for(user) 16 | @analytics_for ||= Analytics.new(user) 17 | end 18 | 19 | def facebook_photo_url(user) 20 | facebook_access_token = user.facebook_access_token 21 | graph = Koala::Facebook::API.new(facebook_access_token, ENV['FACEBOOK_APP_SECRET']) 22 | graph.get_picture('me', type: "large") 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/workers/add_organization_icon_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/base64_image_decoder" 2 | 3 | class AddOrganizationIconWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(organization_id) 7 | organization = Organization.find(organization_id) 8 | return unless organization.base64_icon_data 9 | organization.icon = Base64ImageDecoder.decode(organization.base64_icon_data) 10 | organization.base64_icon_data = nil 11 | organization.save 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/workers/add_profile_picture_from_gravatar_worker.rb: -------------------------------------------------------------------------------- 1 | require "digest/md5" 2 | 3 | class AddProfilePictureFromGravatarWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(user_id) 7 | user = User.find(user_id) 8 | photo_url = gravatar_photo_url(user) 9 | return unless photo_url 10 | user.photo = URI.parse(photo_url) 11 | user.save 12 | analytics_for(user).track_added_profile_picture_from_gravatar 13 | end 14 | 15 | private 16 | 17 | def analytics_for(user) 18 | @analytics_for ||= Analytics.new(user) 19 | end 20 | 21 | def gravatar_photo_url(user) 22 | hash = gravatar_hash_for(user) 23 | gravatar_url = "https://secure.gravatar.com/avatar/#{hash}?s=500&r=pg&d=404" 24 | gravatar_returns_error?(hash) ? nil : gravatar_url 25 | end 26 | 27 | def gravatar_hash_for(user) 28 | Digest::MD5.hexdigest(user.email) 29 | end 30 | 31 | def gravatar_returns_error?(hash) 32 | response = Faraday.get "https://secure.gravatar.com/avatar/#{hash}?d=404" 33 | 34 | response.body == "404 Not Found" ? true : false 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/workers/add_project_icon_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/base64_image_decoder" 2 | 3 | class AddProjectIconWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(project_id) 7 | project = Project.find(project_id) 8 | return unless project.base64_icon_data 9 | project.icon = Base64ImageDecoder.decode(project.base64_icon_data) 10 | project.base64_icon_data = nil 11 | project.save 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/workers/generate_comment_user_notifications_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/scenario/generate_notifications_for_comment_user_mentions" 2 | require "code_corps/scenario/send_notification_emails" 3 | 4 | class GenerateCommentUserNotificationsWorker 5 | include Sidekiq::Worker 6 | 7 | def perform(comment_id) 8 | comment = Comment.find(comment_id) 9 | CodeCorps::Scenario::GenerateNotificationsForCommentUserMentions.new(comment).call 10 | CodeCorps::Scenario::SendNotificationEmails.new(comment).call 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/workers/generate_post_user_notifications_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/scenario/generate_notifications_for_post_user_mentions" 2 | require "code_corps/scenario/send_notification_emails" 3 | 4 | class GeneratePostUserNotificationsWorker 5 | include Sidekiq::Worker 6 | 7 | def perform(post_id) 8 | post = Post.find(post_id) 9 | CodeCorps::Scenario::GenerateNotificationsForPostUserMentions.new(post).call 10 | CodeCorps::Scenario::SendNotificationEmails.new(post).call 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/workers/notify_pusher_of_comment_image_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/scenario/notify_pusher_of_comment_image" 2 | 3 | class NotifyPusherOfCommentImageWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(comment_image_id) 7 | comment_image = CommentImage.find(comment_image_id) 8 | CodeCorps::Scenario::NotifyPusherOfCommentImage.new(comment_image).call 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/workers/notify_pusher_of_post_image_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/scenario/notify_pusher_of_post_image" 2 | 3 | class NotifyPusherOfPostImageWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(post_image_id) 7 | post_image = PostImage.find(post_image_id) 8 | CodeCorps::Scenario::NotifyPusherOfPostImage.new(post_image).call 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/workers/subscribe_to_mailing_list_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/adapters/mailing_list" 2 | 3 | class SubscribeToMailingListWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(user_id) 7 | user = User.find(user_id) 8 | CodeCorps::Adapters::MailingList.new(user).subscribe 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/workers/update_profile_picture_worker.rb: -------------------------------------------------------------------------------- 1 | require "code_corps/base64_image_decoder" 2 | 3 | class UpdateProfilePictureWorker 4 | include Sidekiq::Worker 5 | 6 | def perform(user_id) 7 | user = User.find(user_id) 8 | return unless user.base64_photo_data 9 | user.photo = Base64ImageDecoder.decode(user.base64_photo_data) 10 | user.base64_photo_data = nil 11 | user.save 12 | analytics_for(user).track_updated_profile_picture 13 | end 14 | 15 | private 16 | 17 | def analytics_for(user) 18 | @analytics_for ||= Analytics.new(user) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/colors: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export red=$'\e[1;31m' 4 | export green=$'\e[0;32m' 5 | export yellow=$'\e[1;33m' 6 | export blue=$'\e[1;34m' 7 | -------------------------------------------------------------------------------- /bin/development: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | HEROKU_APP=code-corps-development HKAPP=code-corps-development exec "${HEROKU_COMMAND:-heroku}" "$@" 3 | -------------------------------------------------------------------------------- /bin/migrate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Exit if any subcommand fails 4 | set -e 5 | 6 | # Import colors 7 | . bin/colors 8 | 9 | # Check for tools that need to be installed 10 | dependencies='docker-compose' 11 | for name in $dependencies 12 | do 13 | if ! which "$name" > /dev/null; then 14 | echo -e "${red}\xE2\x9D\x8C $name not installed! Exiting.${end}" 15 | echo "${yellow}You'll need to reinstall $name to continue.${end}" 16 | exit 1 17 | fi 18 | done 19 | 20 | printf "\nMigrating database...\n" 21 | docker-compose run web rake db:migrate db:test:prepare 22 | 23 | echo "" 24 | echo "🙌 ${green}Migrate complete.${end}" 25 | exit 0 26 | -------------------------------------------------------------------------------- /bin/production: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | HEROKU_APP=code-corps HKAPP=code-corps exec "${HEROKU_COMMAND:-heroku}" "$@" 3 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/reseed: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Exit if any subcommand fails 4 | set -e 5 | 6 | # Import colors 7 | . bin/colors 8 | 9 | # Check for tools that need to be installed 10 | dependencies='docker-compose' 11 | for name in $dependencies 12 | do 13 | if ! which "$name" > /dev/null; then 14 | echo -e "${red}\xE2\x9D\x8C $name not installed! Exiting.${end}" 15 | echo "${yellow}You'll need to reinstall $name to continue.${end}" 16 | exit 1 17 | fi 18 | done 19 | 20 | printf "\nMigrating database...\n" 21 | docker-compose run web rake db:migrate db:test:prepare 22 | 23 | printf "\nSeeding database...\n" 24 | docker-compose run web rake db:seed_fu 25 | 26 | printf "\nReindexing elasticsearch...\n" 27 | docker-compose run web rake searchkick:reindex CLASS=Skill 28 | 29 | echo "" 30 | echo "🌱 ${green}Reseed complete.${end}" 31 | exit 0 32 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Exit if any subcommand fails 4 | set -e 5 | 6 | # Import colors 7 | . bin/colors 8 | 9 | # Check for tools that need to be installed 10 | dependencies='docker-compose' 11 | for name in $dependencies 12 | do 13 | if ! which "$name" > /dev/null; then 14 | echo -e "${red}\xE2\x9D\x8C $name not installed! Exiting.${end}" 15 | exit 1 16 | fi 17 | done 18 | 19 | if docker-compose run web rake db:exists > /dev/null; then 20 | echo -e "${red}\xE2\x9D\x8C Database already exists! Exiting.${end}" 21 | exit 1 22 | fi 23 | 24 | printf "\nPreparing database...\n" 25 | # Creates the database. 26 | docker-compose run web rake db:create db:migrate db:test:prepare 27 | 28 | printf "\nSeeding database...\n" 29 | docker-compose run web rake db:seed_fu 30 | 31 | printf "\nReindexing elasticsearch...\n" 32 | docker-compose run web rake searchkick:reindex CLASS=Skill 33 | 34 | printf "\nRemoving old logs and tempfiles...\n" 35 | rm -f log/* 36 | rm -rf tmp/cache 37 | 38 | printf "\n🌤 ${green}Setup complete.${end}" 39 | exit 0 40 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) 11 | Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq } 12 | gem 'spring', match[1] 13 | require 'spring/binstub' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /bin/staging: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | HEROKU_APP=code-corps-staging HKAPP=code-corps-staging exec "${HEROKU_COMMAND:-heroku}" "$@" 3 | -------------------------------------------------------------------------------- /blueprint/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:0.12.7 2 | 3 | # Install Aglio 4 | RUN npm install -g aglio@latest 5 | -------------------------------------------------------------------------------- /blueprint/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | aglio: 5 | build: 6 | context: . 7 | volumes: 8 | - .:/tmp 9 | -------------------------------------------------------------------------------- /blueprint/generate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Exit if any subcommand fails 4 | set -e 5 | 6 | # Import colors 7 | . ../bin/colors 8 | 9 | # Check for tools that need to be installed 10 | dependencies='docker-compose' 11 | for name in $dependencies 12 | do 13 | if ! which "$name" > /dev/null; then 14 | echo -e "${red}\xE2\x9D\x8C $name not installed! Exiting.${end}" 15 | exit 1 16 | fi 17 | done 18 | 19 | printf "\nGenerating API docs...\n\n" 20 | # Creates the database. 21 | docker-compose run aglio aglio --theme-variables flatly -i /tmp/api.apib -o /tmp/index.html 22 | 23 | echo "" 24 | printf "${green}Docs generated.${end}" 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - elasticsearch 4 | deployment: 5 | staging: 6 | branch: develop 7 | commands: 8 | - git push git@heroku.com:code-corps-development.git $CIRCLE_SHA1:master 9 | - heroku run rake db:migrate --app code-corps-development 10 | - git push git@heroku.com:code-corps-staging.git $CIRCLE_SHA1:master 11 | - heroku run rake db:migrate --app code-corps-staging 12 | - gem install apiaryio 13 | - apiary publish --api-name="codecorpsapidevelop" --path ./blueprint/api.apib 14 | production: 15 | branch: master 16 | commands: 17 | - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow" 18 | - git push git@heroku.com:code-corps.git $CIRCLE_SHA1:master 19 | - heroku run rake db:migrate --app code-corps 20 | - gem install apiaryio 21 | - apiary publish --api-name="codecorpsapi" --path ./blueprint/api.apib 22 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: redis://localhost:6379/1 10 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: postgresql 3 | username: postgres 4 | host: db 5 | port: 5432 6 | role: postgres 7 | 8 | test: 9 | <<: *default 10 | database: code_corps_test 11 | development: 12 | <<: *default 13 | database: code_corps_dev 14 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Application-wide configuration 5 | Rails.application.configure do 6 | 7 | config.paperclip_defaults = { 8 | storage: :s3, 9 | s3_protocol: :https, 10 | s3_credentials: { 11 | bucket: ENV["S3_BUCKET_NAME"], 12 | s3_region: "us-east-1", 13 | access_key_id: ENV["AWS_ACCESS_KEY_ID"], 14 | secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"] 15 | }, 16 | s3_host_alias: ENV["CLOUDFRONT_DOMAIN"], 17 | url: ":s3_alias_url" 18 | } 19 | end 20 | 21 | # Initialize the Rails application. 22 | Rails.application.initialize! 23 | -------------------------------------------------------------------------------- /config/initializers/active_model_serializers.rb: -------------------------------------------------------------------------------- 1 | ActiveModelSerializers.config.adapter = :json_api 2 | ActiveModelSerializers.config.key_transform = :unaltered 3 | require "active_model_serializers/register_jsonapi_renderer" 4 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/clearance.rb: -------------------------------------------------------------------------------- 1 | Clearance.configure do |config| 2 | config.mailer_sender = "reply@example.com" 3 | config.routes = false 4 | end 5 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Once upgraded flip defaults one by one to migrate to the new default. 6 | # 7 | # Read the Rails 5.0 release notes for more info on each option. 8 | 9 | # Enable per-form CSRF tokens. Previous versions had false. 10 | Rails.application.config.action_controller.per_form_csrf_tokens = false 11 | 12 | # Enable origin-checking CSRF mitigation. Previous versions had false. 13 | Rails.application.config.action_controller.forgery_protection_origin_check = false 14 | 15 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 16 | # Previous versions had false. 17 | ActiveSupport.to_time_preserves_timezone = false 18 | 19 | # Require `belongs_to` associations by default. Previous versions had false. 20 | Rails.application.config.active_record.belongs_to_required_by_default = false 21 | 22 | # Do not halt callback chains when a callback returns false. Previous versions had true. 23 | ActiveSupport.halt_callback_chains_on_return_false = true 24 | -------------------------------------------------------------------------------- /config/initializers/pusher.rb: -------------------------------------------------------------------------------- 1 | Pusher.app_id = ENV['PUSHER_APP_ID'] 2 | Pusher.key = ENV['PUSHER_KEY'] 3 | Pusher.secret = ENV['PUSHER_SECRET'] 4 | 5 | if Rails.env.test? && ENV["PUSHER_FAKE"] 6 | require "pusher-fake/support/base" 7 | end 8 | -------------------------------------------------------------------------------- /config/initializers/redis.rb: -------------------------------------------------------------------------------- 1 | if ENV["REDISCLOUD_URL"] 2 | ENV["REDIS_URL"] = ENV["REDISCLOUD_URL"] 3 | $redis = Redis.new(url: ENV["REDIS_URL"]) 4 | elsif Rails.env.test? 5 | $redis = Redis.new 6 | end 7 | -------------------------------------------------------------------------------- /config/initializers/reserved_routes.rb: -------------------------------------------------------------------------------- 1 | Rails.configuration.x.reserved_routes = 2 | %w( 3 | about account admin android api app apps blog bug bugs cache charter 4 | comment comments contact contributor contributors cookies 5 | developer developers discover donate engineering enterprise explore 6 | facebook favorites feed followers following github help home image images 7 | integration integrations invite invitations ios issue issues jobs learn 8 | likes lists log-in log-out login logout mention mentions new news 9 | notification notifications oauth oauth_clients organization organizations 10 | ping popular post_image post_images post_like post_likes post post 11 | press pricing privacy 12 | project projects repositories role roles rules search security session 13 | sessions settings shop showcases sidekiq sign-in sign-out signin signout 14 | signup sitemap slug slugs spotlight stars status tag tags 15 | tasks team teams terms training trends trust tour twitter 16 | user_role user_roles user_skill user_skills user users watching year 17 | ) 18 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure your secret_key_base is kept private 11 | # if you're sharing your code publicly. 12 | 13 | # Although this is not needed for an api-only application, rails4 14 | # requires secret_key_base or secret_token to be defined, otherwise an 15 | # error is raised. 16 | # Using secret_token for rails3 compatibility. Change to secret_key_base 17 | # to avoid deprecation warning. 18 | # Can be safely removed in a rails3 api-only application. 19 | CodeCorpsApi::Application.config.secret_token = ENV['SECRET_KEY_BASE'] 20 | -------------------------------------------------------------------------------- /config/initializers/sentry.rb: -------------------------------------------------------------------------------- 1 | Raven.configure do |config| 2 | config.environments = %w[ staging production ] 3 | end 4 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: "_code_corps_api_session" 4 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper 4 | 5 | # Enable parameter wrapping for JSON. 6 | # ActiveSupport.on_load(:action_controller) do 7 | # wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 8 | # end 9 | 10 | # To enable root element in JSON for ActiveRecord objects. 11 | # ActiveSupport.on_load(:active_record) do 12 | # self.include_root_in_json = true 13 | # end 14 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | workers Integer(ENV["WEB_CONCURRENCY"] || 2) 2 | threads_count = Integer(ENV["RAILS_MAX_THREADS"] || 5) 3 | threads threads_count, threads_count 4 | 5 | preload_app! 6 | 7 | rackup DefaultRackup 8 | port ENV["PORT"] || 3000 9 | environment ENV["RACK_ENV"] || "development" 10 | 11 | on_worker_boot do 12 | # Worker specific setup for Rails 4.1+ 13 | # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot 14 | ActiveRecord::Base.establish_connection 15 | end 16 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 6e261a8aadb3ce591081aa3340c0d13b7281356b4eea371c3b1e876a70870c885667a3ced94710478a120a64376f7d0411ed4ec9806d822c4466aaa962b4b283 15 | 16 | test: 17 | secret_key_base: 720a2a359359fc9422f2a7db6e45d77ff639d061e717824253c2302fa9ac34b351fe490578e51a144a930c80f4486a0bd77aa31861f1d4fbf88063ac647aeb9f 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /config/sidekiq.yml: -------------------------------------------------------------------------------- 1 | --- 2 | :verbose: true 3 | :concurrency: 10 4 | :queues: 5 | - default 6 | - paperclip -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /db/fixtures/001_users.rb: -------------------------------------------------------------------------------- 1 | User.seed do |user| 2 | user.id = 1 3 | user.username = "administrator" 4 | user.email = "admin@example.org" 5 | user.password = "password" 6 | user.admin = true 7 | end 8 | 9 | User.seed do |user| 10 | user.id = 2 11 | user.username = "testuser" 12 | user.email = "test@example.com" 13 | user.password = "test" 14 | user.admin = false 15 | end 16 | -------------------------------------------------------------------------------- /db/fixtures/002_organizations.rb: -------------------------------------------------------------------------------- 1 | Organization.seed do |organization| 2 | organization.id = 1 3 | organization.name = "Code Corps" 4 | organization.slug = "code_corps" 5 | end 6 | 7 | OrganizationMembership.seed do |membership| 8 | membership.id = 1 9 | membership.member_id = 2 10 | membership.organization_id = 1 11 | end 12 | -------------------------------------------------------------------------------- /db/fixtures/003_projects.rb: -------------------------------------------------------------------------------- 1 | Project.seed do |project| 2 | project.id = 1 3 | project.title = "Code Corps" 4 | project.description = "A basic project for use in development" 5 | project.organization_id = 1 6 | project.slug = "code_corps" 7 | end 8 | -------------------------------------------------------------------------------- /db/fixtures/004_posts.rb: -------------------------------------------------------------------------------- 1 | 5.times do 2 | Post.seed do |post| 3 | post.title = "A task" 4 | post.body = "This is a basic task" 5 | post.markdown = "This is a basic task" 6 | post.project_id = 1 7 | post.user_id = 2 8 | post.post_type = "task" 9 | post.aasm_state = "published" 10 | end 11 | 12 | Post.seed do |post| 13 | post.title = "An idea" 14 | post.body = "This is a basic idea" 15 | post.markdown = "This is a basic idea" 16 | post.project_id = 1 17 | post.user_id = 2 18 | post.post_type = "idea" 19 | post.aasm_state = "published" 20 | end 21 | 22 | Post.seed do |post| 23 | post.title = "An issue" 24 | post.body = "This is a basic issue" 25 | post.markdown = "This is a basic progress post" 26 | post.project_id = 1 27 | post.user_id = 2 28 | post.post_type = "issue" 29 | post.aasm_state = "published" 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /db/fixtures/007_skills.rb: -------------------------------------------------------------------------------- 1 | skills = [ 2 | { 3 | title: "Ember.js", 4 | }, 5 | { 6 | title: "HTML", 7 | }, 8 | { 9 | title: "CSS", 10 | }, 11 | { 12 | title: "Ruby", 13 | }, 14 | { 15 | title: "Ruby on Rails", 16 | }, 17 | { 18 | title: "Docker", 19 | }, 20 | ] 21 | 22 | skills.each do |skill| 23 | Skill.seed_once(:title) do |s| 24 | s.title = skill[:title] 25 | s.slug = skill[:title].parameterize 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /db/migrate/20150623143430_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration 2 | def change 3 | create_table :users do |t| 4 | t.timestamps null: false 5 | t.string :email, null: false 6 | t.string :encrypted_password, limit: 128, null: false 7 | t.string :confirmation_token, limit: 128 8 | t.string :remember_token, limit: 128, null: false 9 | end 10 | 11 | add_index :users, :email 12 | add_index :users, :remember_token 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20150623144945_add_username_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddUsernameToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :username, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20150628202953_add_admin_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddAdminToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :admin, :boolean, null: false, default: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151119113429_create_project_related_tables.rb: -------------------------------------------------------------------------------- 1 | class CreateProjectRelatedTables < ActiveRecord::Migration 2 | def change 3 | create_table :teams do |t| 4 | t.string :name, null: false 5 | 6 | t.timestamps null: false 7 | 8 | t.belongs_to :organization 9 | end 10 | 11 | create_table :organizations do |t| 12 | t.string :name, null: false 13 | 14 | t.timestamps null: false 15 | end 16 | 17 | create_table :projects do |t| 18 | t.string :title, null: false 19 | t.string :description 20 | 21 | t.references :owner, polymorphic: true, index: true 22 | 23 | t.timestamps null: false 24 | end 25 | 26 | create_table :team_memberships do |t| 27 | t.timestamps null: false 28 | 29 | t.integer :member_id 30 | t.belongs_to :team 31 | 32 | end 33 | 34 | add_index :team_memberships, [:member_id, :team_id], unique: true 35 | 36 | create_table :organization_memberships do |t| 37 | t.string :role, default: "regular", null: false 38 | 39 | t.timestamps null: false 40 | 41 | t.integer :member_id 42 | t.belongs_to :organization 43 | end 44 | 45 | add_index :organization_memberships, [:member_id, :organization_id], unique: true 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /db/migrate/20151124121656_add_twitter_website_biography_to_user.rb: -------------------------------------------------------------------------------- 1 | class AddTwitterWebsiteBiographyToUser < ActiveRecord::Migration 2 | def change 3 | add_column(:users, :website, :text) 4 | add_column(:users, :twitter, :string) 5 | add_column(:users, :biography, :text) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20151124130003_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration 2 | def change 3 | create_table :posts do |t| 4 | t.string :status, default: "open" 5 | t.string :type, default: "task" 6 | t.string :title, null: false 7 | t.text :body 8 | 9 | t.belongs_to :user 10 | t.belongs_to :project 11 | 12 | t.timestamps null: false 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20151124130007_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration 2 | def change 3 | create_table :comments do |t| 4 | t.text :body 5 | 6 | t.belongs_to :user 7 | t.belongs_to :post 8 | 9 | t.timestamps null: false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20151124205005_add_icon_columns_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddIconColumnsToProjects < ActiveRecord::Migration 2 | def up 3 | add_attachment :projects, :icon 4 | end 5 | 6 | def down 7 | remove_attachment :projects, :icon 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20151124222923_add_icon_data_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddIconDataToProjects < ActiveRecord::Migration 2 | def change 3 | add_column(:projects, :base_64_icon_data, :text) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151125120623_rename_posts_type.rb: -------------------------------------------------------------------------------- 1 | class RenamePostsType < ActiveRecord::Migration 2 | def change 3 | rename_column :posts, :type, :post_type 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151125134242_add_foreign_keys_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddForeignKeysToPosts < ActiveRecord::Migration 2 | def change 3 | change_column_null :posts, :user_id, false 4 | add_foreign_key :posts, :users 5 | change_column_null :posts, :project_id, false 6 | add_foreign_key :posts, :projects 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20151125142534_make_comment_body_not_nullable.rb: -------------------------------------------------------------------------------- 1 | class MakeCommentBodyNotNullable < ActiveRecord::Migration 2 | def change 3 | change_column_null :comments, :body, false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151125142551_add_foreign_keys_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddForeignKeysToComments < ActiveRecord::Migration 2 | def change 3 | change_column_null :comments, :user_id, false 4 | add_foreign_key :comments, :users 5 | change_column_null :comments, :post_id, false 6 | add_foreign_key :comments, :posts 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20151126094430_create_skill_categories.rb: -------------------------------------------------------------------------------- 1 | class CreateSkillCategories < ActiveRecord::Migration 2 | def change 3 | create_table :skill_categories do |t| 4 | t.string :title, null: false 5 | 6 | t.timestamps null: false 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20151126094437_create_skills.rb: -------------------------------------------------------------------------------- 1 | class CreateSkills < ActiveRecord::Migration 2 | def change 3 | create_table :skills do |t| 4 | t.string :title, null: false 5 | t.string :description 6 | 7 | t.belongs_to :skill_category 8 | 9 | t.timestamps null: false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20151126100212_create_user_skills.rb: -------------------------------------------------------------------------------- 1 | class CreateUserSkills < ActiveRecord::Migration 2 | def change 3 | create_table :user_skills do |t| 4 | t.belongs_to :user 5 | t.belongs_to :skill 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20151126133741_create_post_likes.rb: -------------------------------------------------------------------------------- 1 | class CreatePostLikes < ActiveRecord::Migration 2 | def change 3 | create_table :post_likes do |t| 4 | t.belongs_to :post, counter_cache: true 5 | t.belongs_to :user 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_column :posts, :post_likes_count, :integer, default: 0 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20151130085255_make_posts_body_not_nullable.rb: -------------------------------------------------------------------------------- 1 | class MakePostsBodyNotNullable < ActiveRecord::Migration 2 | def change 3 | change_column_null :posts, :body, false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151130204153_add_markdown_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddMarkdownToPosts < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :markdown, :text, null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151201091555_create_contributors.rb: -------------------------------------------------------------------------------- 1 | class CreateContributors < ActiveRecord::Migration 2 | def change 3 | create_table :contributors do |t| 4 | t.belongs_to :user 5 | t.belongs_to :project 6 | 7 | t.string :status, null: false, default: "pending" 8 | 9 | t.timestamps null: false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20151201175725_add_markdown_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddMarkdownToComments < ActiveRecord::Migration 2 | def change 3 | add_column :comments, :markdown, :text, null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151201201552_create_post_user_mentions.rb: -------------------------------------------------------------------------------- 1 | class CreatePostUserMentions < ActiveRecord::Migration 2 | def change 3 | create_table :post_user_mentions do |t| 4 | t.belongs_to :user, null: false 5 | t.belongs_to :post, null: false 6 | 7 | t.string :username, null: false 8 | t.integer :start_index, null: false 9 | t.integer :end_index, null: false 10 | 11 | t.timestamps null: false 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20151202083431_add_facebook_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddFacebookToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :facebook_id, :string 4 | add_column :users, :facebook_access_token, :string 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20151203125938_create_github_repositories.rb: -------------------------------------------------------------------------------- 1 | class CreateGithubRepositories < ActiveRecord::Migration 2 | def change 3 | create_table :github_repositories do |t| 4 | t.string :repository_name, null: false 5 | t.string :owner_name, null: false 6 | 7 | t.belongs_to :project, null: false 8 | 9 | t.timestamps null: false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20151203174346_create_slug_routes.rb: -------------------------------------------------------------------------------- 1 | class CreateSlugRoutes < ActiveRecord::Migration 2 | def change 3 | create_table :slug_routes do |t| 4 | t.string :slug, null: false 5 | t.references :owner, polymorphic: true 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :slug_routes, :slug, unique: true 11 | add_index :slug_routes, [:owner_id, :owner_type], unique: true 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20151203181837_add_slug_to_organizations.rb: -------------------------------------------------------------------------------- 1 | class AddSlugToOrganizations < ActiveRecord::Migration 2 | def change 3 | add_column :organizations, :slug, :string 4 | Organization.all.each do |organization| 5 | organization.update_attributes(slug: organization.name.parameterize) 6 | end 7 | change_column_null :organizations, :slug, false 8 | 9 | add_index :organizations, :slug, :unique => true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20151203191921_add_contributors_count_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddContributorsCountToProjects < ActiveRecord::Migration 2 | def change 3 | add_column :projects, :contributors_count, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151204234343_add_number_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddNumberToPosts < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :number, :integer, null: false 4 | 5 | add_index :posts, [:number, :project_id], unique: true 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20151205212042_create_members.rb: -------------------------------------------------------------------------------- 1 | class CreateMembers < ActiveRecord::Migration 2 | def change 3 | create_table :members do |t| 4 | t.string :slug, null: false 5 | t.references :model, polymorphic: true 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :members, :slug, unique: true 11 | add_index :members, [:model_id, :model_type], unique: true 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20151205223211_drop_slug_routes.rb: -------------------------------------------------------------------------------- 1 | class DropSlugRoutes < ActiveRecord::Migration 2 | def change 3 | drop_table :slug_routes 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151207101527_add_slug_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddSlugToProjects < ActiveRecord::Migration 2 | def change 3 | add_column :projects, :slug, :string 4 | Project.all.each do |project| 5 | project.update_attributes(slug: project.title.parameterize) 6 | end 7 | change_column_null :projects, :slug, false 8 | 9 | add_index :projects, [:slug, :owner_id], unique: true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20151207192647_add_photo_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddPhotoToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :base_64_photo_data, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151207224048_addphotocolumnstousers.rb: -------------------------------------------------------------------------------- 1 | class Addphotocolumnstousers < ActiveRecord::Migration 2 | def up 3 | add_attachment :users, :photo 4 | end 5 | 6 | def down 7 | remove_attachment :users, :photo 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20151208115704_create_user_relationships.rb: -------------------------------------------------------------------------------- 1 | class CreateUserRelationships < ActiveRecord::Migration 2 | def change 3 | create_table :user_relationships do |t| 4 | 5 | t.belongs_to :follower, index: true 6 | t.belongs_to :following, index: true 7 | 8 | t.timestamps null: false 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20151208214105_create_comment_user_mentions.rb: -------------------------------------------------------------------------------- 1 | class CreateCommentUserMentions < ActiveRecord::Migration 2 | def change 3 | create_table :comment_user_mentions do |t| 4 | t.belongs_to :user, null: false 5 | t.belongs_to :comment, null: false 6 | t.belongs_to :post, null: false 7 | 8 | t.string :username, null: false 9 | t.integer :start_index, null: false 10 | t.integer :end_index, null: false 11 | 12 | t.timestamps null: false 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20151208225204_create_notifications.rb: -------------------------------------------------------------------------------- 1 | class CreateNotifications < ActiveRecord::Migration 2 | def change 3 | create_table :notifications do |t| 4 | t.references :notifiable, polymorphic: true, null: false 5 | t.references :user, null: false 6 | t.string :aasm_state 7 | 8 | t.timestamps null: false 9 | end 10 | 11 | add_index :notifications, :user_id 12 | add_index :notifications, [:user_id, :notifiable_id, :notifiable_type], name: 'index_notifications_on_user_id_and_notifiable', unique: true 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20151209065037_add_state_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddStateToPosts < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :aasm_state, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151209065652_allow_skipping_number_on_posts.rb: -------------------------------------------------------------------------------- 1 | class AllowSkippingNumberOnPosts < ActiveRecord::Migration 2 | def up 3 | change_column :posts, :number, :integer, null: true 4 | remove_index :posts, [:number, :project_id] 5 | end 6 | 7 | def down 8 | change_column :posts, :number, :integer, null: false 9 | add_index :posts, [:number, :project_id], unique: true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20151209222143_add_state_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddStateToComments < ActiveRecord::Migration 2 | def change 3 | add_column :comments, :aasm_state, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20151209234741_create_post_images.rb: -------------------------------------------------------------------------------- 1 | class CreatePostImages < ActiveRecord::Migration 2 | def change 3 | create_table :post_images do |t| 4 | t.belongs_to :user, null: false 5 | t.belongs_to :post, null: false 6 | 7 | t.text :filename, null: false 8 | t.text :base_64_photo_data, null: false 9 | 10 | t.timestamps null: false 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20151209235804_add_attachment_to_post_images.rb: -------------------------------------------------------------------------------- 1 | class AddAttachmentToPostImages < ActiveRecord::Migration 2 | def up 3 | add_attachment :post_images, :image 4 | end 5 | 6 | def down 7 | remove_attachment :post_images, :image 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20151211200152_rename_base64_columns.rb: -------------------------------------------------------------------------------- 1 | class RenameBase64Columns < ActiveRecord::Migration 2 | def change 3 | rename_column :post_images, :base_64_photo_data, :base64_photo_data 4 | rename_column :users, :base_64_photo_data, :base64_photo_data 5 | rename_column :projects, :base_64_icon_data, :base64_icon_data 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20151212172654_create_comment_images.rb: -------------------------------------------------------------------------------- 1 | class CreateCommentImages < ActiveRecord::Migration 2 | def change 3 | create_table :comment_images do |t| 4 | t.belongs_to :user, null: false 5 | t.belongs_to :comment, null: false 6 | 7 | t.text :filename, null: false 8 | t.text :base64_photo_data, null: false 9 | 10 | t.timestamps null: false 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20151212172744_add_attachment_to_comment_images.rb: -------------------------------------------------------------------------------- 1 | class AddAttachmentToCommentImages < ActiveRecord::Migration 2 | def up 3 | add_attachment :comment_images, :image 4 | end 5 | 6 | def down 7 | remove_attachment :comment_images, :image 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20151227182138_create_team_projects.rb: -------------------------------------------------------------------------------- 1 | class CreateTeamProjects < ActiveRecord::Migration 2 | def change 3 | create_table :team_projects do |t| 4 | t.belongs_to :team, null: false 5 | t.belongs_to :project, null: false 6 | 7 | t.string :role, default: "regular", null: false 8 | 9 | t.timestamps null: false 10 | end 11 | 12 | add_index :team_projects, [:team_id, :project_id], unique: true 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20160115233549_rename_members_to_slugged_routes.rb: -------------------------------------------------------------------------------- 1 | class RenameMembersToSluggedRoutes < ActiveRecord::Migration 2 | def up 3 | rename_table :members, :slugged_routes 4 | end 5 | 6 | def down 7 | rename_table :slugged_routes, :members 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20160115233646_rename_model_in_slugged_routes_to_owner.rb: -------------------------------------------------------------------------------- 1 | class RenameModelInSluggedRoutesToOwner < ActiveRecord::Migration 2 | def up 3 | rename_column :slugged_routes, :model_id, :owner_id 4 | rename_column :slugged_routes, :model_type, :owner_type 5 | end 6 | 7 | def down 8 | rename_column :slugged_routes, :owner_id, :model_id 9 | rename_column :slugged_routes, :owner_type, :model_type 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160116192724_drop_team_project.rb: -------------------------------------------------------------------------------- 1 | class DropTeamProject < ActiveRecord::Migration 2 | def change 3 | drop_table :team_projects 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160116192734_drop_team.rb: -------------------------------------------------------------------------------- 1 | class DropTeam < ActiveRecord::Migration 2 | def change 3 | drop_table :teams 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160116192810_drop_contributor.rb: -------------------------------------------------------------------------------- 1 | class DropContributor < ActiveRecord::Migration 2 | def change 3 | drop_table :contributors 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160116193005_drop_team_membership.rb: -------------------------------------------------------------------------------- 1 | class DropTeamMembership < ActiveRecord::Migration 2 | def change 3 | drop_table :team_memberships 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160116200428_remove_contributors_count_from_projects.rb: -------------------------------------------------------------------------------- 1 | class RemoveContributorsCountFromProjects < ActiveRecord::Migration 2 | def up 3 | remove_column :projects, :contributors_count 4 | end 5 | 6 | def down 7 | add_column :projects, :contributors_count 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20160116201731_change_default_for_organization_memberships_to_pending.rb: -------------------------------------------------------------------------------- 1 | class ChangeDefaultForOrganizationMembershipsToPending < ActiveRecord::Migration 2 | def up 3 | change_column_default :organization_memberships, :role, "pending" 4 | end 5 | 6 | def down 7 | change_column_default :organization_memberships, :role, "regular" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20160116232700_add_organization_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddOrganizationToProjects < ActiveRecord::Migration 2 | def change 3 | add_reference :projects, :organization, null: false, index: true, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160116232718_remove_owner_from_projects.rb: -------------------------------------------------------------------------------- 1 | class RemoveOwnerFromProjects < ActiveRecord::Migration 2 | def change 3 | remove_reference :projects, :owner, polymorphic: true, index: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160119181706_add_name_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddNameToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :name, :text 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160119230937_add_comments_count_to_post.rb: -------------------------------------------------------------------------------- 1 | class AddCommentsCountToPost < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :comments_count, :integer, default: 0 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160204223535_add_icon_columns_to_organizations.rb: -------------------------------------------------------------------------------- 1 | class AddIconColumnsToOrganizations < ActiveRecord::Migration 2 | def up 3 | add_attachment :organizations, :icon 4 | end 5 | 6 | def down 7 | remove_attachment :organizations, :icon 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20160204223727_add_icon_data_to_organizations.rb: -------------------------------------------------------------------------------- 1 | class AddIconDataToOrganizations < ActiveRecord::Migration 2 | def change 3 | add_column(:organizations, :base64_icon_data, :text) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160209170316_add_body_preview_markdown_preview_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddBodyPreviewMarkdownPreviewToPosts < ActiveRecord::Migration 2 | def change 3 | add_column :posts, :body_preview, :text, null: true 4 | add_column :posts, :markdown_preview, :text, null: true 5 | change_column_null :posts, :body, true 6 | change_column_null :posts, :markdown, true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20160210140342_add_body_preview_markdown_preview_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddBodyPreviewMarkdownPreviewToComments < ActiveRecord::Migration 2 | def change 3 | add_column :comments, :body_preview, :text, null: true 4 | add_column :comments, :markdown_preview, :text, null: true 5 | change_column_null :comments, :body, true 6 | change_column_null :comments, :markdown, true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20160212102442_allow_null_on_post_title.rb: -------------------------------------------------------------------------------- 1 | class AllowNullOnPostTitle < ActiveRecord::Migration 2 | def change 3 | change_column_null :posts, :title, true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160215223422_add_description_to_organizations.rb: -------------------------------------------------------------------------------- 1 | class AddDescriptionToOrganizations < ActiveRecord::Migration 2 | def change 3 | add_column(:organizations, :description, :text) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160225201529_add_status_to_user_mentions.rb: -------------------------------------------------------------------------------- 1 | class AddStatusToUserMentions < ActiveRecord::Migration 2 | def change 3 | add_column(:comment_user_mentions, :status, :string, null: false, default: "preview") 4 | add_column(:post_user_mentions, :status, :string, null: false, default: "preview") 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160517230704_rename_skill_category_to_role.rb: -------------------------------------------------------------------------------- 1 | class RenameSkillCategoryToRole < ActiveRecord::Migration 2 | def change 3 | rename_table :skill_categories, :roles 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160517231457_add_name_and_ability_to_roles.rb: -------------------------------------------------------------------------------- 1 | class AddNameAndAbilityToRoles < ActiveRecord::Migration 2 | def change 3 | add_column :roles, :name, :string, null: false 4 | add_column :roles, :ability, :string, null: false 5 | remove_column :roles, :title 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20160518050009_change_skills_to_reference_roles.rb: -------------------------------------------------------------------------------- 1 | class ChangeSkillsToReferenceRoles < ActiveRecord::Migration 2 | def change 3 | rename_column :skills, :skill_category_id, :role_id 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160518205433_create_role_skills.rb: -------------------------------------------------------------------------------- 1 | class CreateRoleSkills < ActiveRecord::Migration 2 | def change 3 | create_table :role_skills do |t| 4 | t.belongs_to :role 5 | t.belongs_to :skill 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160518210630_remove_role_id_from_skills.rb: -------------------------------------------------------------------------------- 1 | class RemoveRoleIdFromSkills < ActiveRecord::Migration 2 | def change 3 | remove_column :skills, :role_id 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160518211037_create_user_roles.rb: -------------------------------------------------------------------------------- 1 | class CreateUserRoles < ActiveRecord::Migration 2 | def change 3 | create_table :user_roles do |t| 4 | t.belongs_to :user 5 | t.belongs_to :role 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160519061004_create_categories.rb: -------------------------------------------------------------------------------- 1 | class CreateCategories < ActiveRecord::Migration 2 | def change 3 | create_table :categories do |t| 4 | t.string :name, null: false 5 | t.string :slug, null: false 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :categories, :slug, unique: true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20160519181120_create_project_categories.rb: -------------------------------------------------------------------------------- 1 | class CreateProjectCategories < ActiveRecord::Migration 2 | def change 3 | create_table :project_categories do |t| 4 | t.belongs_to :project 5 | t.belongs_to :category 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160520010146_add_description_to_categories.rb: -------------------------------------------------------------------------------- 1 | class AddDescriptionToCategories < ActiveRecord::Migration 2 | def change 3 | add_column :categories, :description, :text 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160520040950_add_indexes_and_foreign_keys_to_project_categories.rb: -------------------------------------------------------------------------------- 1 | class AddIndexesAndForeignKeysToProjectCategories < ActiveRecord::Migration 2 | def change 3 | add_index :project_categories, [:project_id, :category_id], unique: true 4 | add_foreign_key :project_categories, :projects, on_delete: :cascade 5 | add_foreign_key :project_categories, :categories, on_delete: :cascade 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20160520222346_create_project_roles.rb: -------------------------------------------------------------------------------- 1 | class CreateProjectRoles < ActiveRecord::Migration 2 | def change 3 | create_table :project_roles do |t| 4 | t.belongs_to :project 5 | t.belongs_to :role 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :project_roles, [:project_id, :role_id], unique: true 11 | add_foreign_key :project_roles, :projects, on_delete: :cascade 12 | add_foreign_key :project_roles, :roles, on_delete: :cascade 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20160520231546_create_project_skills.rb: -------------------------------------------------------------------------------- 1 | class CreateProjectSkills < ActiveRecord::Migration 2 | def change 3 | create_table :project_skills do |t| 4 | t.belongs_to :project 5 | t.belongs_to :skill 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :project_skills, [:project_id, :skill_id], unique: true 11 | add_foreign_key :project_skills, :projects, on_delete: :cascade 12 | add_foreign_key :project_skills, :skills, on_delete: :cascade 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20160520235218_create_user_categories.rb: -------------------------------------------------------------------------------- 1 | class CreateUserCategories < ActiveRecord::Migration 2 | def change 3 | create_table :user_categories do |t| 4 | t.belongs_to :user 5 | t.belongs_to :category 6 | 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :user_categories, [:user_id, :category_id], unique: true 11 | add_foreign_key :user_categories, :users, on_delete: :cascade 12 | add_foreign_key :user_categories, :categories, on_delete: :cascade 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20160602211946_add_state_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddStateToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :aasm_state, :string, default: "signed_up", null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160609202045_add_kind_to_roles.rb: -------------------------------------------------------------------------------- 1 | class AddKindToRoles < ActiveRecord::Migration 2 | def change 3 | add_column :roles, :kind, :string, null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160621003651_create_previews.rb: -------------------------------------------------------------------------------- 1 | class CreatePreviews < ActiveRecord::Migration 2 | def change 3 | create_table :previews do |t| 4 | t.text :body, null: false 5 | t.text :markdown, null: false 6 | 7 | t.belongs_to :user, index: true, foreign_key: true 8 | 9 | t.timestamps null: false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20160621003916_create_preview_user_mentions.rb: -------------------------------------------------------------------------------- 1 | class CreatePreviewUserMentions < ActiveRecord::Migration 2 | def change 3 | create_table :preview_user_mentions do |t| 4 | t.belongs_to :user, index: true, foreign_key: true, null: false 5 | t.belongs_to :preview, index: true, foreign_key: true, null: false 6 | 7 | t.string :username, null: false 8 | t.integer :start_index, null: false 9 | t.integer :end_index, null: false 10 | 11 | t.timestamps null: false 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20160621024455_remove_preview_fields_from_posts.rb: -------------------------------------------------------------------------------- 1 | class RemovePreviewFieldsFromPosts < ActiveRecord::Migration 2 | def change 3 | remove_column :posts, :body_preview, :string 4 | remove_column :posts, :markdown_preview, :string 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160621024928_remove_preview_fields_from_comments.rb: -------------------------------------------------------------------------------- 1 | class RemovePreviewFieldsFromComments < ActiveRecord::Migration 2 | def change 3 | remove_column :comments, :body_preview, :string 4 | remove_column :comments, :markdown_preview, :string 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160621031228_remove_status_from_user_mentions.rb: -------------------------------------------------------------------------------- 1 | class RemoveStatusFromUserMentions < ActiveRecord::Migration 2 | def change 3 | remove_column :comment_user_mentions, :status, :string, null: false, default: "preview" 4 | remove_column :post_user_mentions, :status, :string, null: false, default: "preview" 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160621203648_add_long_description_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddLongDescriptionToProjects < ActiveRecord::Migration 2 | def change 3 | add_column :projects, :long_description_body, :text 4 | add_column :projects, :long_description_markdown, :text 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160623044025_add_open_and_closed_posts_count_to_projects.rb: -------------------------------------------------------------------------------- 1 | class AddOpenAndClosedPostsCountToProjects < ActiveRecord::Migration 2 | def change 3 | add_column :projects, :open_posts_count, :integer, null: false, default: 0 4 | add_column :projects, :closed_posts_count, :integer, null: false, default: 0 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160624065209_create_imports.rb: -------------------------------------------------------------------------------- 1 | class CreateImports < ActiveRecord::Migration 2 | def change 3 | create_table :imports do |t| 4 | t.attachment :file 5 | t.integer :status, default: 0 6 | 7 | t.timestamps null: false 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160625224912_add_code_theme_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddCodeThemeToUsers < ActiveRecord::Migration 2 | def change 3 | add_column :users, :theme, :string, default: "light", null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160626043812_add_mapping_to_skills_and_roles.rb: -------------------------------------------------------------------------------- 1 | class AddMappingToSkillsAndRoles < ActiveRecord::Migration 2 | def change 3 | add_column :skills, :original_row, :integer 4 | add_column :role_skills, :cat, :integer 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160626075820_add_slug_to_skills.rb: -------------------------------------------------------------------------------- 1 | class AddSlugToSkills < ActiveRecord::Migration 2 | def change 3 | add_column :skills, :slug, :string 4 | Skill.all.each do |skill| 5 | skill.update_attributes(slug: skill.title.parameterize) 6 | end 7 | change_column_null :skills, :slug, false 8 | 9 | add_index :skills, :slug, unique: true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160626090623_create_import_skill_failures.rb: -------------------------------------------------------------------------------- 1 | class CreateImportSkillFailures < ActiveRecord::Migration 2 | def change 3 | create_table :import_skill_failures do |t| 4 | t.belongs_to :import, null: false 5 | t.belongs_to :skill, null: true 6 | 7 | t.json :data, null: false 8 | t.text :issues, null: false, array: true 9 | 10 | t.timestamps null: false 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20160705042501_split_names.rb: -------------------------------------------------------------------------------- 1 | require "full-name-splitter" 2 | 3 | class SplitNames < ActiveRecord::Migration 4 | def change 5 | add_column :users, :first_name, :text 6 | add_column :users, :last_name, :text 7 | 8 | reversible do |dir| 9 | User.reset_column_information 10 | User.all.each do |u| 11 | dir.up { u.first_name, u.last_name = FullNameSplitter.split(u.name) } 12 | dir.down { u.name = "#{u.first_name} #{u.last_name}" } 13 | u.save 14 | end 15 | end 16 | 17 | revert { add_column :users, :name, :text } 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /db/migrate/20160705185815_add_url_protocol_to_user_websites.rb: -------------------------------------------------------------------------------- 1 | class AddUrlProtocolToUserWebsites < ActiveRecord::Migration 2 | def change 3 | User.find_each(&:save) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | Doorkeeper::Application.create! :name => "Code Corps Ember", :redirect_uri => "urn:ietf:wg:oauth:2.0:oob" -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/lib/assets/.keep -------------------------------------------------------------------------------- /lib/code_corps/base64_image_decoder.rb: -------------------------------------------------------------------------------- 1 | class Base64ImageDecoder 2 | DATA_URI_REGEX = %r{^data:image\/[^;]+;base64,} 3 | 4 | def self.decode(base64_string) 5 | base64_string.gsub!(DATA_URI_REGEX, "") 6 | data = StringIO.new(Base64.decode64(base64_string)) 7 | data.class.class_eval { attr_accessor :original_filename, :content_type } 8 | data.original_filename = SecureRandom.hex + ".png" 9 | data.content_type = "image/png" 10 | data 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/code_corps/base64_image_matcher.rb: -------------------------------------------------------------------------------- 1 | class Base64ImageMatcher 2 | BASE64_REGEX = /^data:image\/(png|jpg|gif|jpeg|pjpeg|x-png);base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/ 3 | 4 | def match?(base64_string) 5 | BASE64_REGEX =~ base64_string ? true : false 6 | end 7 | end -------------------------------------------------------------------------------- /lib/code_corps/github_repository_url_parser.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | class GithubRepositoryUrlParser 3 | def initialize(url) 4 | @url = url 5 | end 6 | 7 | def owner_name 8 | return unless @url.present? 9 | 10 | owner_name = @url.split("/")[-2] 11 | 12 | possible_prefix = "git@github.com:" 13 | owner_name.sub!(possible_prefix,"") 14 | 15 | owner_name 16 | end 17 | 18 | def repository_name 19 | return unless @url.present? 20 | 21 | repo_name_with_extension = @url.split("/").last 22 | repo_name_without_extension = repo_name_with_extension.sub(".git", "") 23 | 24 | repo_name_without_extension 25 | end 26 | 27 | def slug 28 | "#{organization}/#{name}" 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/code_corps/scenario/generate_notifications_for_comment_user_mentions.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | module Scenario 3 | class GenerateNotificationsForCommentUserMentions 4 | def initialize(comment) 5 | @comment = comment 6 | end 7 | 8 | def call 9 | ActiveRecord::Base.transaction do 10 | mentions = CommentUserMention.includes(:user).where(comment: @comment) 11 | mentions.each do |mention| 12 | Notification.find_or_create_by!(notifiable: @comment, user: mention.user) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/code_corps/scenario/generate_notifications_for_post_user_mentions.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | module Scenario 3 | class GenerateNotificationsForPostUserMentions 4 | def initialize(post) 5 | @post = post 6 | end 7 | 8 | def call 9 | ActiveRecord::Base.transaction do 10 | mentions = PostUserMention.includes(:user).where(post: @post) 11 | mentions.each do |mention| 12 | Notification.find_or_create_by!(notifiable: @post, user: mention.user) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/code_corps/scenario/notify_pusher_of_comment_image.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | module Scenario 3 | class NotifyPusherOfCommentImage 4 | def initialize(comment_image) 5 | @comment_image = comment_image 6 | end 7 | 8 | def call 9 | Pusher.trigger(channel, 'comment_image_uploaded', data) 10 | end 11 | 12 | private 13 | 14 | def user_id 15 | @comment_image.user.id 16 | end 17 | 18 | def comment_id 19 | @comment_image.comment.id 20 | end 21 | 22 | def channel 23 | "private-user-#{user_id}" 24 | end 25 | 26 | def data 27 | { 28 | comment_id: comment_id, 29 | user_id: user_id, 30 | filename: @comment_image.filename, 31 | url: @comment_image.image.url 32 | } 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/code_corps/scenario/notify_pusher_of_post_image.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | module Scenario 3 | class NotifyPusherOfPostImage 4 | def initialize(post_image) 5 | @post_image = post_image 6 | end 7 | 8 | def call 9 | Pusher.trigger(channel, 'post_image_uploaded', data) 10 | end 11 | 12 | private 13 | 14 | def user_id 15 | @post_image.user.id 16 | end 17 | 18 | def post_id 19 | @post_image.post.id 20 | end 21 | 22 | def channel 23 | "private-user-#{user_id}" 24 | end 25 | 26 | def data 27 | { 28 | post_id: post_id, 29 | user_id: user_id, 30 | filename: @post_image.filename, 31 | url: @post_image.image.url 32 | } 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/code_corps/scenario/send_notification_emails.rb: -------------------------------------------------------------------------------- 1 | module CodeCorps 2 | module Scenario 3 | class SendNotificationEmails 4 | 5 | def initialize(notifiable) 6 | @notifiable = notifiable 7 | end 8 | 9 | def call 10 | Notification.pending.includes(:user, :notifiable).where(notifiable: @notifiable).each do |notification| 11 | NotificationMailer.notify(notification).deliver_now 12 | notification.dispatch! 13 | end 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/code_corps/slug_matcher.rb: -------------------------------------------------------------------------------- 1 | class SlugMatcher 2 | def match?(slug) 3 | /\A((?:(?:(?:[^-\W]-?))*)(?:(?:(?:[^-\W]-?))*)\w+)\z/ =~ slug ? true : false 4 | end 5 | end -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/lib/tasks/.keep -------------------------------------------------------------------------------- /lib/tasks/db_exists.rake: -------------------------------------------------------------------------------- 1 | namespace :db do 2 | desc "Checks to see if the database exists" 3 | task :exists do 4 | begin 5 | Rake::Task["environment"].invoke 6 | ActiveRecord::Base.connection 7 | rescue 8 | exit 1 9 | else 10 | exit 0 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/tasks/subscribe_users_to_mailing_list.rake: -------------------------------------------------------------------------------- 1 | # lib/tasks/subscribe_users_to_mailing_list.rake 2 | desc "Subscribe users to the mailing list" 3 | task subscribe_users_to_mailing_list: :environment do 4 | User.find_each do |user| 5 | SubscribeToMailingListWorker.perform_async(user.id) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /spec/factories/category_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: categories 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # slug :string not null 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # description :text 11 | # 12 | 13 | FactoryGirl.define do 14 | factory :category do 15 | sequence(:name) { |n| "Category #{n}" } 16 | sequence(:description) { |n| "Category #{n} description" } 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/factories/comment_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comments 4 | # 5 | # id :integer not null, primary key 6 | # body :text 7 | # user_id :integer not null 8 | # post_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # markdown :text 12 | # aasm_state :string 13 | # 14 | 15 | FactoryGirl.define do 16 | factory :comment do 17 | sequence(:markdown) { |n| "Comment #{n}" } 18 | 19 | association :post 20 | association :user 21 | 22 | trait :published do 23 | aasm_state :published 24 | markdown "Comment content" 25 | body "Comment content" 26 | end 27 | 28 | trait :edited do 29 | aasm_state :edited 30 | markdown "Comment content" 31 | body "Comment content" 32 | end 33 | 34 | trait :with_user_mentions do 35 | transient do 36 | mention_count 5 37 | end 38 | 39 | after :create do |comment, evaluator| 40 | create_list(:comment_user_mention, evaluator.mention_count, comment: comment) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /spec/factories/comment_image_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_images 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # filename :text not null 9 | # base64_photo_data :text not null 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # image_file_name :string 13 | # image_content_type :string 14 | # image_file_size :integer 15 | # image_updated_at :datetime 16 | # 17 | 18 | FactoryGirl.define do 19 | 20 | factory :comment_image do 21 | association :user 22 | association :comment 23 | 24 | trait :with_s3_image do 25 | after(:build) do |comment_image, evaluator| 26 | comment_image.image_file_name = 'comment_image.jpg' 27 | comment_image.image_content_type = 'image/jpeg' 28 | comment_image.image_file_size = 1024 29 | comment_image.image_updated_at = Time.now 30 | end 31 | end 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /spec/factories/comment_user_mention_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: comment_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # comment_id :integer not null 8 | # post_id :integer not null 9 | # username :string not null 10 | # start_index :integer not null 11 | # end_index :integer not null 12 | # created_at :datetime not null 13 | # updated_at :datetime not null 14 | # 15 | 16 | FactoryGirl.define do 17 | factory :comment_user_mention do 18 | association :user 19 | association :comment 20 | association :post 21 | 22 | sequence(:start_index) { |n| n } 23 | sequence(:end_index) { |n| n } 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/factories/github_repository_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: github_repositories 4 | # 5 | # id :integer not null, primary key 6 | # repository_name :string not null 7 | # owner_name :string not null 8 | # project_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | FactoryGirl.define do 14 | 15 | factory :github_repository do 16 | sequence(:owner_name) { |n| "owner#{n}" } 17 | sequence(:repository_name) { |n| "repository#{n}" } 18 | 19 | association :project 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /spec/factories/import_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: imports 4 | # 5 | # id :integer not null, primary key 6 | # file_file_name :string 7 | # file_content_type :string 8 | # file_file_size :integer 9 | # file_updated_at :datetime 10 | # status :integer default(0) 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | FactoryGirl.define do 16 | factory :import do 17 | status :unprocessed 18 | file { File.new(Rails.root.join("spec", "sample_data", "import.csv")) } 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/factories/import_skill_failure_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: import_skill_failures 4 | # 5 | # id :integer not null, primary key 6 | # import_id :integer not null 7 | # skill_id :integer 8 | # data :json not null 9 | # issues :text not null, is an Array 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | FactoryGirl.define do 15 | factory :import_skill_failure do 16 | association :skill 17 | association :import 18 | 19 | sequence(:issues) do |n| 20 | [ 21 | "First issue for import_skill_failure #{n}", 22 | "Second issue for import_skill_failure #{n}" 23 | ] 24 | end 25 | 26 | sequence(:data) do |n| 27 | { 28 | "Status" => "Categorize", 29 | "Batch" => "A", 30 | "Original Row" => "1", 31 | "Original Order" => "1", 32 | "Skill" => "Skill #{n}", 33 | "Cat 1" => "Backend Developer", 34 | "Cat 2" => "Architect", 35 | "Cat 3" => nil, 36 | "Cat 4" => nil, 37 | "Cat 5" => nil, 38 | "Cat 6" => nil 39 | } 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /spec/factories/notification_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: notifications 4 | # 5 | # id :integer not null, primary key 6 | # notifiable_id :integer not null 7 | # notifiable_type :string not null 8 | # user_id :integer not null 9 | # aasm_state :string 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | FactoryGirl.define do 15 | 16 | factory :notification do 17 | association :user 18 | association :notifiable, factory: :post 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /spec/factories/oauth_application_factory.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | 3 | factory :oauth_application, :class => Doorkeeper::Application do 4 | sequence(:name) { |n| "application_name_#{n}" } 5 | redirect_uri 'urn:ietf:wg:oauth:2.0:oob' 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /spec/factories/oauth_token_factory.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | 3 | factory :oauth_token, :class => Doorkeeper::AccessToken do 4 | association :application, :factory => :oauth_application 5 | association :resource_owner_id, :factory => :user 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /spec/factories/organization_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: organizations 4 | # 5 | # id :integer not null, primary key 6 | # name :string not null 7 | # created_at :datetime not null 8 | # updated_at :datetime not null 9 | # slug :string not null 10 | # icon_file_name :string 11 | # icon_content_type :string 12 | # icon_file_size :integer 13 | # icon_updated_at :datetime 14 | # base64_icon_data :text 15 | # description :text 16 | # 17 | 18 | FactoryGirl.define do 19 | 20 | factory :organization do 21 | sequence(:name) { |n| "Organization#{n}" } 22 | sequence(:description) { |n| "Organization description #{n}" } 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /spec/factories/organization_membership_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: organization_memberships 4 | # 5 | # id :integer not null, primary key 6 | # role :string default("pending"), not null 7 | # created_at :datetime not null 8 | # updated_at :datetime not null 9 | # member_id :integer 10 | # organization_id :integer 11 | # 12 | 13 | FactoryGirl.define do 14 | factory :organization_membership do |f| 15 | association :member, factory: :user 16 | association :organization 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/factories/post_image_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_images 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # filename :text not null 9 | # base64_photo_data :text not null 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # image_file_name :string 13 | # image_content_type :string 14 | # image_file_size :integer 15 | # image_updated_at :datetime 16 | # 17 | 18 | FactoryGirl.define do 19 | 20 | factory :post_image do 21 | association :user 22 | association :post 23 | 24 | trait :with_s3_image do 25 | after(:build) do |post_image, evaluator| 26 | post_image.image_file_name = "post_image.jpg" 27 | post_image.image_content_type = "image/jpeg" 28 | post_image.image_file_size = 1024 29 | post_image.image_updated_at = Time.now 30 | end 31 | end 32 | 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /spec/factories/post_like_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_likes 4 | # 5 | # id :integer not null, primary key 6 | # post_id :integer 7 | # user_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | 14 | factory :post_like do 15 | after(:build) do |post, evaluator| 16 | post.user = evaluator.user || build(:user) 17 | post.post = evaluator.post || build(:post) 18 | end 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /spec/factories/post_user_mention_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_user_mentions 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer not null 7 | # post_id :integer not null 8 | # username :string not null 9 | # start_index :integer not null 10 | # end_index :integer not null 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | FactoryGirl.define do 16 | factory :post_user_mention do 17 | association :user 18 | association :post 19 | 20 | sequence(:start_index) { |n| n } 21 | sequence(:end_index) { |n| n } 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/factories/preview_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: previews 4 | # 5 | # id :integer not null, primary key 6 | # body :text not null 7 | # markdown :text not null 8 | # user_id :integer 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | FactoryGirl.define do 14 | factory :preview do 15 | sequence(:markdown) { |n| "Post content #{n}" } 16 | 17 | association :user 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/factories/preview_user_mention.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :preview_user_mention do 3 | association :user 4 | association :preview 5 | 6 | sequence(:start_index) { |n| n } 7 | sequence(:end_index) { |n| n } 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/factories/project_category_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_categories 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :project_category do 14 | association :project 15 | association :category 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/factories/project_role.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :project_role do 3 | association :project 4 | association :role 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /spec/factories/project_skill_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_skills 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :project_skill do 14 | association :project 15 | association :skill 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/factories/role_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: roles 4 | # 5 | # id :integer not null, primary key 6 | # created_at :datetime not null 7 | # updated_at :datetime not null 8 | # name :string not null 9 | # ability :string not null 10 | # kind :string not null 11 | # 12 | 13 | FactoryGirl.define do 14 | factory :role do 15 | sequence(:name) { |n| "Role #{n}" } 16 | sequence(:ability) { |n| "Ability #{n}" } 17 | kind "technology" 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/factories/role_skill_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: role_skills 4 | # 5 | # id :integer not null, primary key 6 | # role_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # cat :integer 11 | # 12 | 13 | FactoryGirl.define do 14 | factory :role_skill do 15 | association :role 16 | association :skill 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/factories/skill_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: skills 4 | # 5 | # id :integer not null, primary key 6 | # title :string not null 7 | # description :string 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # original_row :integer 11 | # slug :string not null 12 | # 13 | 14 | FactoryGirl.define do 15 | factory :skill do 16 | sequence(:title) { |n| "Skill #{n}" } 17 | sequence(:description) { |n| "Skill description #{n}" } 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/factories/user_category_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_categories 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :user_category do 14 | association :user 15 | association :category 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/factories/user_relationship_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_relationships 4 | # 5 | # id :integer not null, primary key 6 | # follower_id :integer 7 | # following_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :user_relationship do |f| 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/factories/user_role_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_roles 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :user_role do 14 | association :user 15 | association :role 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/factories/user_skill_factory.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_skills 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | FactoryGirl.define do 13 | factory :user_skill do 14 | association :user 15 | association :skill 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/lib/code_corps/scenario/generate_preview_mentions_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | require "code_corps/scenario/generate_preview_mentions" 3 | 4 | module CodeCorps 5 | module Scenario 6 | describe GeneratePreviewMentions do 7 | describe "#call" do 8 | let(:user) { create(:user, username: "joshsmith") } 9 | let(:preview) { create(:preview) } 10 | 11 | before do 12 | # need to disable the default after save hook which generates mentions 13 | allow_any_instance_of(Preview).to receive(:generate_mentions) 14 | end 15 | 16 | it "creates user mentions from body when publishing" do 17 | preview.markdown = "Mentioning @#{user.username}" 18 | preview.save 19 | 20 | GeneratePreviewMentions.new(preview).call 21 | 22 | mention = PreviewUserMention.last 23 | expect(mention.preview).to eq preview 24 | expect(mention.user).to eq user 25 | expect(mention.username).to eq user.username 26 | end 27 | 28 | it "does not fail when content is nil" do 29 | preview.markdown = nil 30 | preview.save 31 | expect { GeneratePreviewMentions.new(preview).call }.not_to raise_error 32 | end 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/lib/code_corps/scenario/notify_pusher_of_comment_image_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | require "code_corps/scenario/notify_pusher_of_comment_image" 3 | 4 | module CodeCorps 5 | module Scenario 6 | describe NotifyPusherOfCommentImage, :local_skip do 7 | 8 | let(:gif_string) { 9 | file = File.open("#{Rails.root}/spec/sample_data/base64_images/gif.txt", 'r') 10 | open(file) { |io| io.read } 11 | } 12 | let(:comment_image) { create(:comment_image, :with_s3_image, filename: "jake.gif", base64_photo_data: gif_string) } 13 | 14 | describe "#call" do 15 | 16 | it "notifies pusher", vcr: { cassette_name: "lib/code_corps/scenario/notify_pusher_of_comment_image" } do 17 | data = { 18 | comment_id: comment_image.comment.id, 19 | user_id: comment_image.user.id, 20 | filename: comment_image.filename, 21 | url: comment_image.image.url 22 | } 23 | 24 | expect_any_instance_of(Pusher::Client).to receive(:trigger).with( 25 | "private-user-#{comment_image.user.id}", 26 | 'comment_image_uploaded', 27 | data 28 | ) 29 | 30 | NotifyPusherOfCommentImage.new(comment_image).call 31 | end 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/lib/code_corps/scenario/notify_pusher_of_post_image_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | require "code_corps/scenario/notify_pusher_of_post_image" 3 | 4 | module CodeCorps 5 | module Scenario 6 | describe NotifyPusherOfPostImage, :local_skip do 7 | 8 | let(:gif_string) { 9 | file = File.open("#{Rails.root}/spec/sample_data/base64_images/gif.txt", 'r') 10 | open(file) { |io| io.read } 11 | } 12 | let(:post_image) { create(:post_image, :with_s3_image, filename: "jake.gif", base64_photo_data: gif_string) } 13 | 14 | describe "#call" do 15 | 16 | it "notifies pusher", vcr: { cassette_name: "lib/code_corps/scenario/notify_pusher_of_post_image" } do 17 | data = { 18 | post_id: post_image.post.id, 19 | user_id: post_image.user.id, 20 | filename: post_image.filename, 21 | url: post_image.image.url 22 | } 23 | 24 | expect_any_instance_of(Pusher::Client).to receive(:trigger).with( 25 | "private-user-#{post_image.user.id}", 26 | 'post_image_uploaded', 27 | data 28 | ) 29 | 30 | NotifyPusherOfPostImage.new(post_image).call 31 | end 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/mailers/notification_mailer_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe NotificationMailer do 4 | describe "notify" do 5 | let(:notification) { create(:notification) } 6 | let(:mail) { NotificationMailer.notify(notification) } 7 | let(:author) { notification.notifiable.user} 8 | 9 | it "renders the subject" do 10 | expect(mail.subject).to eql("You have been mentioned in a post") 11 | end 12 | 13 | it "renders the receiver email" do 14 | expect(mail.to).to eql([notification.user.email]) 15 | end 16 | 17 | it "renders the sender email" do 18 | expect(mail.from).to eql(["notifications@example.com"]) 19 | end 20 | 21 | it "renders author name in the body" do 22 | expect(mail.body.encoded).to match(author.username) 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/models/github_repository_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: github_repositories 4 | # 5 | # id :integer not null, primary key 6 | # repository_name :string not null 7 | # owner_name :string not null 8 | # project_id :integer not null 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | require 'rails_helper' 14 | 15 | describe GithubRepository, type: :model do 16 | describe "schema" do 17 | it { should have_db_column(:owner_name).of_type(:string).with_options(null: false) } 18 | it { should have_db_column(:repository_name).of_type(:string).with_options(null: false) } 19 | it { should have_db_column(:project_id).of_type(:integer).with_options(null: false) } 20 | end 21 | 22 | describe "relationships" do 23 | it { should belong_to :project } 24 | end 25 | 26 | describe "validations" do 27 | it { should validate_presence_of(:project) } 28 | it { should validate_presence_of(:owner_name) } 29 | it { should validate_presence_of(:repository_name) } 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/models/import_skill_failure_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: import_skill_failures 4 | # 5 | # id :integer not null, primary key 6 | # import_id :integer not null 7 | # skill_id :integer 8 | # data :json not null 9 | # issues :text not null, is an Array 10 | # created_at :datetime not null 11 | # updated_at :datetime not null 12 | # 13 | 14 | require "rails_helper" 15 | 16 | describe ImportSkillFailure, type: :model do 17 | describe "schema" do 18 | it { should have_db_column(:data).of_type(:json).with_options(null: false) } 19 | it { should have_db_column(:issues).of_type(:text).with_options(null: false) } 20 | 21 | it { should have_db_column(:updated_at) } 22 | it { should have_db_column(:created_at) } 23 | end 24 | 25 | describe "relationships" do 26 | it { should belong_to(:import) } 27 | it { should belong_to(:skill) } 28 | end 29 | 30 | describe "validations" do 31 | it { should validate_presence_of(:import) } 32 | it { should validate_presence_of(:issues) } 33 | it { should validate_presence_of(:data) } 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/models/import_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: imports 4 | # 5 | # id :integer not null, primary key 6 | # file_file_name :string 7 | # file_content_type :string 8 | # file_file_size :integer 9 | # file_updated_at :datetime 10 | # status :integer default(0) 11 | # created_at :datetime not null 12 | # updated_at :datetime not null 13 | # 14 | 15 | require "rails_helper" 16 | 17 | describe Import, type: :model do 18 | describe "schema" do 19 | it { should have_db_column(:status).of_type(:integer) } 20 | end 21 | 22 | describe "paperclip" do 23 | it { should have_attached_file(:file) } 24 | it { should validate_attachment_content_type(:file).allowing("text/csv", "text/plain") } 25 | end 26 | 27 | describe "behavior" do 28 | it { should define_enum_for(:status).with([:unprocessed, :processed, :failed]) } 29 | end 30 | 31 | describe "after_create" do 32 | subject { create(:import) } 33 | 34 | it "calls perform method" do 35 | expect { subject }.to change(PerformImportWorker.jobs, :size).by(1) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /spec/models/post_like_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: post_likes 4 | # 5 | # id :integer not null, primary key 6 | # post_id :integer 7 | # user_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require 'rails_helper' 13 | 14 | describe PostLike, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:post_id).of_type(:integer) } 17 | it { should have_db_column(:user_id).of_type(:integer) } 18 | it { should have_db_column(:updated_at) } 19 | it { should have_db_column(:created_at) } 20 | end 21 | 22 | describe "relationships" do 23 | it { should belong_to(:post).counter_cache true } 24 | it { should belong_to(:user) } 25 | end 26 | 27 | describe "validations" do 28 | it { should validate_presence_of :user } 29 | it { should validate_presence_of :post } 30 | it { should validate_uniqueness_of(:post_id).scoped_to(:user_id) } 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /spec/models/project_category_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_categories 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require "rails_helper" 13 | 14 | RSpec.describe ProjectCategory, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:project_id).of_type(:integer) } 17 | it { should have_db_column(:category_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:project) } 22 | it { should belong_to(:category) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :project } 27 | it { should validate_presence_of :category } 28 | 29 | describe "uniquness" do 30 | subject { create(:project_category) } 31 | 32 | it { should validate_uniqueness_of(:project_id).scoped_to(:category_id) } 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/models/project_role_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_roles 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require "rails_helper" 13 | 14 | RSpec.describe ProjectRole, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:project_id).of_type(:integer) } 17 | it { should have_db_column(:role_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:project) } 22 | it { should belong_to(:role) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :project } 27 | it { should validate_presence_of :role } 28 | 29 | describe "uniquness" do 30 | subject { create(:project_role) } 31 | 32 | it { should validate_uniqueness_of(:project_id).scoped_to(:role_id) } 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/models/project_skill_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: project_skills 4 | # 5 | # id :integer not null, primary key 6 | # project_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require "rails_helper" 13 | 14 | RSpec.describe ProjectSkill, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:project_id).of_type(:integer) } 17 | it { should have_db_column(:skill_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:project) } 22 | it { should belong_to(:skill) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :project } 27 | it { should validate_presence_of :skill } 28 | 29 | describe "uniquness" do 30 | subject { create(:project_skill) } 31 | 32 | it { should validate_uniqueness_of(:project_id).scoped_to(:skill_id) } 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/models/role_skill_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: role_skills 4 | # 5 | # id :integer not null, primary key 6 | # role_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # cat :integer 11 | # 12 | 13 | require "rails_helper" 14 | 15 | RSpec.describe RoleSkill, type: :model do 16 | describe "schema" do 17 | it { should have_db_column(:role_id).of_type(:integer) } 18 | it { should have_db_column(:skill_id).of_type(:integer) } 19 | end 20 | 21 | describe "relationships" do 22 | it { should belong_to(:role) } 23 | it { should belong_to(:skill) } 24 | end 25 | 26 | describe "validations" do 27 | it { should validate_presence_of :role } 28 | it { should validate_presence_of :skill } 29 | it { should validate_uniqueness_of(:role_id).scoped_to(:skill_id) } 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/models/slugged_route_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: slugged_routes 4 | # 5 | # id :integer not null, primary key 6 | # slug :string not null 7 | # owner_id :integer 8 | # owner_type :string 9 | # created_at :datetime not null 10 | # updated_at :datetime not null 11 | # 12 | 13 | require "rails_helper" 14 | 15 | describe SluggedRoute, type: :model do 16 | describe "schema" do 17 | it { should have_db_column(:slug).of_type(:string) } 18 | it { should have_db_column(:owner_id).of_type(:integer) } 19 | it { should have_db_column(:owner_type).of_type(:string) } 20 | end 21 | 22 | describe "relationships" do 23 | it { should belong_to(:owner) } 24 | end 25 | 26 | describe "validations" do 27 | it_behaves_like "a slug validating model", :slug 28 | 29 | describe "slug" do 30 | it { should validate_presence_of(:slug) } 31 | it { should validate_uniqueness_of(:slug).case_insensitive } 32 | it { should validate_exclusion_of(:slug).in_array(Rails.configuration.x.reserved_routes) } 33 | 34 | Rails.configuration.x.reserved_routes.each do |route| 35 | it { should_not allow_value(route).for(:slug) } 36 | end 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /spec/models/user_category_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_categories 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # category_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require "rails_helper" 13 | 14 | RSpec.describe UserCategory, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:user_id).of_type(:integer) } 17 | it { should have_db_column(:category_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:user) } 22 | it { should belong_to(:category) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :user } 27 | it { should validate_presence_of :category } 28 | 29 | describe "uniquness" do 30 | subject { create(:user_category) } 31 | 32 | it { should validate_uniqueness_of(:user_id).scoped_to(:category_id) } 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/models/user_relationship_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_relationships 4 | # 5 | # id :integer not null, primary key 6 | # follower_id :integer 7 | # following_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require 'rails_helper' 13 | 14 | describe UserRelationship, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:follower_id) } 17 | it { should have_db_column(:following_id) } 18 | 19 | it { should have_db_index(:follower_id) } 20 | it { should have_db_index(:following_id) } 21 | 22 | it { should have_db_column(:created_at) } 23 | it { should have_db_column(:updated_at) } 24 | end 25 | 26 | describe "relationships" do 27 | it { should belong_to(:follower).class_name("User") } 28 | it { should belong_to(:following).class_name("User") } 29 | end 30 | 31 | describe "validations" do 32 | it { should validate_presence_of(:follower) } 33 | it { should validate_presence_of(:following) } 34 | it { should validate_uniqueness_of(:follower_id).scoped_to(:following_id) } 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/models/user_role_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_roles 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # role_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require "rails_helper" 13 | 14 | RSpec.describe UserRole, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:user_id).of_type(:integer) } 17 | it { should have_db_column(:role_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:user) } 22 | it { should belong_to(:role) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :user } 27 | it { should validate_presence_of :role } 28 | it { should validate_uniqueness_of(:user_id).scoped_to(:role_id) } 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/models/user_skill_spec.rb: -------------------------------------------------------------------------------- 1 | # == Schema Information 2 | # 3 | # Table name: user_skills 4 | # 5 | # id :integer not null, primary key 6 | # user_id :integer 7 | # skill_id :integer 8 | # created_at :datetime not null 9 | # updated_at :datetime not null 10 | # 11 | 12 | require 'rails_helper' 13 | 14 | describe UserSkill, type: :model do 15 | describe "schema" do 16 | it { should have_db_column(:user_id).of_type(:integer) } 17 | it { should have_db_column(:skill_id).of_type(:integer) } 18 | end 19 | 20 | describe "relationships" do 21 | it { should belong_to(:user) } 22 | it { should belong_to(:skill) } 23 | end 24 | 25 | describe "validations" do 26 | it { should validate_presence_of :user } 27 | it { should validate_presence_of :skill } 28 | it { should validate_uniqueness_of(:user_id).scoped_to(:skill_id) } 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/policies/comment_image_policy_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe CommentImagePolicy do 4 | subject { described_class } 5 | 6 | let(:comment) { build_stubbed(:comment) } 7 | 8 | let(:gif_string) do 9 | open( 10 | File.open( 11 | "#{Rails.root}/spec/sample_data/base64_images/gif.txt", "r" 12 | ), 13 | &:read 14 | ) 15 | end 16 | 17 | let(:comment_image) do 18 | build_stubbed( 19 | :comment_image, 20 | :with_s3_image, 21 | filename: "jake.gif", 22 | base64_photo_data: gif_string, 23 | comment: comment, 24 | user: user 25 | ) 26 | end 27 | 28 | let(:user) { build_stubbed(:user) } 29 | 30 | permissions :create? do 31 | it "is not permitted when no user is present" do 32 | expect(subject).not_to permit(nil, comment_image) 33 | end 34 | 35 | it "is not permitted when not the same user" do 36 | expect(subject).not_to permit(user, comment_image) 37 | end 38 | 39 | it "is permitted when comment belongs to the user" do 40 | expect(subject).to permit(comment.user, comment_image) 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /spec/policies/comment_user_mention_policy_spec.rb: -------------------------------------------------------------------------------- 1 | describe CommentUserMentionPolicy do 2 | subject { described_class } 3 | 4 | permissions :index? do 5 | it "is permited for anyone" do 6 | expect(subject).to permit(nil, nil) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/policies/import_policy_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe ImportPolicy do 4 | subject { described_class } 5 | 6 | permissions :create? do 7 | context "user is not admin" do 8 | let(:user) { create(:user) } 9 | 10 | it "denies permission" do 11 | expect(subject).not_to permit(user, Import.new) 12 | end 13 | end 14 | 15 | context "user is an admin" do 16 | let(:user) { create(:user, :admin) } 17 | 18 | it "allows permission" do 19 | expect(subject).to permit(user, Import.new) 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/policies/import_skill_failure_policy_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe ImportSkillFailurePolicy do 4 | subject { described_class } 5 | 6 | permissions :index? do 7 | context "user is not admin" do 8 | let(:user) { create(:user) } 9 | 10 | it "denies permission" do 11 | expect(subject).not_to permit(user, ImportSkillFailure) 12 | end 13 | end 14 | 15 | context "user is an admin" do 16 | let(:user) { create(:user, :admin) } 17 | 18 | it "allows permission" do 19 | expect(subject).to permit(user, ImportSkillFailure) 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/policies/post_user_mention_policy_spec.rb: -------------------------------------------------------------------------------- 1 | describe PostUserMentionPolicy do 2 | subject { described_class } 3 | 4 | permissions :index? do 5 | it "is permited for anyone" do 6 | expect(subject).to permit(nil, nil) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/policies/preview_user_mention_policy_spec.rb: -------------------------------------------------------------------------------- 1 | describe PreviewUserMentionPolicy do 2 | subject { described_class } 3 | 4 | permissions :index? do 5 | it "is permited for anyone" do 6 | expect(subject).to permit(nil, nil) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/policies/slugged_route_policy_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe SluggedRoutePolicy do 4 | subject { described_class } 5 | 6 | let(:organization) { build_stubbed(:organization) } 7 | 8 | permissions :show? do 9 | it "is permited for anyone" do 10 | expect(subject).to permit(nil, organization.slugged_route) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/requests/api/comment_user_mentions_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe "CommentUserMentions API", :json_api do 4 | context "GET /comment_user_mentions/" do 5 | let(:comment_a) do 6 | comment = create(:comment) 7 | create_list(:comment_user_mention, 4, comment: comment) 8 | comment 9 | end 10 | 11 | let(:comment_b) do 12 | comment = create(:comment) 13 | create_list(:comment_user_mention, 1, comment: comment) 14 | comment 15 | end 16 | 17 | def make_request_for_comment(comment) 18 | get "#{host}/comment_user_mentions/", comment_id: comment.id 19 | end 20 | 21 | it "fetches mentions of specified status for specified comment" do 22 | make_request_for_comment(comment_a) 23 | expect(last_response.status).to eq 200 24 | expect(json).to( 25 | serialize_collection(comment_a.comment_user_mentions.all). 26 | with(CommentUserMentionSerializer) 27 | ) 28 | make_request_for_comment(comment_b) 29 | expect(last_response.status).to eq 200 30 | expect(json).to( 31 | serialize_collection(comment_b.comment_user_mentions.all). 32 | with(CommentUserMentionSerializer) 33 | ) 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/requests/api/oauth_applications_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | describe "OAuth Applications API" do 4 | 5 | it 'does not show the oauth applications page when unauthed' do 6 | get "#{host}/oauth/applications" 7 | 8 | expect(last_response.status).to eq 401 9 | end 10 | 11 | end -------------------------------------------------------------------------------- /spec/requests/api/ping_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | describe "Ping API" do 4 | 5 | let(:token) { authenticate(email: "josh@coderly.com", password: "password") } 6 | 7 | it 'gets a pong when pinging unauthed' do 8 | get "#{host}/ping" 9 | 10 | expect(last_response.status).to eq 200 11 | expect(json.ping).to eq "pong" 12 | end 13 | 14 | it 'pongs the user email when authed' do 15 | create(:user, email: "josh@coderly.com", password: "password") 16 | 17 | authenticated_get "ping", nil, token 18 | 19 | expect(last_response.status).to eq 200 20 | expect(json.ping).to eq "josh@coderly.com" 21 | end 22 | 23 | end -------------------------------------------------------------------------------- /spec/requests/api/post_user_mentions_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe "PostUserMentions API", :json_api do 4 | context "GET /post_user_mentions/" do 5 | let(:post_a) do 6 | post = create(:post) 7 | create_list(:post_user_mention, 4, post: post) 8 | post 9 | end 10 | 11 | let(:post_b) do 12 | post = create(:post) 13 | create_list(:post_user_mention, 1, post: post) 14 | post 15 | end 16 | 17 | def make_request_for_post(post) 18 | get "#{host}/post_user_mentions/", post_id: post.id 19 | end 20 | 21 | it "fetches mentions of specified status for specified post" do 22 | make_request_for_post(post_a) 23 | expect(last_response.status).to eq 200 24 | expect(json).to( 25 | serialize_collection(post_a.post_user_mentions.all). 26 | with(PostUserMentionSerializer) 27 | ) 28 | 29 | make_request_for_post(post_b) 30 | expect(last_response.status).to eq 200 31 | expect(json).to( 32 | serialize_collection(post_b.post_user_mentions.all). 33 | with(PostUserMentionSerializer) 34 | ) 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /spec/requests/api/preview_user_mentions_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe "PreviewUserMentions API", :json_api do 4 | context "GET /preview_user_mentions/" do 5 | def make_request_for_preview(preview) 6 | get "#{host}/preview_user_mentions/", preview_id: preview.id 7 | end 8 | 9 | let(:preview_a) { create(:preview) } 10 | let(:preview_b) { create(:preview) } 11 | 12 | before do 13 | create_list(:preview_user_mention, 4, preview: preview_a) 14 | create_list(:preview_user_mention, 1, preview: preview_b) 15 | end 16 | 17 | it "fetches mentions of specified status for specified post" do 18 | make_request_for_preview(preview_a) 19 | expect(last_response.status).to eq 200 20 | expect(json). 21 | to serialize_collection(preview_a.preview_user_mentions.all). 22 | with(PreviewUserMentionSerializer) 23 | 24 | make_request_for_preview(preview_b) 25 | expect(last_response.status).to eq 200 26 | expect(json). 27 | to serialize_collection(preview_b.preview_user_mentions.all). 28 | with(PreviewUserMentionSerializer) 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/sample_data/default-avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-corps/deprecated-code-corps-rails-api/cc55169a2a63da5a01c8df2ab0c4899b463abd4d/spec/sample_data/default-avatar.png -------------------------------------------------------------------------------- /spec/sample_data/import.csv: -------------------------------------------------------------------------------- 1 | Status,Batch,Original Row,Original Order,Skill,Cat 1,Cat 2,Cat 3,Cat 4,Cat 5,Cat 6 2 | Categorize,A,1,1,Ruby,Backend Developer,Architect,,,, 3 | Reject - QA,A,2,2,Pottery,,,,,, -------------------------------------------------------------------------------- /spec/support/aws.rb: -------------------------------------------------------------------------------- 1 | Aws.config[:stub_responses] = true 2 | -------------------------------------------------------------------------------- /spec/support/helpers/api_helpers.rb: -------------------------------------------------------------------------------- 1 | require 'oauth2' 2 | 3 | module ApiHelpers 4 | def authenticate(email:, password:) 5 | application = create(:oauth_application) 6 | 7 | client = OAuth2::Client.new(application.uid, application.secret) do |b| 8 | b.request :url_encoded 9 | b.adapter :rack, Rails.application 10 | end 11 | access_token = client.password.get_token(email, password) 12 | access_token.token 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/support/helpers/json_api_helpers.rb: -------------------------------------------------------------------------------- 1 | require "json" 2 | require "hashie/mash" 3 | 4 | module JsonApiHelpers 5 | JSON_API_HEADERS = { 6 | "CONTENT_TYPE" => "application/vnd.api+json; charset=utf-8" 7 | }.freeze 8 | 9 | # NOTE - GET and DELETE do not have a JSON api payload, so they 10 | # do not need a content type set 11 | # All others need to have the correct CONTENT_TYPE headers added 12 | # regardless of authentication, so we override the base request 13 | # helpers. 14 | 15 | def post(*args) 16 | super(*wrap_for_json_api(*args)) 17 | end 18 | 19 | def update(*args) 20 | super(*wrap_for_json_api(*args)) 21 | end 22 | 23 | def patch(*args) 24 | super(*wrap_for_json_api(*args)) 25 | end 26 | 27 | def put(*args) 28 | super(*wrap_for_json_api(*args)) 29 | end 30 | 31 | private 32 | 33 | def wrap_for_json_api(path, params = {}, headers = {}) 34 | # NOTE: without a params.to_json, the middleware encodes params 35 | # as form, which causes errors 36 | 37 | params ||= {} 38 | headers ||= {} 39 | 40 | [path, params.to_json, JSON_API_HEADERS.merge(headers)] 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /spec/support/matchers/cors_matchers.rb: -------------------------------------------------------------------------------- 1 | RSpec::Matchers.define :have_proper_cors_headers do 2 | match do |response| 3 | return response.headers["Access-Control-Allow-Origin"] == "*" 4 | end 5 | end 6 | 7 | RSpec::Matchers.define :have_proper_preflight_options_response_headers do 8 | match do |response| 9 | headers = response.headers 10 | return false unless headers["Access-Control-Allow-Origin"] == "*" 11 | return false unless headers["Access-Control-Allow-Methods"] == methods 12 | return false unless headers["Access-Control-Allow-Headers"] == "test" 13 | return false unless headers.key? "Access-Control-Max-Age" 14 | return true 15 | end 16 | 17 | def methods 18 | @method_string || "GET, POST, PATCH, OPTIONS, DELETE" 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/support/matchers/time_matchers.rb: -------------------------------------------------------------------------------- 1 | RSpec::Matchers.define :be_the_same_time_as do |expected| 2 | match do |actual| 3 | expect(Date.parse(expected.to_s)).to eq(Date.parse(actual)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/support/shared_examples/slug.rb: -------------------------------------------------------------------------------- 1 | RSpec.shared_examples "a slug validating model" do |column| 2 | it { should allow_value("code_corps").for(column) } 3 | it { should allow_value("codecorps").for(column) } 4 | it { should allow_value("codecorps12345").for(column) } 5 | it { should allow_value("code12345corps").for(column) } 6 | it { should allow_value("code____corps").for(column) } 7 | it { should allow_value("code-corps").for(column) } 8 | it { should allow_value("code-corps-corps").for(column) } 9 | it { should allow_value("code_corps_corps").for(column) } 10 | it { should allow_value("c").for(column) } 11 | it { should_not allow_value("-codecorps").for(column) } 12 | it { should_not allow_value("codecorps-").for(column) } 13 | it { should_not allow_value("@codecorps").for(column) } 14 | it { should_not allow_value("code----corps").for(column) } 15 | it { should_not allow_value("code/corps").for(column) } 16 | it { should_not allow_value("code_corps/code_corps").for(column) } 17 | it { should_not allow_value("code///corps").for(column) } 18 | it { should_not allow_value("@code/corps/code").for(column) } 19 | it { should_not allow_value("@code/corps/code/corps").for(column) } 20 | end 21 | -------------------------------------------------------------------------------- /spec/support/vcr.rb: -------------------------------------------------------------------------------- 1 | VCR.configure do |c| 2 | c.cassette_library_dir = Rails.root.join("spec", "vcr") 3 | c.hook_into :webmock 4 | c.configure_rspec_metadata! 5 | 6 | # Uncomment for debugging VCR 7 | # c.debug_logger = File.open("log/test.log", "w") 8 | 9 | c.allow_http_connections_when_no_cassette = false 10 | 11 | c.default_cassette_options = { :serialize_with => :psych } 12 | 13 | c.ignore_hosts "elasticsearch" 14 | 15 | ignore_localhost = true 16 | end 17 | -------------------------------------------------------------------------------- /spec/vcr/lib/code_corps/scenario/notify_pusher_of_post_image.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: http://127.0.0.1:54082/apps/160485/events?auth_key=7b0b034d6b2928e5c548&auth_signature=b979e39667c8991f1aef20a38fc1b8b1cee1f52f694c82e472a91dabd6f096c2&auth_timestamp=1449870749&auth_version=1.0&body_md5=8565fbd507a51483d08b65d755d199f7 6 | body: 7 | encoding: UTF-8 8 | string: '{"name":"post_image_uploaded","channels":["private-user-1"],"data":"{\"post_id\":1,\"user_id\":1,\"filename\":\"default-avatar.png\",\"url\":\"https://dawxes9syhrgg.cloudfront.net/posts/1/images/1/original.jpg?1449870749\"}"}' 9 | headers: 10 | User-Agent: 11 | - HTTPClient/1.0 (2.7.0.1, ruby 2.2.3 (2015-08-18)) 12 | Accept: 13 | - "*/*" 14 | Date: 15 | - Fri, 11 Dec 2015 21:52:29 GMT 16 | Content-Type: 17 | - application/json 18 | response: 19 | status: 20 | code: 200 21 | message: OK 22 | headers: 23 | Content-Length: 24 | - '2' 25 | Connection: 26 | - keep-alive 27 | Server: 28 | - thin 29 | body: 30 | encoding: UTF-8 31 | string: "{}" 32 | http_version: 33 | recorded_at: Fri, 11 Dec 2015 21:52:29 GMT 34 | recorded_with: VCR 3.0.0 35 | -------------------------------------------------------------------------------- /spec/workers/add_facebook_friends_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | describe AddFacebookFriendsWorker, local_skip: true do 4 | 5 | before do 6 | oauth = Koala::Facebook::OAuth.new(ENV["FACEBOOK_APP_ID"], ENV["FACEBOOK_APP_SECRET"], ENV["FACEBOOK_REDIRECT_URL"]) 7 | test_users = Koala::Facebook::TestUsers.new(app_id: ENV["FACEBOOK_APP_ID"], secret: ENV["FACEBOOK_APP_SECRET"]) 8 | @facebook_user = test_users.create(true, "email,user_friends") 9 | @friend = test_users.create(true, "email,user_friends") 10 | test_users.befriend(@facebook_user, @friend) 11 | @original_user = create(:user, facebook_id: @facebook_user["id"], facebook_access_token: @facebook_user["access_token"]) 12 | @friend_user = create(:user, facebook_id: @friend["id"]) 13 | end 14 | 15 | it "adds friends from facebook", vcr: { cassette_name: 'workers/add facebook friends/adds friends from facebook' } do 16 | AddFacebookFriendsWorker.new.perform(@original_user.id) 17 | 18 | expect(@original_user.following?(@friend_user)).to eq true 19 | expect(@friend_user.following?(@original_user)).to eq true 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/workers/add_facebook_profile_picture_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe AddFacebookProfilePictureWorker, local_skip: true do 4 | before do 5 | test_users = Koala::Facebook::TestUsers.new(app_id: ENV["FACEBOOK_APP_ID"], secret: ENV["FACEBOOK_APP_SECRET"]) 6 | facebook_user = test_users.create(true, "email,user_friends") 7 | @user = create(:user, facebook_id: facebook_user["id"], facebook_access_token: facebook_user["access_token"]) 8 | end 9 | 10 | it "adds a profile picture from facebook", vcr: { cassette_name: "workers/add facebook profile picture worker/adds a profile picture from facebook" } do 11 | expect_any_instance_of(Analytics).to receive(:track_added_profile_picture_from_facebook) 12 | AddFacebookProfilePictureWorker.new.perform(@user.id) 13 | @user.reload 14 | expect(@user.photo.path).to_not be_nil 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/workers/add_profile_picture_from_gravatar_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe AddProfilePictureFromGravatarWorker do 4 | before do 5 | @user = create(:user, email: "fake_email@email.com") 6 | @user_gravatar = create(:user, email: "bradyrudesill@gmail.com") 7 | end 8 | 9 | context "when the user does not have a gravatar image", vcr: { cassette_name: "workers/add gravatar image worker/does not add the gravatar" } do 10 | it "does not add the gravatar" do 11 | AddProfilePictureFromGravatarWorker.new.perform(@user.id) 12 | 13 | @user.reload 14 | 15 | expect(@user.photo.to_s).to include "user_default" 16 | end 17 | end 18 | 19 | context "when the user has a gravatar image", vcr: { cassette_name: "workers/add gravatar image worker/adds the gravatar" } do 20 | it "adds the gravatar" do 21 | expect_any_instance_of(Analytics).to receive(:track_added_profile_picture_from_gravatar) 22 | AddProfilePictureFromGravatarWorker.new.perform(@user_gravatar.id) 23 | 24 | @user_gravatar.reload 25 | 26 | expect(@user_gravatar.photo.to_s).to_not include "user_default" 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/workers/notify_pusher_of_comment_image_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe NotifyPusherOfCommentImageWorker do 4 | let(:gif_string) do 5 | filename = "#{Rails.root}/spec/sample_data/base64_images/gif.txt" 6 | file = File.open(filename, "r") 7 | open(file, &:read) 8 | end 9 | 10 | let(:comment_image) do 11 | create( 12 | :comment_image, 13 | :with_s3_image, 14 | filename: "jake.gif", 15 | base64_photo_data: gif_string 16 | ) 17 | end 18 | 19 | it "calls the NotifyPusherOCommentImage scenario" do 20 | expect_any_instance_of(CodeCorps::Scenario::NotifyPusherOfCommentImage).to receive(:call).exactly(1).times 21 | NotifyPusherOfCommentImageWorker.new.perform(comment_image.id) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/workers/notify_pusher_of_post_image_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe NotifyPusherOfPostImageWorker do 4 | let(:gif_string) do 5 | filename = "#{Rails.root}/spec/sample_data/base64_images/gif.txt" 6 | file = File.open(filename, "r") 7 | open(file, &:read) 8 | end 9 | 10 | let(:post_image) do 11 | create(:post_image, :with_s3_image, 12 | filename: "jake.gif", base64_photo_data: gif_string 13 | ) 14 | end 15 | 16 | it "calls the NotifyPusherOfPostImage scenario" do 17 | expect_any_instance_of( 18 | CodeCorps::Scenario::NotifyPusherOfPostImage 19 | ).to receive(:call).exactly(1).times 20 | 21 | NotifyPusherOfPostImageWorker.new.perform(post_image.id) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/workers/subscribe_to_mailing_list_worker_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe SubscribeToMailingListWorker do 4 | it "calls subscribe on an instance of CodeCorps::Adapters::MailingList" do 5 | user = create(:user) 6 | expect_any_instance_of( 7 | CodeCorps::Adapters::MailingList 8 | ).to receive(:subscribe).exactly(1).times 9 | 10 | SubscribeToMailingListWorker.new.perform(user.id) 11 | end 12 | end 13 | --------------------------------------------------------------------------------