X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fpettanr%2Faction_filter.js.coffee;h=70f44aba773b507cd383aaf6e2596eefff7b8cf3;hp=1b2cac42f63f12ccb6a3d4e70c238ad31fa35df4;hb=6feb1c7f35b819955c56b14b6cfb7d1c21c0cffa;hpb=1faa2a7eb0cca883d62d7e7e36ad7e3a7530a6a2 diff --git a/app/assets/javascripts/pettanr/action_filter.js.coffee b/app/assets/javascripts/pettanr/action_filter.js.coffee index 1b2cac42..70f44aba 100644 --- a/app/assets/javascripts/pettanr/action_filter.js.coffee +++ b/app/assets/javascripts/pettanr/action_filter.js.coffee @@ -1,101 +1,503 @@ class Pettanr.ActionFilter - @suply_default: (reader, resource_reader, user, author) -> + # access block + # return sign in form if invalid url + # return null if url is valid + @test: (params) -> + return @guest_url() if @is_deny('reader', params) or @is_deny('resource_reader', params) or @is_deny('user', params) + return @new_author_url() if @is_deny('author', params) + return @new_artist_url() if @is_deny('artist', params) + null + + @filters: () -> + if Pettanr.is_sns() + @sns_filters() + else + @blog_filters() + + @my_filters: (role, params) -> + f = @filters() + c = f[params['controller']] || {} + r = c[role] + r + + @before_filter: (action_name, filter_action_names) -> + _.contains(filter_action_names, action_name) + + # return false if allow + # return true if deny + @is_deny: (role, params) -> + n = 'is_' + role + if not Pettanr.cache.operators[n]() # ex: operators.is_user() + filter = @my_filters(role, params) + if @before_filter(params['action'], filter) + return true + false + + @guest_url: () -> + 'user_sessions/new' + + @new_author_url: () -> + 'authors/new' + + @new_artist_url: () -> + 'artists/new' + + @suply_default: (mode, reader, resource_reader, user, author, artist) -> + author_filter = if _.isFunction(author) + author() + else + _.union(@default_filters[mode].author, author) + artist_filter = if _.isFunction(artist) + artist() + else + _.union(@default_filters[mode].artist, artist) { - reader: _.union(default_reader_filters, reader), - resource_reader: _.union(default_resource_reader_filters, resource_reader), - user: _.union(default_user_filters, user), - author: _.union(default_author_filters, author) + reader: _.union(@default_filters[mode].reader, reader), + resource_reader: _.union(@default_filters[mode].resource_reader, resource_reader), + user: _.union(@default_filters[mode].user, user), + author: author_filter, + artist: artist_filter + } + + @suply_sns_default: (reader, resource_reader, user, author, artist) -> + @suply_default('sns', reader, resource_reader, user, author, artist) + + @suply_blog_default: (reader, resource_reader, user, author, artist) -> + @suply_default('blog', reader, resource_reader, user, author, artist) + + @default_filters = { + sns: { + reader: ['index', 'show'] + resource_reader: [] + user: ['new', 'create', 'edit', 'update', 'destroy'] + author: ['new', 'create', 'edit', 'update', 'destroy'] + artist: [] + }, + blog: { + reader: [] + resource_reader: [] + user: ['new', 'create', 'edit', 'update', 'destroy'] + author: ['new', 'create', 'edit', 'update', 'destroy'] + artist: [] } + } @sns_filters: () -> - default_reader_filters = ['index', 'show'] - default_resource_reader_filters = [] - default_user_filters = ['new', 'create', 'edit', 'update', 'destroy'] - default_author_filters = ['new', 'create', 'edit', 'update', 'destroy'] { - 'folders': { - reader: _.union(default_reader_filters, ['root', 'watch']), - resource_reader: _.union(default_resource_reader_filters, []), - user: _.union(default_user_filters, []), - author: _.union(default_author_filters, []) - }, - 'scrolls': { - reader: _.union(default_reader_filters, ['play', 'by_panel', 'by_author']), - resource_reader: _.union(default_resource_reader_filters, []), - user: _.union(default_user_filters, []), - author: _.union(default_author_filters, []) - }, - scroll_panels: { - reader: _.union(default_reader_filters, ['by_panel', 'by_scroll', 'by_author']), - resource_reader: _.union(default_resource_reader_filters, []), - user: _.union(default_user_filters, []), - author: _.union(default_author_filters, []) - }, - comics: { - }, - comic_stories: { - }, - stories: { - }, - story_sheets: { - }, - sheets: { - }, - sheet_panels: { - }, - panels: { - }, - panel_pictures: { - }, - speech_balloons: { - }, - speeches: { - }, - balloons: { - }, - ground_pictures: { - }, - ground_colors: { - }, - original_pictures: { - }, - pictures: { - }, - resource_pictures: { - }, - speech_balloon_templates: { - }, - writing_formats: { - }, - license_groups: { - }, - licenses: { - }, - authors: { - }, - artists: { - }, - system_pictures: { - }, - home: { - }, + folders: @suply_sns_default( + ['root', 'watch'], + [], + [], + [], + [] + ), + scrolls: @suply_sns_default( + ['play', 'by_panel', 'by_author'], + [], + [], + [], + [] + ), + scroll_panels: @suply_sns_default( + ['by_panel', 'by_scroll', 'by_author'], + [], + [], + [], + [] + ), + comics: @suply_sns_default( + ['play', 'by_story', 'by_author'], + [], + [], + [], + [] + ), + comic_stories: @suply_sns_default( + ['by_story', 'by_comic', 'by_author'], + [], + [], + [], + [] + ), + stories: @suply_sns_default( + ['play', 'by_comic', 'by_sheet', 'by_author'], + [], + [], + [], + [] + ), + story_sheets: @suply_sns_default( + ['by_story', 'by_sheet', 'by_author'], + [], + [], + [], + [] + ), + sheets: @suply_sns_default( + ['play', 'by_story', 'by_panel', 'by_author'], + [], + [], + [], + [] + ), + sheet_panels: @suply_sns_default( + ['by_panel', 'by_sheet', 'by_author'], + [], + [], + [], + [] + ), + panels: @suply_sns_default( + ['by_scroll', 'by_sheet', 'by_author', 'by_speech_balloon_template'], + [], + [], + [], + [] + ), + panel_pictures: @suply_sns_default( + ['by_panel', 'by_author'], + [], + [], + [], + [] + ), + speech_balloons: @suply_sns_default( + ['by_panel', 'by_author', 'by_speech_balloon_template'], + [], + [], + [], + [] + ), + speeches: @suply_sns_default( + ['by_author', 'by_speech_balloon', 'by_speech_balloon_template', 'by_writing_format'], + [], + [], + [], + [] + ), + balloons: @suply_sns_default( + [], + [], + [], + [], + [] + ), + ground_pictures: @suply_sns_default( + ['by_panel', 'by_author'], + [], + [], + [], + [] + ), + ground_colors: @suply_sns_default( + ['by_panel', 'by_author'], + [], + [], + [], + [] + ), + original_pictures: @suply_sns_default( + ['history'], + [], + [], + () -> + [] + , + ['index', 'new', 'create', 'edit', 'update', 'destroy'] + ), + pictures: @suply_sns_default( + ['credit', 'search'], + [], + [], + [], + [] + ), + resource_pictures: @suply_sns_default( + ['credit', 'by_original_picture', 'by_license_group', 'by_license', 'by_artist'], + [], + [], + [], + ['new', 'create', 'edit', 'update', 'destroy'] + ), + speech_balloon_templates: @suply_sns_default( + ['by_panel', 'by_system_picture'], + [], + [], + [], + [] + ), + writing_formats: @suply_sns_default( + ['by_system_picture'], + [], + [], + [], + [] + ), + license_groups: @suply_sns_default( + ['by_resource_picture'], + [], + [], + [], + [] + ), + licenses: @suply_sns_default( + ['by_license_group', 'by_system_picture'], + [], + [], + [], + [] + ), + authors: @suply_sns_default( + [], + [], + [], + () -> + ['edit', 'update', 'destroy'] + , + () -> + [] + , + ), + artists: @suply_sns_default( + [], + [], + [], + () -> + [] + , + () -> + ['edit', 'update', 'destroy'] + ), + system_pictures: @suply_sns_default( + [], + [], + [], + [], + [] + ), + home: @suply_sns_default( + [ + 'profile', 'configure', 'create_token', 'delete_token', + 'scrolls', 'scroll_panels', 'comics', 'comic_stories', 'stories', 'story_sheets', 'sheets', 'sheet_panels', + 'panels', 'panel_pictures', 'speech_balloons', 'balloons', 'speeches', 'ground_pictures', 'ground_colors' + ], + [ + 'scrolls', 'scroll_panels', 'comics', 'comic_stories', 'stories', 'story_sheets', 'sheets', 'sheet_panels', + 'panels', 'panel_pictures', 'speech_balloons', 'balloons', 'speeches', 'ground_pictures', 'ground_colors' + ], + [], + [], + [] + ), } @blog_filters: () -> - default_reader_filters = [] - default_user_filters = ['new', 'create', 'edit', 'update', 'destroy'] - default_author_filters = ['new', 'create', 'edit', 'update', 'destroy'] { - 'folders': { - reader: _.union(default_reader_filters, []), - resource_reader: _.union(default_resource_reader_filters, []), - user: _.union(default_user_filters, []), - author: _.union(default_author_filters, []) - }, - 'scrolls': { - user: _.union(default_user_filters, []), - author: _.union(default_author_filters, []) - }, + folders: @suply_blog_default( + [], + [], + [], + [], + [] + ), + scrolls: @suply_blog_default( + [], + [], + [], + [], + [] + ), + scroll_panels: @suply_blog_default( + [], + [], + [], + [], + [] + ), + comics: @suply_blog_default( + [], + [], + [], + [], + [] + ), + comic_stories: @suply_blog_default( + [], + [], + [], + [], + [] + ), + stories: @suply_blog_default( + [], + [], + [], + [], + [] + ), + story_sheets: @suply_blog_default( + [], + [], + [], + [], + [] + ), + sheets: @suply_blog_default( + [], + [], + [], + [], + [] + ), + sheet_panels: @suply_blog_default( + [], + [], + [], + [], + [] + ), + panels: @suply_blog_default( + [], + [], + [], + [], + [] + ), + panel_pictures: @suply_blog_default( + [], + [], + [], + [], + [] + ), + speech_balloons: @suply_blog_default( + [], + [], + [], + [], + [] + ), + speeches: @suply_blog_default( + [], + [], + [], + [], + [] + ), + balloons: @suply_blog_default( + [], + [], + [], + [], + [] + ), + ground_pictures: @suply_blog_default( + [], + [], + [], + [], + [] + ), + ground_colors: @suply_blog_default( + [], + [], + [], + [], + [] + ), + original_pictures: @suply_blog_default( + ['history'], + [], + [], + () -> + [] + , + ['index', 'new', 'create', 'edit', 'update', 'destroy'] + ), + pictures: @suply_blog_default( + [], + [], + [], + [], + [] + ), + resource_pictures: @suply_blog_default( + [], + [], + [], + [], + ['new', 'create', 'edit', 'update', 'destroy'] + ), + speech_balloon_templates: @suply_blog_default( + [], + [], + [], + [], + [] + ), + writing_formats: @suply_blog_default( + [], + [], + [], + [], + [] + ), + license_groups: @suply_blog_default( + [], + [], + [], + [], + [] + ), + licenses: @suply_blog_default( + [], + [], + [], + [], + [] + ), + authors: @suply_blog_default( + [], + [], + [], + () -> + ['edit', 'update', 'destroy'] + , + () -> + [] + , + ), + artists: @suply_blog_default( + [], + [], + [], + () -> + [] + , + () -> + ['edit', 'update', 'destroy'] + ), + system_pictures: @suply_blog_default( + [], + [], + [], + [], + [] + ), + home: @suply_blog_default( + [ + 'profile', 'configure', 'create_token', 'delete_token', + 'scrolls', 'scroll_panels', 'comics', 'comic_stories', 'stories', 'story_sheets', 'sheets', 'sheet_panels', + 'panels', 'panel_pictures', 'speech_balloons', 'balloons', 'speeches', 'ground_pictures', 'ground_colors' + ], + [ + 'scrolls', 'scroll_panels', 'comics', 'comic_stories', 'stories', 'story_sheets', 'sheets', 'sheet_panels', + 'panels', 'panel_pictures', 'speech_balloons', 'balloons', 'speeches', 'ground_pictures', 'ground_colors' + ], + [], + [], + [] + ), }