-
Notifications
You must be signed in to change notification settings - Fork 0
feat: admin control #4
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,6 @@ def show? | |
| end | ||
|
|
||
| def update? | ||
| user.present? | ||
| user&.system_admin? | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| user_ids = group.user_ids | ||
| admin_user_ids = group.group_memberships.filter_map { |membership| membership.user_id if membership.admin? } | ||
| parent_group_visible = group.parent_group_id.present? && viewer.can_access_group?(group.parent_group_id) | ||
|
|
||
| json.extract! group, :id, :name, :description, :parent_group_id, :created_at, :updated_at | ||
| json.parent_group_name parent_group_visible ? group.parent_group&.name : nil | ||
| json.user_ids user_ids | ||
| json.users_count user_ids.size | ||
| json.admin_user_ids admin_user_ids | ||
| json.admins_count admin_user_ids.size | ||
| json.can_admin viewer.can_admin_group?(group.id) |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| json.extract! user, :id, :email, :display_name, :title, :bio, :created_at, :updated_at | ||
| json.extract! user, :id, :email, :display_name, :title, :bio, :system_admin, :created_at, :updated_at |
5 changes: 5 additions & 0 deletions
5
backend/db/migrate/20260709090000_add_system_admin_to_users.rb
This file contains hidden or 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 @@ | ||
| class AddSystemAdminToUsers < ActiveRecord::Migration[8.1] | ||
| def change | ||
| add_column :users, :system_admin, :boolean, null: false, default: false | ||
| end | ||
| end |
34 changes: 34 additions & 0 deletions
34
backend/db/migrate/20260709091000_add_admin_to_group_memberships.rb
This file contains hidden or 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,34 @@ | ||
| class AddAdminToGroupMemberships < ActiveRecord::Migration[8.1] | ||
| def up | ||
| add_column :group_memberships, :admin, :boolean, null: false, default: false | ||
| add_index :group_memberships, [ :group_id, :admin ] | ||
|
|
||
| execute <<~SQL.squish | ||
| UPDATE group_memberships | ||
| SET admin = TRUE | ||
| SQL | ||
|
|
||
| execute <<~SQL.squish | ||
| INSERT INTO group_memberships (group_id, user_id, admin, created_at, updated_at) | ||
| SELECT groups.id, system_admins.id, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP | ||
| FROM groups | ||
| CROSS JOIN LATERAL ( | ||
| SELECT users.id | ||
| FROM users | ||
| WHERE users.system_admin = TRUE | ||
| ORDER BY users.id ASC | ||
| LIMIT 1 | ||
| ) system_admins | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM group_memberships | ||
| WHERE group_memberships.group_id = groups.id | ||
| ) | ||
| SQL | ||
| end | ||
|
|
||
| def down | ||
| remove_index :group_memberships, [ :group_id, :admin ] | ||
| remove_column :group_memberships, :admin | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,29 @@ | ||
| # This file should ensure the existence of records required to run the application in every environment (production, | ||
| # development, test). The code here should be idempotent so that it can be executed at any point in every environment. | ||
| # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
| # | ||
| # Example: | ||
| # | ||
| # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| | ||
| # MovieGenre.find_or_create_by!(name: genre_name) | ||
| # end | ||
|
|
||
| require "securerandom" | ||
|
|
||
| root_admin_password = nil | ||
|
|
||
| User.transaction do | ||
| unless User.lock.exists?(system_admin: true) | ||
| root_admin_password = SecureRandom.urlsafe_base64(24) | ||
| root_user = User.lock.find_or_initialize_by(email: "root@example.org") | ||
| root_user.display_name = "Root Admin" if root_user.display_name.blank? | ||
| root_user.assign_attributes( | ||
| password: root_admin_password, | ||
| password_confirmation: root_admin_password, | ||
| system_admin: true | ||
| ) | ||
| root_user.save! | ||
| end | ||
| end | ||
|
|
||
| if root_admin_password | ||
| puts <<~MESSAGE | ||
| Created default system admin user: | ||
| email: root@example.org | ||
| password: #{root_admin_password} | ||
| MESSAGE | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.