Commit 29b7ecda authored by kaiyou's avatar kaiyou
Browse files

Merge remote-tracking branch 'upstream/master' into HEAD

parents ef94849b 195aa7b9
Pipeline #127 passed with stages
in 15 minutes and 41 seconds
File deleted
......@@ -39,3 +39,5 @@ coverage
.env
.env.development
.env
.DS_Store
# Contributing to Prismo
Thank you for your interest in Prismo!
You can contribute in the following ways:
* Spreading the word about Prismo
* Join in design discussions on [SocialHub](https://socialhub.network/c/prismo)
* [Finding and reporting bugs](#bug-reports)
* [Requesting new features](#feature-requests)
* [Fixing bugs or implementing features](#workflow)
* Improving the documentation
Bug reports and feature suggestions can be submitted on the GitLab repository. Please make sure that you are not submitting duplicates, and that a similar report or request has not already been resolved or rejected in the past using the search function. Please also use descriptive, concise titles.
## Bug Reports
If you think you have found a bug, please check that it hasn't already been reported. You can do that by going to [Issues](https://gitlab.com/mbajur/prismo/issues) and searching for related keywords. After verifying an issue doesn't already exist, create a new issue and title it with a simple description of the bug. In the body of the issue, add a more complete description if necessary. Be sure to include steps to reproduce the bug. Once you file a bug, maintainers or contributors will verify that it can be reproduced and triage the issue so a developer can work on it.
## Feature Requests
If you want to request a new feature, please check that it hasn't already been requested and check closed issues to verify that it hasn't already been rejected for any reason. After verifying you have a new request, create an issue and give it a simple, clear title. Describe your request more completely in the body of the issue. Include what value you think this adds to Prismo and examples of similar features in other software.
## Workflow
Prismo development utilizes GitLab for its public repository. Bug reports and feature requests should be filed as [Issues](https://gitlab.com/mbajur/prismo/issues). Issues will be triaged by project maintainers according to the project priorities. Labels indicate the areas of the software the bug/feature is related to and it's priority. Weight indicates amount of work needed by a developer. The more weight issue has, the more work a developer need to put into the issue to resolve it.
If you are a developer and you want to work on an issue, leave a comment on the issue to say that you are working on it. If it's a large bug/feature or you are unsure of the best solution, feel free to open a WIP merge request so maintainers can guide you as you work.
## Merge requests
Please use clean, concise titles for your merge requests.
The smaller the set of changes in the merge request is, the quicker it can be reviewed and merged. Splitting tasks into multiple, smaller merge requests is often preferable.
Please make sure merge requests for new features includes test specs for the new code.
\ No newline at end of file
......@@ -92,6 +92,7 @@ group :development do
gem 'spring-commands-rspec'
gem 'foreman'
gem 'letter_opener'
gem 'slimkeyfy'
end
group :test do
......
......@@ -174,6 +174,9 @@ GEM
domain_name (~> 0.5)
http-form_data (2.1.1)
http_parser.rb (0.6.0)
httparty (0.16.4)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
image_info (1.1.2)
......@@ -233,6 +236,9 @@ GEM
meta-tags (2.10.0)
actionpack (>= 3.2.0, < 5.3)
method_source (0.9.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mimemagic (0.3.2)
mini_magick (4.8.0)
mini_mime (1.0.0)
......@@ -241,6 +247,7 @@ GEM
moneta (1.0.0)
msgpack (1.2.4)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
mustache (1.0.5)
net-http-persistent (3.0.0)
......@@ -355,6 +362,8 @@ GEM
ffi (~> 1.9)
ruby_dep (1.5.0)
rubyzip (1.2.1)
russian (0.6.0)
i18n (>= 0.5.0)
safe_yaml (1.0.4)
sanitize (4.6.6)
crass (~> 1.0.2)
......@@ -404,6 +413,9 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (~> 3.0)
slimkeyfy (0.1.0)
russian
yandex-translator
spring (2.0.2)
activesupport (>= 4.2)
spring-commands-rspec (1.0.4)
......@@ -464,6 +476,8 @@ GEM
activerecord (>= 4.2)
xpath (3.1.0)
nokogiri (~> 1.8)
yandex-translator (0.3.2)
httparty (>= 0.13.4)
PLATFORMS
ruby
......@@ -528,6 +542,7 @@ DEPENDENCIES
simplecov
site_prism (~> 2.15)
slim-rails
slimkeyfy
spring
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
......
......@@ -14,6 +14,30 @@ will not be backward-compatible.**
***
## Table Of Contents
<!-- MarkdownTOC -->
- [Getting started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Setup / first run](#setup--first-run)
- [Development](#development)
- [Running the tests](#running-the-tests)
- [Deployment](#deployment)
- [Prerequisites](#prerequisites-1)
- [Setting up](#setting-up)
- [Getting the Prismo image](#getting-the-prismo-image)
- [Using a prebuilt image](#using-a-prebuilt-image)
- [Building your own image](#building-your-own-image)
- [Building the app](#building-the-app)
- [Versioning](#versioning)
- [Thanks](#thanks)
- [License](#license)
<!-- /MarkdownTOC -->
## Getting started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
......@@ -49,6 +73,12 @@ If the app has been set up already and you want to continue working on it:
## Running the tests
Make sure [geckodriver](https://github.com/mozilla/geckodriver) is installed or the browser specs will fail.
If you have a mac with homebrew, you can do this by running:
$ brew install geckodriver
Running unit specs:
$ bundle exec rspec
......@@ -119,6 +149,12 @@ Following that, you have a Prismo instance running on 127.0.0.1:3000. **It's hig
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://gitlab.com/mbajur/prismo/tags).
## Thanks
Prismo Team is extremely grateful to all the contributors and donors from Patreon and LiberaPay. Apart from that, it's fair to mention that
huge amount of Prismo code base is heavily based on Mastodon code and it would be impossible to implement this project without Mastodon source guidance.
Thank you ❤️
## License
......
module Admin
class FlagsController < ApplicationController
layout 'settings'
def index
authorize Flag
@flags = Flag.order(created_at: :desc).page(params[:page])
end
def show
@flag = find_flag
authorize @flag
end
def resolve
@flag = find_flag
authorize @flag
Flags::Resolve.run(flag: @flag)
redirect_to admin_flag_path(@flag), notice: 'Flag marked as resolved'
end
def unresolve
@flag = find_flag
authorize @flag
Flags::Unresolve.run(flag: @flag)
redirect_to admin_flag_path(@flag), notice: 'Flag marked as unresolved'
end
private
def find_flag
@find_flag ||= Flag.find(params[:id]).decorate
end
end
end
......@@ -8,6 +8,7 @@ module Admin
comment_likes_per_day
open_registrations
closed_registrations_message
story_title_update_time_limit
).freeze
BOOLEAN_SETTINGS = %w(open_registrations).freeze
......
class FlagsController < ApplicationController
layout 'application'
before_action :set_flaggable_jumpbox_link
before_action :set_liked_ids
helper_method :flaggable
helper_method :form_url
def new
redirect_to edit_resource_path if find_flag.present?
authorize Flag
@resource = flaggable
@flag_form = Flags::Create.new
end
def edit
redirect_to new_resource_path if find_flag.blank?
authorize find_flag
@flag_form = Flags::Update.new(flag: find_flag, summary: find_flag.summary)
end
def create
authorize Flag
outcome = Flags::Create.run(
flag_params.merge(
actor: current_account,
flaggable: flaggable
)
)
if outcome.valid?
redirect_to flaggable, notice: 'Flag has been created'
else
@flag_form = outcome
render :new
end
end
def update
flag = find_flag
authorize flag
outcome = Flags::Update.run(
flag: flag,
summary: params.fetch(:flag)[:summary],
account: current_account
)
if outcome.valid?
redirect_to flag.flaggable, notice: 'Flag has been updated'
else
@flag_form = outcome
render :edit
end
end
private
def flaggable_model
if params.key?(:story_id)
Story
else
Comment
end
end
def flaggable_id_param
case flaggable_model.to_s
when 'Story' then :story_id
when 'Comment' then :comment_id
end
end
def flaggable
@flaggable ||= flaggable_model.find(params[flaggable_id_param])
end
def flag_params
params.require(:flag).permit(:summary)
end
def find_flag
@find_flag ||= flaggable.flags.unresolved.find_by(actor: current_account)
end
def set_liked_ids
case flaggable_model.to_s
when 'Story' then set_account_liked_story_ids
when 'Comment' then set_account_liked_comment_ids
end
end
def form_url
case flaggable_model.to_s
when 'Story' then story_flag_path(flaggable)
when 'Comment' then comment_flag_path(flaggable)
end
end
def edit_resource_path
case flaggable_model.to_s
when 'Story' then edit_story_flag_path
when 'Comment' then edit_comment_flag_path
end
end
def new_resource_path
case flaggable_model.to_s
when 'Story' then new_story_flag_path
when 'Comment' then new_comment_flag_path
end
end
def set_flaggable_jumpbox_link
case flaggable_model.to_s
when 'Story' then set_jumpbox_link(Jumpbox::STORIES_LINK)
when 'Comment' then set_jumpbox_link(Jumpbox::COMMENTS_LINK)
end
end
end
class ManifestController < ActionController::Base
def show
render json: ManifestSerializer.new
end
def show
render json: ManifestSerializer.new
end
\ No newline at end of file
end
class CommentDecorator < Draper::Decorator
delegate_all
def to_flag_title
'Comment'
end
def excerpt
h.strip_tags(object.body).truncate(200)
end
......
class FlagDecorator < Draper::Decorator
delegate_all
def path
h.admin_flag_path(object.id)
end
end
......@@ -5,6 +5,10 @@ class StoryDecorator < Draper::Decorator
object.title
end
def to_flag_title
to_s
end
def path
h.story_path(object)
end
......
......@@ -5,6 +5,9 @@ class Comments::Update < ActiveInteraction::Base
def execute
comment.body = body if body?
comment.modified_at = Time.current
comment.modified_count += 1
if comment.save
after_comment_save_hook(comment)
else
......
class Flags::Create < ActiveInteraction::Base
string :summary
interface :flaggable
interface :actor
validates :summary, presence: true
def execute
flag = Flag.new
flag.summary = summary
flag.actor = actor
flag.flaggable = flaggable
if flag.save
Notifications::SendForFlag.run!(flag: flag)
else
errors.merge!(flag.errors)
end
flag
end
end
class Flags::Resolve < ActiveInteraction::Base
object :flag
def execute
flag.action_taken = true
if flag.valid?
flag.save
else
errors.merge!(flag.errors)
end
flag
end
end
class Flags::Unresolve < ActiveInteraction::Base
object :flag
def execute
flag.action_taken = false
if flag.valid?
flag.save
else
errors.merge!(flag.errors)
end
flag
end
end
class Flags::Update < ActiveInteraction::Base
object :flag
string :summary
def execute
flag.summary = summary if summary?
if flag.valid?
flag.save
else
errors.merge!(flag.errors)
end
flag
end
def persisted?
true
end
end
class Notifications::SendForFlag < ActiveInteraction::Base
object :flag
def execute
User.admins.each do |recipient|
CreateNotificationJob.call(
'new_flag',
author: flag.actor,
recipient: recipient.account,
notifable: flag,
context: flag.flaggable
)
end
end
end
......@@ -3,15 +3,16 @@ class Stories::Update < Stories::CreateUpdateBase
validates :url, url: { allow_blank: true }
validate :url_or_description_required
validate :title_update_time_limit
def execute
story.title = title if title?
story.tag_names = tags if tag_list?
story.description = description if description?
story.url = url if url.present? && can_update_url?
if url.present? && Stories::UpdatePolicy.new(account.user, story).update_url?
story.url = url
end
story.modified_at = Time.current
story.modified_count += 1
if story.save
after_story_save_hook(story)
......@@ -30,7 +31,26 @@ class Stories::Update < Stories::CreateUpdateBase
def after_story_save_hook(story)
Stories::ScrapJob.perform_later(story.id) if story.url_changed?
Stories::BroadcastChanges.run! story: story
Stories::BroadcastChanges.run!(story: story)
ActivityPub::UpdateDistributionJob.call_later(story) if story.local?
end
def title_update_time_limit
return unless title_changed?
limit = Setting.story_title_update_time_limit
errors.add(:title, "can't be edited after #{limit} minutes") unless can_update_title?
end
def title_changed?
title? && title != story.title
end
def can_update_title?
StoryPolicy.new(account.user, story).update_title?
end
def can_update_url?
Stories::UpdatePolicy.new(account.user, story).update_url?
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment