Google Drive API는 파일 콘텐츠 제한, 파일 다운로드, 인쇄 또는 복사 옵션 금지를 비롯한 파일 수정 방지 방법을 여러 가지 지원합니다.
Drive 콘텐츠 제한으로 파일을 읽기 전용으로 설정하기
Google Drive 파일에 콘텐츠 제한을 추가하여 사용자가 다음 작업을 하지 못하도록 할 수 있습니다.
- 제목 수정
- 콘텐츠 수정
- 버전 업로드
- 댓글 추가 또는 수정
콘텐츠 제한은 액세스 제한이 아닙니다. 사용자는 파일의 콘텐츠를 수정할 수 없지만 액세스 수준에 따라 다른 작업은 여전히 허용됩니다. 예를 들어 수정 액세스 권한이 있는 사용자는 항목을 이동하거나 공유 설정을 변경할 수 있습니다.
드라이브의 파일에 콘텐츠 제한을 추가하거나 삭제하려면 사용자에게 연결된 permissions
이 있어야 합니다. 내 드라이브 또는 공유 드라이브에 있는 파일이나 폴더에 capabilities.canModifyEditorContentRestriction
이 있는 경우 role=writer
이 할당되어 있어야 합니다. ownerRestricted
콘텐츠 제한이 있는 내 드라이브 또는 공유 드라이브의 파일 또는 폴더의 경우 파일을 소유하거나 role=organizer
권한이 있어야 합니다. 콘텐츠 제한이 있는 항목을 보려면 사용자에게 role=reader
이상의 권한이 있어야 합니다. 전체 역할 목록은 역할 및 권한을 참고하세요. 파일의 권한을 업데이트하려면 권한 업데이트를 참고하세요.
files
리소스의 contentRestrictions.readOnly
불리언 필드를 사용하여 콘텐츠 제한을 설정할 수 있습니다. 항목에 콘텐츠 제한을 설정하면 기존 제한이 덮어쓰여집니다.
콘텐츠 제한 시나리오
Drive 항목에 대한 콘텐츠 제한은 사용자에게 콘텐츠를 변경해서는 안 된다는 신호를 보냅니다. 이러한 문제가 발생하는 이유는 다음과 같습니다.
- 검토 또는 감사 기간 동안 공동작업 문서 작업을 일시중지합니다.
- 항목을 승인과 같은 최종 상태로 설정합니다.
- 민감한 회의 중에 변경 방지
- 자동화된 시스템에서 처리하는 워크플로의 외부 변경을 금지합니다.
- Google Apps Script 및 Google Workspace 부가기능의 수정 제한
- 문서의 실수로 인한 수정 방지
콘텐츠 제한은 콘텐츠를 관리하는 데 도움이 되지만, 충분한 권한이 있는 사용자가 항목 작업을 계속하지 못하도록 하는 것은 아닙니다. 또한 불변 레코드를 만드는 방법도 아닙니다. Drive 콘텐츠 제한은 변경 가능하므로 항목에 대한 콘텐츠 제한이 항목이 변경되지 않음을 보장하지는 않습니다.
콘텐츠 제한이 있는 파일 관리
Google Docs, Google Sheets, Google Slides 및 기타 모든 파일에는 콘텐츠 제한이 포함될 수 있습니다.
상품에 대한 콘텐츠 제한으로 인해 다음과 같은 제목과 콘텐츠를 변경할 수 없습니다.
- 댓글 및 제안 (Docs, Sheets, Slides, 바이너리 파일)
- 바이너리 파일 버전
- Docs의 텍스트 및 서식
- Sheets의 텍스트 또는 수식, Sheets 레이아웃, Sheets의 인스턴스
- 슬라이드의 모든 콘텐츠와 슬라이드의 순서 및 번호
특정 파일 형식에는 콘텐츠 제한이 포함될 수 없습니다. 몇 가지 예는 다음과 같습니다.
- Google Forms
- Google Sites
- Google Drawings
- 바로가기 및 서드 파티 바로가기 자세한 내용은 앱에서 저장한 콘텐츠의 바로가기 파일 만들기 및 Drive 파일의 바로가기 만들기를 참고하세요.
콘텐츠 제한 추가
파일 콘텐츠 제한을 추가하려면 contentRestrictions.readOnly
필드가 true
로 설정된 files.update
메서드를 사용합니다. '계약 완료'와 같이 제한을 추가하는 이유를 설명하는 선택적 reason
를 추가합니다. 다음 코드 샘플은 콘텐츠 제한을 추가하는 방법을 보여줍니다.
자바
File updatedFile =
new File()
.setContentRestrictions(
ImmutableList.of(new ContentRestriction().setReadOnly(true).setReason("Finalized contract."));
File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();
Python
content_restriction = {'readOnly': True, 'reason':'Finalized contract.'}
response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();
Node.js
/**
* Set a content restriction on a file.
* @return{obj} updated file
**/
async function addContentRestriction() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
const contentRestriction = {
'readOnly': True,
'reason': 'Finalized contract.',
};
const updatedFile = {
'contentRestrictions': [contentRestriction],
};
try {
const response = await service.files.update({
fileId: 'FILE_ID',
resource: updatedFile,
fields: 'contentRestrictions',
});
return response;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
FILE_ID을 수정하려는 파일의 fileId
로 바꿉니다.
샘플 코드를 실행하면 파일이 콘텐츠 제한되고 Google Drive 사용자 인터페이스(UI) 내 파일 이름 옆에 잠금 기호( )가 표시됩니다. 파일이 읽기 전용으로 전환되었습니다.
콘텐츠 제한 삭제
파일 콘텐츠 제한을 삭제하려면 contentRestrictions.readOnly
필드가 false
로 설정된 files.update
메서드를 사용합니다. 다음 코드 샘플은 콘텐츠 제한을 삭제하는 방법을 보여줍니다.
자바
File updatedFile =
new File()
.setContentRestrictions(
ImmutableList.of(new ContentRestriction().setReadOnly(false));
File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();
Python
content_restriction = {'readOnly': False}
response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();
Node.js
/**
* Remove a content restriction on a file.
* @return{obj} updated file
**/
async function removeContentRestriction() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
const contentRestriction = {
'readOnly': False,
};
const updatedFile = {
'contentRestrictions': [contentRestriction],
};
try {
const response = await service.files.update({
fileId: 'FILE_ID',
resource: updatedFile,
fields: 'contentRestrictions',
});
return response;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
FILE_ID을 수정하려는 파일의 fileId
로 바꿉니다.
샘플 코드를 실행하면 파일이 더 이상 콘텐츠 제한되지 않습니다.
또한 드라이브 UI를 사용하여 콘텐츠 제한을 삭제하고 콘텐츠 수정 권한을 허용할 수도 있습니다 (올바른 권한이 있는 경우). 이 작업을 실행하는 두 가지 방법은 다음과 같습니다.
드라이브에서 콘텐츠 제한이 있는 파일을 마우스 오른쪽 버튼으로 클릭하고 잠금 해제
를 클릭합니다.그림 2. Drive 파일 목록 내에서 파일 콘텐츠 제한을 삭제합니다. 콘텐츠 제한이 있는 파일을 열고 (잠금 모드) > 파일 잠금 해제를 클릭합니다.
그림 3. 문서 내 파일 콘텐츠 제한을 삭제합니다.
콘텐츠 제한 확인
콘텐츠 제한을 확인하려면 contentRestrictions
반환 필드와 함께 files.get
메서드를 사용합니다. 다음 코드 샘플은 콘텐츠 제한의 상태를 확인하는 방법을 보여줍니다.
자바
File response = driveService.files().get("FILE_ID").setFields("contentRestrictions").execute();
Python
response = drive_service.files().get(fileId="FILE_ID", fields = "contentRestrictions").execute();
Node.js
/**
* Get content restrictions on a file.
* @return{obj} updated file
**/
async function fetchContentRestrictions() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
try {
const response = await service.files.get({
fileId: 'FILE_ID',
fields: 'contentRestrictions',
});
return response;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
FILE_ID을 확인할 파일의 fileId
로 바꿉니다.
샘플 코드를 실행하면 메서드가 있는 경우 ContentRestriction
리소스를 반환합니다.
파일 소유자만 수정할 수 있는 콘텐츠 제한 추가
파일 소유자만 메커니즘을 전환할 수 있도록 파일 콘텐츠 제한을 추가하려면 contentRestrictions.ownerRestricted
불리언 필드가 true
로 설정된 files.update
메서드를 사용합니다. 다음 코드 샘플은 파일 소유자에게만 콘텐츠 제한을 추가하는 방법을 보여줍니다.
자바
File updatedFile =
new File()
.setContentRestrictions(
ImmutableList.of(new ContentRestriction().setReadOnly(true).setOwnerRestricted(true).setReason("Finalized contract."));
File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();
Python
content_restriction = {'readOnly': True, 'ownerRestricted': True, 'reason':'Finalized contract.'}
response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();
Node.js
/**
* Set an owner restricted content restriction on a file.
* @return{obj} updated file
**/
async function addOwnerRestrictedContentRestriction() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
const contentRestriction = {
'readOnly': True,
'ownerRestricted': True,
'reason': 'Finalized contract.',
};
const updatedFile = {
'contentRestrictions': [contentRestriction],
};
try {
const response = await service.files.update({
fileId: 'FILE_ID',
resource: updatedFile,
fields: 'contentRestrictions',
});
return response;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
FILE_ID을 수정하려는 파일의 fileId
로 바꿉니다.
샘플 코드를 실행하면 파일이 콘텐츠 제한되고 파일 소유자만 파일을 삭제할 수 있습니다. 파일 소유자인 경우 Drive 사용자 인터페이스 (UI) 내의 파일 이름 옆에 활성 잠금 기호( )가 표시됩니다. 소유자가 아닌 경우 잠금 기호가 흐리게 표시됩니다.
ownerRestricted
플래그를 삭제하려면 contentRestrictions.ownerRestricted
필드가 false
로 설정된 files.update
메서드를 사용합니다.
콘텐츠 제한 기능
files
리소스에는 파일에서 작업을 실행할 수 있는지 여부를 나타내는 불리언 capabilities
필드의 컬렉션이 포함됩니다.
콘텐츠 제한에는 다음 capabilities
이 포함됩니다.
capabilities.canModifyEditorContentRestriction
: 현재 사용자가 콘텐츠 제한을 추가하거나 수정할 수 있는지 여부입니다.capabilities.canModifyOwnerContentRestriction
: 현재 사용자가 소유자 콘텐츠 제한을 추가하거나 수정할 수 있는지 여부입니다.capabilities.canRemoveContentRestriction
: 현재 사용자가 적용된 콘텐츠 제한을 삭제할 수 있는지 여부입니다 (있는 경우).
자세한 내용은 파일 기능 이해하기를 참고하세요.
파일 capabilities
가져오기의 예는 파일 기능 가져오기를 참고하세요.
사용자가 파일을 다운로드, 인쇄, 복사하지 못하도록 차단하기
사용자가 Drive, Docs, Sheets, Slides에서 파일을 다운로드, 인쇄, 복사하는 방법을 제한할 수 있습니다.
사용자가 파일의 소유자 또는 주최자가 적용한 다운로드 제한을 변경할 수 있는지 확인하려면 capabilities.canChangeItemDownloadRestriction
불리언 필드를 확인하세요. capabilities.canChangeItemDownloadRestriction
이 true
로 설정되면 파일에 다운로드 제한을 적용할 수 있습니다. 자세한 내용은 파일 기능 이해하기를 참고하세요.
파일에 다운로드 제한을 적용하려면 files.update
메서드를 사용하여 downloadRestrictions
필드를 설정합니다. DownloadRestrictionsMetadata
객체를 사용하여 필드를 설정할 수 있습니다.
DownloadRestrictionsMetadata
객체에는 itemDownloadRestriction
및 effectiveDownloadRestrictionWithContext
의 두 필드가 있습니다. 두 필드 모두 읽을 수 있지만 itemDownloadRestriction
만 설정할 수 있습니다. itemDownloadRestriction
필드는 DownloadRestriction
객체를 반환합니다. DownloadRestriction
객체에는 restrictedForReaders
및 restrictedForWriters
라는 두 개의 별도 불리언 필드가 있습니다.
itemDownloadRestriction
필드를 설정하면 소유자 또는 주최자가 파일의 다운로드 제한을 직접 적용합니다. 공유 드라이브 설정 또는 데이터 손실 방지 (DLP) 규칙은 고려하지 않습니다. 자세한 내용은 DLP 정보를 참고하세요.
restrictedForWriters
필드를 true
로 설정하여 itemDownloadRestriction
필드를 업데이트하면 restrictedForReaders
이 true
임을 의미합니다. 마찬가지로 restrictedForWriters
를 true
로 설정하고 restrictedForReaders
를 false
로 설정하는 것은 restrictedForWriters
와 restrictedForReaders
를 모두 true
로 설정하는 것과 같습니다.
effectiveDownloadRestrictionWithContext
필드의 경우 다운로드 제한이 파일에 적용되며 모든 제한 설정과 DLP 규칙이 고려됩니다.
effectiveDownloadRestrictionWithContext
필드는 restrictedForWriters
또는 restrictedForReaders
로 설정할 수 있습니다. 파일 설정, 공유 드라이브 설정 또는 DLP 규칙 (컨텍스트가 있는 규칙 포함)에서 해당 역할에 대한 다운로드 또는 복사 제한 설정이 있는 경우 값은 true
로 설정되고, 그렇지 않으면 false
로 설정됩니다.
이전 버전과의 호환성
DownloadRestriction
객체를 사용하여 사용자가 파일을 다운로드, 인쇄, 복사하는 방법을 적용하는 것이 좋습니다.
copyRequiresWriterPermission
불리언 필드를 사용하려면 필드에서 읽어오는 것과 필드에 쓰는 것 모두 기능이 다릅니다.
copyRequiresWriterPermission
필드의 검색된 값은 role=commenter
또는 role=reader
권한이 있는 사용자가 드라이브 내에서 파일을 다운로드, 인쇄 또는 복사할 수 있는지를 반영합니다. 필드 값은 파일 설정, 공유 드라이브 설정 또는 DLP 규칙의 조합을 반영합니다. 하지만 DLP 규칙의 컨텍스트 평가는 포함되지 않습니다.
copyRequiresWriterPermission
필드를 false
로 설정하면 restrictedForWriters
및 restrictedForReaders
필드가 모두 false
로 업데이트됩니다. 즉, 모든 사용자에 대해 다운로드 또는 복사 제한 설정이 삭제됩니다.
다운로드, 인쇄, 복사 기능을 제어하는 필드
다음 표에는 다운로드, 인쇄, 복사 기능에 영향을 미치는 files
리소스 필드가 나와 있습니다.
필드 | 설명 | 버전 |
---|---|---|
capabilities.canCopy |
현재 사용자가 파일을 복사할 수 있는지 여부입니다. | v2 및 v3 |
capabilities.canDownload |
현재 사용자가 파일을 다운로드할 수 있는지 여부입니다. | v2 및 v3 |
capabilities.canChangeCopyRequiresWriterPermission |
현재 사용자가 파일의 copyRequiresWriterPermission 제한을 변경할 수 있는지 여부입니다. |
v2 및 v3 |
capabilities.canChangeItemDownloadRestriction |
현재 사용자가 파일의 다운로드 제한을 변경할 수 있는지 여부입니다. | v3만 해당 |
copyRequiresWriterPermission |
읽기 권한 사용자 및 댓글 작성자의 이 파일 복사, 인쇄, 다운로드 옵션을 사용 중지할지 여부입니다. | v2 및 v3 |
downloadRestrictions |
파일에 적용된 다운로드 제한입니다. | v3만 해당 |