mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: Plugin API to add directory columns (#13440)
This commit is contained in:

committed by
GitHub

parent
fe5923da06
commit
7fc3d7bdde
@ -373,6 +373,14 @@ class Plugin::Instance
|
||||
assets
|
||||
end
|
||||
|
||||
def add_directory_column(column_name, query:, icon: nil)
|
||||
validate_directory_column_name(column_name)
|
||||
|
||||
DiscourseEvent.on("before_directory_refresh") do
|
||||
DirectoryColumn.find_or_create_plugin_directory_column(column_name: column_name, icon: icon, query: query)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_extra_automatic_assets(good_paths)
|
||||
return unless Dir.exists? auto_generated_path
|
||||
|
||||
@ -593,7 +601,6 @@ class Plugin::Instance
|
||||
# this allows us to present information about a plugin in the UI
|
||||
# prior to activations
|
||||
def activate!
|
||||
|
||||
if @path
|
||||
root_dir_name = File.dirname(@path)
|
||||
|
||||
@ -964,6 +971,11 @@ class Plugin::Instance
|
||||
|
||||
private
|
||||
|
||||
def validate_directory_column_name(column_name)
|
||||
match = /^[_a-z]+$/.match(column_name)
|
||||
raise "Invalid directory column name '#{column_name}'. Can only contain a-z and underscores" unless match
|
||||
end
|
||||
|
||||
def write_asset(path, contents)
|
||||
unless File.exists?(path)
|
||||
ensure_directory(path)
|
||||
|
Reference in New Issue
Block a user