- 
                Notifications
    You must be signed in to change notification settings 
- Fork 172
feat: file modification #3204
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
          
     Open
      
      
            carlinmack
  wants to merge
  7
  commits into
  inveniosoftware:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
carlinmack:file-mod-req
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    feat: file modification #3204
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6f856b8
              
                chore: extract evaluate_record_deletion into utils
              
              
                carlinmack b51c01a
              
                fix: align selector with semantic-ui
              
              
                carlinmack 778c9a9
              
                feat: pass file modification eval to deposit form
              
              
                carlinmack 3fab41d
              
                chore: relax proptypes
              
              
                carlinmack e0507d3
              
                fix: set files_locked to .locked rather than permission
              
              
                carlinmack 31db9d0
              
                request: add file mod request template
              
              
                carlinmack f87ce73
              
                chore: refactor to reduce indentation
              
              
                carlinmack 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
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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -11,9 +11,14 @@ | |
|  | ||
| from itertools import chain | ||
|  | ||
| from flask import current_app | ||
| from flask import current_app, g | ||
| from invenio_access.permissions import system_identity | ||
| from invenio_rdm_records.records.api import RDMRecord | ||
| from invenio_rdm_records.requests.record_deletion import RecordDeletion | ||
| from invenio_rdm_records.services.config import ( | ||
| FileModificationPolicyEvaluator, | ||
| RDMRecordDeletionPolicy, | ||
| ) | ||
| from invenio_records.dictutils import dict_set | ||
| from invenio_records.errors import MissingModelError | ||
| from invenio_records_files.api import FileObject | ||
|  | @@ -109,3 +114,61 @@ def get_existing_deletion_request(record_id): | |
| ) | ||
| if existing_requests.total > 0: | ||
| return list(existing_requests)[0] | ||
|  | ||
|  | ||
| def evaluate_record_deletion(record: RDMRecord): | ||
| """Evaluate whether a given record can be deleted by an identity.""" | ||
| rec_del = RDMRecordDeletionPolicy().evaluate(g.identity, record._record) | ||
|  | ||
| immediate, request = rec_del["immediate_deletion"], rec_del["request_deletion"] | ||
| rd_enabled = immediate.enabled or request.enabled | ||
| rd_valid_user = immediate.valid_user or request.valid_user | ||
| rd_allowed = immediate.allowed or request.allowed | ||
| existing_request = get_existing_deletion_request(record.id) | ||
|  | ||
| if rd_allowed: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the feature behind a flag? should we return all this information if f.e. we in CDS do not allow any record deletions? | ||
| record_deletion = { | ||
| "enabled": rd_enabled, | ||
| "valid_user": rd_valid_user, | ||
| "allowed": rd_allowed, | ||
| "recordDeletion": rec_del, | ||
| "checklist": ( | ||
| current_app.config["RDM_IMMEDIATE_RECORD_DELETION_CHECKLIST"] | ||
| if immediate.allowed | ||
| else current_app.config["RDM_REQUEST_RECORD_DELETION_CHECKLIST"] | ||
| ), | ||
| "context": { | ||
| "files": record["files"]["count"], | ||
| "internalDoi": record["pids"]["doi"]["provider"] != "external", | ||
| }, | ||
| } | ||
| else: | ||
| record_deletion = { | ||
| "enabled": rd_enabled, | ||
| "valid_user": rd_valid_user, | ||
| "allowed": rd_allowed, | ||
| } | ||
| record_deletion["existing_request"] = ( | ||
| existing_request["links"]["self_html"] if existing_request else None | ||
| ) | ||
|  | ||
| return record_deletion | ||
|  | ||
|  | ||
| def evaluate_file_modification(record): | ||
| """Evaluate whether a given record file's can be edited by an identity.""" | ||
| file_mod = FileModificationPolicyEvaluator().evaluate(g.identity, record._record) | ||
|         
                  carlinmack marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| file_mod = file_mod["immediate_file_modification"] | ||
| fm_allowed = file_mod.allowed | ||
|  | ||
| file_modification = { | ||
| "enabled": file_mod.enabled, | ||
| "valid_user": file_mod.valid_user, | ||
| "allowed": fm_allowed, | ||
| } | ||
| if fm_allowed: | ||
| file_modification["fileModification"] = file_mod | ||
| file_modification["context"] = {} | ||
|  | ||
| return file_modification | ||
  
    
      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
    
  
  
    
              
        
          
          
            88 changes: 88 additions & 0 deletions
          
          88 
        
  ...o_app_rdm/requests_ui/templates/semantic-ui/invenio_requests/file-modification/index.html
  
  
      
      
   
        
      
      
    
  
    
      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,88 @@ | ||
| {# -*- coding: utf-8 -*- | ||
|  | ||
| This file is part of Invenio. | ||
| Copyright (C) 2016-2025 CERN. | ||
|  | ||
| Invenio is free software; you can redistribute it and/or modify it | ||
| under the terms of the MIT License; see LICENSE file for more details. | ||
| #} | ||
|  | ||
| {% extends "invenio_requests/details/index.html" %} | ||
|  | ||
| {% set active_dashboard_menu_item = 'requests' %} | ||
| {% set active_community_header_menu_item = 'requests' %} | ||
|  | ||
| {%- block request_header %} | ||
| {% set back_button_url = url_for("invenio_app_rdm_users.requests") %} | ||
| {% from "invenio_requests/macros/request_header.html" import inclusion_request_header %} | ||
| {{ inclusion_request_header( | ||
| request=invenio_request, | ||
| record=record, | ||
| accepted=request_is_accepted, | ||
| back_button_url=back_button_url, | ||
| back_button_text=_("Back to requests") | ||
| ) }} | ||
| {%- endblock request_header %} | ||
|  | ||
| {% block request_timeline %} | ||
| <div | ||
| class="ui container rdm-tab-container fluid rel-pt-2 ml-0-mobile mr-0-mobile" | ||
| id="request-request-deletion-tab-container" | ||
| > | ||
| <div | ||
| class="ui secondary pointing menu rdm-tab-menu" | ||
| id="request-deletion-request-tab" | ||
| > | ||
| <a | ||
| class="active item" | ||
| data-tab="conversation" | ||
| role="tab" | ||
| aria-selected="true" | ||
| aria-controls="conversation-tab-panel" | ||
| id="conversation-tab" | ||
| > | ||
| {{ _("Conversation") }} | ||
| </a> | ||
|  | ||
| {% if record_ui %} | ||
| <a | ||
| role="tab" | ||
| class="item" | ||
| data-tab="record" | ||
| aria-selected="false" | ||
| aria-controls="record-tab-panel" | ||
| id="record-tab" | ||
| > | ||
| {{ _("Record") }} | ||
| </a> | ||
| {% endif %} | ||
| </div> | ||
|  | ||
| <div | ||
| class="ui bottom attached tab segment active borderless p-0" | ||
| data-tab="conversation" | ||
| role="tabpanel" | ||
| aria-labelledby="conversation-tab" | ||
| id="conversation-tab-panel" | ||
| > | ||
| {{ super() }} | ||
| </div> | ||
|  | ||
| {# The record tab content needs to be last since the HTML structure is complex and breaks following tab contents #} | ||
| {% if record_ui %} | ||
| <div | ||
| class="ui bottom attached tab segment borderless" | ||
| data-tab="record" | ||
| role="tabpanel" | ||
| aria-labelledby="record-tab" | ||
| id="record-tab-panel" | ||
| hidden="hidden" | ||
| > | ||
| {% set use_theme_basic_template = false %} | ||
| {% set preview_submission_request = true %} | ||
| {% include config.APP_RDM_RECORD_LANDING_PAGE_TEMPLATE %} | ||
| </div> | ||
| {% endif %} | ||
|  | ||
| </div> | ||
| {% endblock request_timeline %} | 
  
    
      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
    
  
  
    
              
      
      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.