Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

addjust sql to get actions from anonymous user

Dmitriiba8bd5ff9c6b
diff --git a/app/models/capabilities/scopes/default.rb b/app/models/capabilities/scopes/default.rb
index ad3a7c4f970..76689cb2c20 100644
--- a/app/models/capabilities/scopes/default.rb
+++ b/app/models/capabilities/scopes/default.rb
@@ -40,10 +40,13 @@ module Capabilities::Scopes
UNION
#{default_sql_by_non_member}
UNION
+ #{default_sql_by_non_member_with_anonymous}
+ UNION
#{default_sql_by_admin}
) capabilities
SQL
+ # binding.pry
select('capabilities.*')
.from(capabilities_sql)
end
@@ -117,6 +120,32 @@ module Capabilities::Scopes
WHERE enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL
SQL
end
+
+ def default_sql_by_non_member_with_anonymous
+ <<~SQL.squish
+ SELECT DISTINCT
+ actions.id "action",
+ users.id principal_id,
+ projects.id context_id
+ FROM (#{Action.default.to_sql}) actions
+ JOIN "role_permissions" ON "role_permissions"."permission" = "actions"."permission"
+ JOIN "roles" ON "roles".id = "role_permissions".role_id AND roles.builtin = #{Role::BUILTIN_ANONYMOUS}
+ JOIN (#{Principal.visible.not_builtin_without_anonymous.not_locked_without_anonymous.to_sql}) users
+ ON 1 = 1
+ JOIN "projects"
+ ON "projects".active = true
+ AND ("projects".public = true OR EXISTS (SELECT 1
+ FROM members
+ WHERE members.project_id = projects.id
+ AND members.user_id = users.id
+ LIMIT 1))
+ LEFT OUTER JOIN enabled_modules
+ ON enabled_modules.project_id = projects.id
+ AND actions.module = enabled_modules.name
+
+ WHERE enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL
+ SQL
+ end
end
end
end
diff --git a/app/models/principals/scopes/not_builtin.rb b/app/models/principals/scopes/not_builtin.rb
index aeafd8f22c5..bed6a86e387 100644
--- a/app/models/principals/scopes/not_builtin.rb
+++ b/app/models/principals/scopes/not_builtin.rb
@@ -42,6 +42,11 @@ module Principals::Scopes
AnonymousUser.name,
DeletedUser.name])
end
+
+ def not_builtin_without_anonymous
+ where.not(type: [SystemUser.name,
+ DeletedUser.name])
+ end
end
end
end
diff --git a/app/models/principals/scopes/status.rb b/app/models/principals/scopes/status.rb
index f04f9e083d5..bcf2545174c 100644
--- a/app/models/principals/scopes/status.rb
+++ b/app/models/principals/scopes/status.rb
@@ -45,6 +45,10 @@ module Principals::Scopes
not_builtin.where.not(status: val)
end
end
+
+ def self.not_locked_without_anonymous
+ not_builtin_without_anonymous.where.not(status: :locked)
+ end
end
end
end
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
index 61c05d5431b..0cefff0e1ee 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
@@ -33,7 +33,6 @@ import {
} from '@angular/core';
import {
combineLatest,
- merge,
Observable,
} from 'rxjs';
import {
@@ -86,12 +85,7 @@ export class WorkPackageFilesTabComponent implements OnInit {
return;
}
- // ToDo: Needs to be fixed after capabilities are available for anonymous user.
- // https://community.openproject.org/projects/openproject/work_packages/44850/activity
- const canViewFileLinks = merge(
- this.currentUserService.isLoggedIn$.pipe(map((isLoggedIn) => !isLoggedIn)),
- this.currentUserService.hasCapabilities$('file_links/view', project.id),
- );
+ const canViewFileLinks = this.currentUserService.hasCapabilities$('file_links/view', project.id);
this.storages$ = this
.storagesResourceService
diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.ts
index c195c21b67f..e4de7699c1e 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -201,8 +201,6 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit {
}
private instantiateStorageInformation(fileLinks:IFileLink[]):StorageInformationBox[] {
- // ToDo: Replace with anonymous user capabilities check.
- // https://community.openproject.org/projects/openproject/work_packages/44850/activity
if (!this.isLoggedIn) {
return [];
}