|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -# Model class for additional right data management. |
4 |
| -# |
| 3 | +# Copyright 2015-2017, the Linux Foundation, IDA, and the |
| 4 | +# OpenSSF Best Practices badge contributors |
| 5 | +# SPDX-License-Identifier: MIT |
5 | 6 |
|
| 7 | +# Model class for additional rights data management. |
| 8 | +# |
| 9 | +# This model represents the many-to-many relationship between users and |
| 10 | +# projects for granting additional editing permissions beyond project |
| 11 | +# ownership. It serves as a join table that allows multiple users to have |
| 12 | +# edit rights on a single project, and allows users to have edit rights |
| 13 | +# on multiple projects they don't own. |
| 14 | +# |
| 15 | +# Currently mere *presence* is what matters; it gives the user edit rights |
| 16 | +# to that project. In the future this *could* have 1+ additional fields |
| 17 | +# identifying the specific additional rights of a user over a project. |
| 18 | +# |
| 19 | +# Database schema: |
| 20 | +# - project_id: Foreign key to projects table |
| 21 | +# - user_id: Foreign key to users table |
| 22 | +# - created_at: When the right was granted |
| 23 | +# - updated_at: When the record was last modified |
| 24 | +# |
| 25 | +# Indexes: |
| 26 | +# - Unique index on [user_id, project_id] prevents duplicate rights |
| 27 | +# - Individual indexes on project_id and user_id for query performance |
6 | 28 | class AdditionalRight < ApplicationRecord
|
7 |
| - # List additional rights of users for a given project. |
8 |
| - # This is a simple associative table (between project and user). |
9 |
| - # Currently mere *presence* is what matters; it gives the user edit rights |
10 |
| - # to that project. In the future this *could* have 1+ additional fields |
11 |
| - # identifying the specific additional rights of a user over a project. |
| 29 | + # Associates this additional right with a specific project. |
| 30 | + # When the project is destroyed, all associated additional rights are |
| 31 | + # deleted. |
| 32 | + # @return [Project] the project this right applies to |
12 | 33 | belongs_to :project
|
| 34 | + |
| 35 | + # Associates this additional right with a specific user. |
| 36 | + # When the user is destroyed, all their additional rights are deleted. |
| 37 | + # @return [User] the user who has this additional right |
13 | 38 | belongs_to :user
|
| 39 | + |
| 40 | + # Validates that both project and user exist and are valid. |
| 41 | + # NOTE: These explicit validations are required because this application |
| 42 | + # sets belongs_to_required_by_default = false in its configuration. |
| 43 | + validates :project, presence: true |
| 44 | + validates :user, presence: true |
| 45 | + |
| 46 | + # Finds all additional rights for a specific project. |
| 47 | + # This scope can be used instead of AdditionalRight.where(project_id: id) |
| 48 | + # for better readability and consistency. |
| 49 | + # @param project_id [Integer] the ID of the project |
| 50 | + # @return [ActiveRecord::Relation<AdditionalRight>] rights for project |
| 51 | + scope :for_project, ->(project_id) { where(project_id: project_id) } |
14 | 52 | end
|
0 commit comments