|
821 | 821 | end |
822 | 822 | end |
823 | 823 |
|
| 824 | + context 'inherited edit permissions' do |
| 825 | + let!(:unpublished_media_object) { FactoryBot.create(:media_object, visibility: 'private', collection: collection) } |
| 826 | + let!(:disabled_media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, disable_inheritance: true) } |
| 827 | + let!(:inherited_media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection) } |
| 828 | + let(:collection) { FactoryBot.create(:collection, managers: [user.username]) } |
| 829 | + |
| 830 | + context 'for user' do |
| 831 | + context 'from collection level' do |
| 832 | + it "should return list of media_objects that the user is authorized to view" do |
| 833 | + get 'index', format: 'json' |
| 834 | + expect(json.count).to eq(4) |
| 835 | + end |
| 836 | + end |
| 837 | + |
| 838 | + context 'from unit level' do |
| 839 | + let(:collection) { FactoryBot.create(:collection, unit: unit) } |
| 840 | + let(:unit) { FactoryBot.create(:unit, managers: [user.username]) } |
| 841 | + |
| 842 | + it "should return list of media_objects that the user is authorized to view" do |
| 843 | + get 'index', format: 'json' |
| 844 | + expect(json.count).to eq(4) |
| 845 | + end |
| 846 | + end |
| 847 | + end |
| 848 | + end |
| 849 | + |
824 | 850 | context 'inherited read permissions' do |
825 | 851 | let!(:unpublished_media_object) { FactoryBot.create(:media_object, visibility: 'private', collection: collection) } |
826 | 852 | let!(:disabled_media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, disable_inheritance: true) } |
|
1050 | 1076 |
|
1051 | 1077 | context "inherited access" do |
1052 | 1078 | context "for user" do |
| 1079 | + context 'inherited edit permissions' do |
| 1080 | + context "from collection" do |
| 1081 | + let(:user) { FactoryBot.create(:user) } |
| 1082 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection) } |
| 1083 | + let(:collection) { FactoryBot.create(:collection, managers: [user.username]) } |
| 1084 | + |
| 1085 | + it "should be available to an edit user granted access at collection level" do |
| 1086 | + login_user user.username |
| 1087 | + get 'show', params: { id: media_object.id } |
| 1088 | + expect(response.response_code).to eq(200) |
| 1089 | + end |
| 1090 | + |
| 1091 | + context "when inheritance disabled" do |
| 1092 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection, disable_inheritance: true) } |
| 1093 | + |
| 1094 | + it "should be available to an edit user granted access at collection level" do |
| 1095 | + login_user user.username |
| 1096 | + get 'show', params: { id: media_object.id } |
| 1097 | + expect(response.response_code).to eq(200) |
| 1098 | + end |
| 1099 | + |
| 1100 | + context "and overridden visibility restricts from non-private to private" do |
| 1101 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public', managers: [user.username]) } |
| 1102 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, disable_inheritance: true) } |
| 1103 | + |
| 1104 | + it "should be available to an edit user granted access at collection level" do |
| 1105 | + login_user user.username |
| 1106 | + get 'show', params: { id: media_object.id } |
| 1107 | + expect(response.response_code).to eq(200) |
| 1108 | + end |
| 1109 | + end |
| 1110 | + end |
| 1111 | + end |
| 1112 | + |
| 1113 | + context "from unit" do |
| 1114 | + let(:user) { FactoryBot.create(:user) } |
| 1115 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection) } |
| 1116 | + let(:collection) { FactoryBot.create(:collection, unit: unit) } |
| 1117 | + let(:unit) { FactoryBot.create(:unit, managers: [user.username]) } |
| 1118 | + |
| 1119 | + it "should be available to an edit user granted access at unit level" do |
| 1120 | + login_user user.username |
| 1121 | + get 'show', params: { id: media_object.id } |
| 1122 | + expect(response.response_code).to eq(200) |
| 1123 | + end |
| 1124 | + |
| 1125 | + context "when inheritance disabled" do |
| 1126 | + let(:media_object) { FactoryBot.create(:published_media_object, :with_master_file, collection: collection, disable_inheritance: true) } |
| 1127 | + |
| 1128 | + it "should be available to an edit user granted access at unit level" do |
| 1129 | + login_user user.username |
| 1130 | + get 'show', params: { id: media_object.id } |
| 1131 | + expect(response.response_code).to eq(200) |
| 1132 | + end |
| 1133 | + |
| 1134 | + context "and overridden visibility restricts from non-private to private" do |
| 1135 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public', unit: unit) } |
| 1136 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, disable_inheritance: true) } |
| 1137 | + |
| 1138 | + it "should be available to an edit user granted access at collection level" do |
| 1139 | + login_user user.username |
| 1140 | + get 'show', params: { id: media_object.id } |
| 1141 | + expect(response.response_code).to eq(200) |
| 1142 | + end |
| 1143 | + end |
| 1144 | + end |
| 1145 | + end |
| 1146 | + end |
| 1147 | + |
1053 | 1148 | context "from collection" do |
1054 | 1149 | let(:user) { FactoryBot.create(:user) } |
1055 | 1150 | let(:mo_member) { FactoryBot.create(:user) } |
1056 | | - let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username]) } |
| 1151 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection, read_users: [mo_member.username]) } |
1057 | 1152 | let(:collection) { FactoryBot.create(:collection, default_read_users: [user.username]) } |
1058 | 1153 |
|
1059 | 1154 | it "should be available to a user granted access at collection level" do |
|
1064 | 1159 |
|
1065 | 1160 | context "when inheritance disabled" do |
1066 | 1161 | let(:multi_user) { FactoryBot.create(:user) } |
1067 | | - let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username, multi_user.username], disable_inheritance: true) } |
| 1162 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection, read_users: [mo_member.username, multi_user.username], disable_inheritance: true) } |
1068 | 1163 | let(:collection) { FactoryBot.create(:collection, default_read_users: [user.username, multi_user.username]) } |
1069 | 1164 |
|
1070 | 1165 | it "should block access to inherited user" do |
|
1084 | 1179 | get 'show', params: { id: media_object.id } |
1085 | 1180 | expect(response.response_code).to eq(200) |
1086 | 1181 | end |
1087 | | - end |
| 1182 | + |
| 1183 | + context "and overridden visibility restricts from non-private to private" do |
| 1184 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public') } |
| 1185 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username], disable_inheritance: true) } |
| 1186 | + |
| 1187 | + it "should not block access to non-inherited user" do |
| 1188 | + login_user mo_member.username |
| 1189 | + get 'show', params: { id: media_object.id } |
| 1190 | + expect(response.response_code).to eq(200) |
| 1191 | + end |
| 1192 | + end |
| 1193 | + end |
1088 | 1194 | end |
1089 | 1195 |
|
1090 | 1196 | context "from unit" do |
1091 | 1197 | let(:user) { FactoryBot.create(:user) } |
1092 | 1198 | let(:mo_member) { FactoryBot.create(:user) } |
1093 | | - let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username]) } |
| 1199 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection, read_users: [mo_member.username]) } |
1094 | 1200 | let(:collection) { FactoryBot.create(:collection, unit: unit) } |
1095 | 1201 | let(:unit) { FactoryBot.create(:unit, default_read_users: [user.username]) } |
1096 | 1202 |
|
|
1102 | 1208 |
|
1103 | 1209 | context "when inheritance disabled" do |
1104 | 1210 | let(:multi_user) { FactoryBot.create(:user) } |
1105 | | - let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username, multi_user.username], disable_inheritance: true) } |
| 1211 | + let(:media_object) { FactoryBot.create(:published_media_object, collection: collection, read_users: [mo_member.username, multi_user.username], disable_inheritance: true) } |
1106 | 1212 | let(:collection) { FactoryBot.create(:collection, unit: unit) } |
1107 | 1213 | let(:unit) { FactoryBot.create(:unit, default_read_users: [user.username, multi_user.username]) } |
1108 | 1214 |
|
|
1123 | 1229 | get 'show', params: { id: media_object.id } |
1124 | 1230 | expect(response.response_code).to eq(200) |
1125 | 1231 | end |
| 1232 | + |
| 1233 | + context "and overridden visibility restricts from non-private to private" do |
| 1234 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public', unit: unit) } |
| 1235 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_users: [mo_member.username], disable_inheritance: true) } |
| 1236 | + |
| 1237 | + it "should not block access to non-inherited user" do |
| 1238 | + login_user mo_member.username |
| 1239 | + get 'show', params: { id: media_object.id } |
| 1240 | + expect(response.response_code).to eq(200) |
| 1241 | + end |
| 1242 | + end |
1126 | 1243 | end |
1127 | 1244 | end |
1128 | 1245 | end |
|
1175 | 1292 | get 'show', params: { id: media_object.id } |
1176 | 1293 | expect(response.response_code).to eq(200) |
1177 | 1294 | end |
| 1295 | + |
| 1296 | + context "and overridden visibility restricts from non-private to private" do |
| 1297 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public') } |
| 1298 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_groups: [group.name], disable_inheritance: true) } |
| 1299 | + |
| 1300 | + it "should not block access to non-inherited group" do |
| 1301 | + allow(controller).to receive(:current_user).and_return(group_member) |
| 1302 | + allow(group_member).to receive(:groups).and_return([group.name]) |
| 1303 | + login_user group_member.username |
| 1304 | + get 'show', params: { id: media_object.id } |
| 1305 | + expect(response.response_code).to eq(200) |
| 1306 | + end |
| 1307 | + end |
1178 | 1308 | end |
1179 | 1309 | end |
1180 | 1310 |
|
|
1221 | 1351 | get 'show', params: { id: media_object.id } |
1222 | 1352 | expect(response.response_code).to eq(200) |
1223 | 1353 | end |
| 1354 | + |
| 1355 | + context "and overridden visibility restricts from non-private to private" do |
| 1356 | + let(:collection) { FactoryBot.create(:collection, default_visibility: 'public', unit: unit) } |
| 1357 | + let(:media_object) { FactoryBot.create(:published_media_object, visibility: 'private', collection: collection, read_groups: [group.name], disable_inheritance: true) } |
| 1358 | + |
| 1359 | + it "should not block access to non-inherited group" do |
| 1360 | + allow(controller).to receive(:current_user).and_return(group_member) |
| 1361 | + allow(group_member).to receive(:groups).and_return([group.name]) |
| 1362 | + login_user group_member.username |
| 1363 | + get 'show', params: { id: media_object.id } |
| 1364 | + expect(response.response_code).to eq(200) |
| 1365 | + end |
| 1366 | + end |
1224 | 1367 | end |
1225 | 1368 | end |
1226 | 1369 | end |
|
0 commit comments