Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Extension to Work With Latest Solidus #42

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,73 @@
version: 2.1

orbs:
# Required for feature specs.
browser-tools: circleci/[email protected]

# Always take the latest version of the orb, this allows us to
# run specs against Solidus supported versions only without the need
# to change this configuration every time a Solidus version is released
# or goes EOL.
solidusio_extensions: solidusio/extensions@volatile

jobs:
run-specs-with-postgres:
executor: solidusio_extensions/postgres
run-specs:
parameters:
solidus:
type: string
default: main
db:
type: string
default: "postgres"
ruby:
type: string
default: "3.2"
executor:
name: solidusio_extensions/<< parameters.db >>
ruby_version: << parameters.ruby >>
steps:
- solidusio_extensions/run-tests
run-specs-with-mysql:
executor: solidusio_extensions/mysql
- checkout
- browser-tools/install-chrome
- solidusio_extensions/run-tests-solidus-<< parameters.solidus >>

lint-code:
executor:
name: solidusio_extensions/sqlite
ruby_version: "3.0"
steps:
- solidusio_extensions/run-tests
- solidusio_extensions/lint-code

workflows:
"Run specs on supported Solidus versions":
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
"Weekly run specs against master":
- run-specs:
name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
matrix:
parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] }
- lint-code

"Weekly run specs against main":
triggers:
- schedule:
cron: "0 0 * * 4" # every Thursday
filters:
branches:
only:
- master
- main
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
- run-specs:
name: *name
matrix:
parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
5 changes: 5 additions & 0 deletions .gem_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bump:
recurse: false
file: 'lib/solidus_user_roles/version.rb'
message: Bump SolidusUserRoles to %{version}
tag: true
1 change: 1 addition & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_extends: .github
2 changes: 2 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issues=false
exclude-labels=infrastructure
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.gem
\#*
*~
.#*
Expand All @@ -7,9 +8,14 @@
.sass-cache
coverage
Gemfile.lock
Gemfile-local
tmp
nbproject
pkg
*.swp
spec/dummy
spec/examples.txt
/sandbox
.rvmrc
.ruby-version
.ruby-gemset
3 changes: 2 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--color
--color
--require spec_helper
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
require:
- solidus_dev_support/rubocop

AllCops:
NewCops: disable
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
17 changes: 16 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
gem 'solidus', github: 'solidusio/solidus', branch: branch

# The solidus_frontend gem has been pulled out since v3.2
gem 'solidus_frontend', github: 'solidusio/solidus_frontend' if branch == 'master'
gem 'solidus_frontend' if branch >= 'v3.2' # rubocop:disable Bundler/DuplicatedGem

# Needed to help Bundler figure out how to resolve dependencies,
# otherwise it takes forever to resolve them.
# See https://github.com/bundler/bundler/issues/6677
Expand All @@ -14,7 +18,7 @@ gem 'rails', '>0.a'
# Provides basic authentication functionality for testing parts of your engine
gem 'solidus_auth_devise'

case ENV['DB']
case ENV.fetch('DB', nil)
when 'mysql'
gem 'mysql2'
when 'postgresql'
Expand All @@ -24,5 +28,16 @@ else
end

gem 'rails-controller-testing', group: :test
# While we still support Ruby < 3 we need to workaround a limitation in
# the 'async' gem that relies on the latest ruby, since RubyGems doesn't
# resolve gems based on the required ruby version.
gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')

gemspec

# Use a local Gemfile to include development dependencies that might not be
# relevant for the project or for other contributors, e.g. pry-byebug.
#
# We use `send` instead of calling `eval_gemfile` to work around an issue with
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 [name of plugin creator]
Copyright (c) 2023 Allison Reilly
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand All @@ -9,7 +9,7 @@ are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Spree nor the names of its contributors may be used to
* Neither the name Solidus nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

Expand Down
66 changes: 47 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
SolidusUserRoles
=====================
# Solidus User Roles

[![CircleCI](https://circleci.com/gh/boomerdigital/solidus_user_roles.svg?style=svg)](https://circleci.com/gh/boomerdigital/solidus_user_roles)
[![CircleCI](https://circleci.com/gh/cpfergus1/solidus_user_roles.svg?style=shield)](https://circleci.com/gh/cpfergus1/solidus_user_roles)
[![codecov](https://codecov.io/gh/cpfergus1/solidus_user_roles/branch/master/graph/badge.svg)](https://codecov.io/gh/cpfergus1/solidus_user_roles)

<!-- Explain what your extension does. -->

SolidusUserRoles gives an admin the ability to create custom roles for their employees to restrict or allow access to certain sections in the admin panel.

Installation
------------
## Installation

Add solidus_user_roles to your Gemfile:

Expand All @@ -30,26 +28,56 @@ rake solidus_user_roles:load_seeds
Admin Panel
-----------
An admin is the only user who has the ability to add or remove roles from other users.
![image](https://cloud.githubusercontent.com/assets/6445334/14432566/b90ae0b4-ffd8-11e5-832c-8692dbb437bb.png)
![image](https://cloud.githubusercontent.com/assets/6445334/14432655/0c5c7a84-ffd9-11e5-8463-366fa88b774f.png)
![image](https://cloud.githubusercontent.com/assets/6445334/14432674/22dadc60-ffd9-11e5-97c2-3e9719427140.png)
![image](https://github.com/cpfergus1/solidus_user_roles/assets/68167430/8109fe7e-d098-42c8-a03a-ad1bec273b8c)
![image](https://github.com/cpfergus1/solidus_user_roles/assets/68167430/311d8e38-e801-401d-9fe8-f232435001ad)
![image](https://github.com/cpfergus1/solidus_user_roles/assets/68167430/6f248635-054c-4adc-9fdf-85108acd06c8)
## Development

### Testing the extension

First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
`bin/rake extension:test_app`.

Testing
-------
```shell
bin/rake
```

First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run

```shell
bundle
bundle exec rake
bundle exec rubocop
```

When testing your applications integration with this extension you may use it's factories.
Simply add this require statement to your spec_helper:
When testing your application's integration with this extension you may use its factories.
You can load Solidus core factories along with this extension's factories using this statement:

```ruby
require 'solidus_user_roles/factories'
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusUserRoles::Engine)
```

Copyright (c) 2016 [name of extension creator], released under the New BSD License
### Running the sandbox

To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
`sandbox/bin/rails`.

Here's an example:

```
$ bin/rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop
```

### Releasing new versions

Please refer to the [dedicated page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) in the Solidus wiki.


## License
Fork of https://github.com/boomerdigital/solidus_user_roles

Copyright (c) 2023 Allison Reilly, released under the New BSD License.
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# frozen_string_literal: true

require 'solidus_dev_support/rake_tasks'
SolidusDevSupport::RakeTasks.install

task default: %w[extension:test_app extension:specs]
task default: 'extension:specs'
2 changes: 2 additions & 0 deletions app/controllers/spree/admin/roles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Spree
module Admin
class RolesController < ResourceController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true


module SolidusUserRoles
module Spree
module RoleDecorator
Expand All @@ -9,7 +8,7 @@ def self.prepended(base)
base.has_many :permission_sets, through: :role_permissions

base.scope :non_base_roles, -> { where.not(name: ['admin', 'user']) }
base.validates :name, uniqueness: true
base.validates_uniqueness_of :name, case_sensitive: false
base.after_save :assign_permissions
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/spree/permission_set.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module Spree
class PermissionSet < Spree::Base
has_many :role_permissions
has_many :role_permissions # rubocop:disable Rails/HasManyOrHasOneDependent
has_many :roles, through: :role_permissions
validates :name, :set, presence: true
scope :display_permissions, -> { where('name LIKE ?', '%Display') }
Expand Down
15 changes: 14 additions & 1 deletion app/models/spree/permission_sets/role_management.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# frozen_string_literal: true

# A Role Manager has all the access of a UserManager and the ability to manage Roles
module Spree
module PermissionSets
class RoleManagement < PermissionSets::Base
def activate!
can [:admin, :display, :create, :update, :save_in_address_book, :remove_from_address_book, :addresses, :orders, :items], Spree.user_class
can [
:admin,
:display,
:create,
:update,
:save_in_address_book,
:remove_from_address_book,
:addresses,
:orders,
:items
],
Spree.user_class

# due to how cancancan filters by associations,
# we have to define this twice, once for `accessible_by`
Expand Down
2 changes: 2 additions & 0 deletions app/models/spree/role_permission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Spree
class RolePermission < Spree::Base
belongs_to :role
Expand Down
6 changes: 4 additions & 2 deletions app/overrides/user_sub_menu.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

Deface::Override.new(
virtual_path: 'spree/admin/shared/_menu',
name: 'add_user_roles_menu_links',
virtual_path: 'spree/admin/shared/_menu',
name: 'add_user_roles_menu_links',
insert_bottom: "[data-hook='admin_tabs']"
) do
<<-HTML
Expand Down
Loading