Google Drive API, फ़ाइल में बदलाव को रोकने के कई तरीके उपलब्ध कराता है. इनमें फ़ाइल के कॉन्टेंट पर पाबंदी लगाना और फ़ाइलों को डाउनलोड, प्रिंट या कॉपी करने के विकल्प पर पाबंदी लगाना शामिल है.
Drive में मौजूद कॉन्टेंट पर पाबंदियां लगाने की मदद से, फ़ाइलों को सिर्फ़ पढ़ने के लिए बनाया जा सकता है
उपयोगकर्ताओं को ऐसा करने से रोकने के लिए, Google Drive की किसी फ़ाइल में कॉन्टेंट पर पाबंदी लगाई जा सकती है:
- टाइटल में बदलाव करना
- कॉन्टेंट में बदलाव करना
- वर्शन अपलोड करना
- टिप्पणियां जोड़ना या उनमें बदलाव करना
कॉन्टेंट पर पाबंदियां लागू करने का तरीका, Drive में मौजूद आइटम के कॉन्टेंट को रीड-ओनली मोड में रखता है. इसके लिए, आइटम की ऐक्सेस अनुमतियों में बदलाव नहीं किया जाता. इसका मतलब है कि इस पर ऐक्सेस से जुड़ी कोई पाबंदी नहीं है. हालांकि उपयोगकर्ता फ़ाइल की सामग्री में बदलाव नहीं कर सकते, फिर भी ऐक्सेस लेवल के आधार पर दूसरे कामों की अनुमति दी जाती है (उदाहरण के लिए, बदलाव करने का ऐक्सेस रखने वाला उपयोगकर्ता अब भी किसी आइटम को एक जगह से दूसरी जगह ले जा सकता है या उसकी शेयर करने की सेटिंग बदल सकता है).
Drive में किसी फ़ाइल पर कॉन्टेंट पर पाबंदी लगाने या हटाने के लिए, उपयोगकर्ता के पास उनसे जुड़ी
अनुमतियां होनी चाहिए. 'मेरी ड्राइव' में मौजूद किसी फ़ाइल या फ़ोल्डर को या 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 में इंस्टेंस
- स्लाइड में मौजूद सारा कॉन्टेंट और स्लाइड का क्रम और उनकी संख्या
कुछ फ़ाइल टाइप में कॉन्टेंट पर पाबंदी नहीं लगाई जा सकती. यहां कुछ उदाहरण दिए गए हैं:
- Google Forms
- Google Sites
- Google Drawings
- शॉर्टकट और तीसरे पक्ष के शॉर्टकट. ज़्यादा जानकारी के लिए, अपने ऐप्लिकेशन में सेव किए गए कॉन्टेंट के लिए शॉर्टकट फ़ाइल बनाना और Drive में मौजूद फ़ाइल का शॉर्टकट बनाना देखें.
कॉन्टेंट पर पाबंदी लगाएं
किसी फ़ाइल के लिए कॉन्टेंट पर पाबंदी लगाने के लिए, files.update
तरीके का इस्तेमाल करें.
contentRestrictions.readOnly
फ़ील्ड को true
पर सेट करें. पाबंदी क्यों जोड़ी जा रही है, इसके लिए एक वैकल्पिक reason
जोड़ें, जैसे कि "पूरा अनुबंध". नीचे दिए गए कोड सैंपल में, कॉन्टेंट पर पाबंदी लगाने का तरीका बताया गया है:
Java
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;
}
}
जिस फ़ाइल में आपको बदलाव करना है उसके fileId
से FILE_ID को बदलें.
सैंपल कोड का इस्तेमाल करने पर, फ़ाइल पर पाबंदी लगी होती है. साथ ही, Google Drive के यूज़र इंटरफ़ेस (यूआई) में फ़ाइल के नाम के बगल में, एक लॉक सिंबल ( ) दिखता है. फ़ाइल अब सिर्फ़ रीड-ओनली मोड में है.
कॉन्टेंट पर लगी पाबंदी हटाना
फ़ाइल के कॉन्टेंट पर लगी पाबंदी हटाने के लिए, files.update
तरीके का इस्तेमाल करें.
इसके लिए, contentRestrictions.readOnly
फ़ील्ड को false
पर सेट करें. नीचे दिए गए कोड सैंपल में, कॉन्टेंट पर पाबंदी
हटाने का तरीका बताया गया है:
Java
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;
}
}
जिस फ़ाइल में आपको बदलाव करना है उसके fileId
से FILE_ID को बदलें.
सैंपल कोड चलाने के बाद, फ़ाइल के कॉन्टेंट पर कोई पाबंदी नहीं रहती.
कॉन्टेंट पर लगी पाबंदी को हटाने और कॉन्टेंट में बदलाव करने की अनुमति देने के लिए, Drive के यूज़र इंटरफ़ेस (यूआई) का इस्तेमाल भी किया जा सकता है. हालांकि, इसके लिए ज़रूरी है कि आपके पास सही अनुमतियां हों. ऐसा करने के लिए दो विकल्प हैं:
Drive में, कॉन्टेंट पर पाबंदी वाली फ़ाइल पर राइट क्लिक करें. इसके बाद,
अनलॉक करें पर क्लिक करें.कॉन्टेंट पर पाबंदी वाली फ़ाइल खोलें और (लॉक मोड) > फ़ाइल अनलॉक करें पर क्लिक करें.
कॉन्टेंट पर पाबंदी की जांच करना
कॉन्टेंट पर लगी पाबंदी का पता लगाने के लिए, contentRestrictions
के दिखाए गए फ़ील्ड के साथ files.get
तरीके का इस्तेमाल करें. नीचे दिए गए कोड सैंपल में, कॉन्टेंट पर पाबंदी
की स्थिति जांचने का तरीका बताया गया है:
Java
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
तरीके का इस्तेमाल करें. नीचे दिए गए कोड सैंपल में बताया गया है कि सिर्फ़ फ़ाइल के मालिकों के लिए, कॉन्टेंट पर पाबंदी कैसे लगाई जाए:
Java
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;
}
}
जिस फ़ाइल में आपको बदलाव करना है उसके fileId
से FILE_ID को बदलें.
सैंपल कोड चलाने पर, फ़ाइल पर कॉन्टेंट नहीं दिखता और उसे सिर्फ़ फ़ाइल के मालिक ही हटा सकते हैं. अगर आपके पास फ़ाइल का मालिकाना हक है, तो Drive के यूज़र इंटरफ़ेस (यूआई) में फ़ाइल के नाम के बगल में, एक ऐक्टिव लॉक सिंबल ( ) दिखता है. अगर आप मालिक नहीं हैं, तो लॉक सिंबल की रोशनी कम हो जाती है.
ownerRestricted
फ़्लैग हटाने के लिए, files.update
तरीके का इस्तेमाल करें. इसमें contentRestrictions.ownerRestricted
फ़ील्ड को false
पर सेट करें.
कॉन्टेंट पर पाबंदी लगाने की सुविधाएं
files
संसाधन में बूलियन capabilities
फ़ील्ड का कलेक्शन होता है. इसका इस्तेमाल यह बताने के लिए किया जाता है कि किसी फ़ाइल पर कार्रवाई की जा सकती है या नहीं.
कॉन्टेंट पर पाबंदियों में, ये capabilities
शामिल होते हैं:
capabilities.canModifyEditorContentRestriction
: क्या मौजूदा उपयोगकर्ता कॉन्टेंट पर पाबंदी को जोड़ सकता है या उसमें बदलाव कर सकता है.capabilities.canModifyOwnerContentRestriction
: मौजूदा उपयोगकर्ता, मालिक के कॉन्टेंट पर पाबंदी को जोड़ सकता है या उसमें बदलाव कर सकता है.capabilities.canRemoveContentRestriction
: अगर मौजूदा उपयोगकर्ता, लागू की गई कॉन्टेंट पर लगी पाबंदी को हटा सकता है (अगर यह मौजूद है), तो.
ज़्यादा जानकारी के लिए, क्षमताएं देखें.
capabilities
फ़ाइल को ऐक्सेस करने के उदाहरण के लिए, उपयोगकर्ता की अनुमतियों की पुष्टि करना देखें.
उपयोगकर्ताओं को अपनी फ़ाइल डाउनलोड, प्रिंट या कॉपी करने से रोकें
आप यह तय कर सकते हैं कि role=commenter
या role=reader
की अनुमतियों वाले उपयोगकर्ता, Drive, Docs, Sheets, और Slides में
फ़ाइलों को कैसे डाउनलोड, प्रिंट, और कॉपी कर सकते हैं.
फ़ाइलों को डाउनलोड, प्रिंट, और कॉपी करने के विकल्प हटाने के लिए, files.update
तरीके का इस्तेमाल करें. इसके लिए, copyRequiresWriterPermission
बूलियन फ़ील्ड को true
पर सेट करें.