This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class RulesController < BaseController | ||
before_action :set_rule, except: [:index, :create] | ||
|
||
def index | ||
authorize :rule, :index? | ||
|
||
@rules = Rule.ordered | ||
@rule = Rule.new | ||
end | ||
|
||
def create | ||
authorize :rule, :create? | ||
|
||
@rule = Rule.new(resource_params) | ||
|
||
if @rule.save | ||
redirect_to admin_rules_path | ||
else | ||
@rules = Rule.ordered | ||
render :index | ||
end | ||
end | ||
|
||
def edit | ||
authorize @rule, :update? | ||
end | ||
|
||
def update | ||
authorize @rule, :update? | ||
|
||
if @rule.update(resource_params) | ||
redirect_to admin_rules_path | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
authorize @rule, :destroy? | ||
|
||
@rule.discard | ||
|
||
redirect_to admin_rules_path | ||
end | ||
|
||
private | ||
|
||
def set_rule | ||
@rule = Rule.find(params[:id]) | ||
end | ||
|
||
def resource_params | ||
params.require(:rule).permit(:text, :priority) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Instances::RulesController < Api::BaseController | ||
skip_before_action :require_authenticated_user!, unless: :whitelist_mode? | ||
|
||
before_action :set_rules | ||
|
||
def index | ||
render json: @rules, each_serializer: REST::RuleSerializer | ||
end | ||
|
||
private | ||
|
||
def set_rules | ||
@rules = Rule.ordered | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: rules | ||
# | ||
# id :bigint(8) not null, primary key | ||
# priority :integer default(0), not null | ||
# deleted_at :datetime | ||
# text :text default(""), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Rule < ApplicationRecord | ||
include Discard::Model | ||
|
||
self.discard_column = :deleted_at | ||
|
||
validates :text, presence: true, length: { maximum: 300 } | ||
|
||
scope :ordered, -> { kept.order(priority: :asc) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class RulePolicy < ApplicationPolicy | ||
def index? | ||
staff? | ||
end | ||
|
||
def create? | ||
admin? | ||
end | ||
|
||
def update? | ||
admin? | ||
end | ||
|
||
def destroy? | ||
admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class REST::RuleSerializer < ActiveModel::Serializer | ||
attributes :id, :text | ||
|
||
def id | ||
object.id.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,16 @@ | |
- else | ||
.box-widget | ||
.rich-formatting | ||
- unless @rules.empty? | ||
%h2#rules= t('about.rules') | ||
|
||
%p= t('about.rules_html') | ||
|
||
%ol.rules-list | ||
- @rules.each do |rule| | ||
%li | ||
.rules-list__text= rule.text | ||
|
||
= @contents.html_safe | ||
|
||
- if display_blocks? && [email protected]? | ||
|
@@ -70,6 +80,9 @@ | |
|
||
.column-4 | ||
%ul.table-of-contents | ||
- unless @rules.empty? | ||
%li= link_to t('about.rules'), '#rules' | ||
|
||
- @table_of_contents.each do |item| | ||
%li | ||
= link_to item.title, "##{item.anchor}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.announcements-list__item | ||
= link_to edit_admin_rule_path(rule), class: 'announcements-list__item__title' do | ||
= "#{rule_counter + 1}." | ||
= truncate(rule.text) | ||
|
||
.announcements-list__item__action-bar | ||
.announcements-list__item__meta | ||
= rule.text | ||
|
||
%div | ||
= table_link_to 'trash', t('admin.rules.delete'), admin_rule_path(rule), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:destroy, rule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- content_for :page_title do | ||
= t('admin.rules.edit') | ||
|
||
= simple_form_for @rule, url: admin_rule_path(@rule) do |f| | ||
= render 'shared/error_messages', object: @rule | ||
|
||
.fields-group | ||
= f.input :text, wrapper: :with_block_label | ||
|
||
.actions | ||
= f.button :button, t('generic.save_changes'), type: :submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- content_for :page_title do | ||
= t('admin.rules.title') | ||
|
||
.simple_form | ||
%p.hint= t('admin.rules.description') | ||
|
||
- if can? :create, :rule | ||
= simple_form_for @rule, url: admin_rules_path do |f| | ||
= render 'shared/error_messages', object: @rule | ||
|
||
.fields-group | ||
= f.input :text, wrapper: :with_block_label | ||
|
||
.actions | ||
= f.button :button, t('admin.rules.add_new'), type: :submit | ||
|
||
%hr.spacer/ | ||
|
||
- if @rules.empty? | ||
%div.muted-hint.center-text | ||
= t 'admin.rules.empty' | ||
- else | ||
.announcements-list | ||
= render partial: 'rule', collection: @rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateRules < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :rules do |t| | ||
t.integer :priority, null: false, default: 0 | ||
t.datetime :deleted_at | ||
t.text :text, null: false, default: '' | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Fabricator(:rule) do | ||
priority "" | ||
deleted_at "2021-02-21 05:51:09" | ||
text "MyText" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Rule, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |