Revision 58476
Added by Konstantina Galouni about 4 years ago
modules/uoa-admin-tools/trunk/update_db.js | ||
---|---|---|
1449 | 1449 |
} |
1450 | 1450 |
} |
1451 | 1451 |
|
1452 |
function createNewPagesForConnect() { |
|
1453 |
// Connect pages |
|
1454 |
publicationsId = db.page.insertOne({ |
|
1455 |
"name": "Publications", |
|
1456 |
"route": "/publications", |
|
1457 |
"type": "other", |
|
1458 |
"connect": true, |
|
1459 |
"openaire": false, |
|
1460 |
"communities": false, |
|
1461 |
"entities": [], |
|
1462 |
"top": true, |
|
1463 |
"bottom": false, |
|
1464 |
"right": false, |
|
1465 |
"left": false |
|
1466 |
}).insertedId.str; |
|
1467 |
print("Connect: Creating Publications page with id " + publicationsId); |
|
1468 |
|
|
1469 |
var connectCommunity = db.community.findOne({pid: "connect"}); |
|
1470 |
connect_pages = connectCommunity.pages; |
|
1471 |
connect_pages[publicationsId] = true; |
|
1472 |
db.community.update({"pid": "connect"}, {$set: {"pages": connect_pages}}); |
|
1473 |
print("Add Publications page with id " + publicationsId + " on community connect"); |
|
1474 |
} |
|
1475 |
|
|
1476 |
function createNewPagesForCommunities() { |
|
1477 |
// Community pages |
|
1478 |
sourcesId = db.page.insertOne({"name" : "Sources and methology", "route" : "/content", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str; |
|
1479 |
print("Communities: Creating Sources and methology page with id " + sourcesId); |
|
1480 |
|
|
1481 |
projectsId = db.page.insertOne({"name" : "Projects and funding opportunities", "route" : "/projects", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str; |
|
1482 |
print("Communities: Creating Projects page with id " + projectsId); |
|
1483 |
|
|
1484 |
nationalBulletinsId = db.page.insertOne({"name" : "National Bulletins", "route" : "/national-bulletins", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str; |
|
1485 |
print("Communities: Creating National Bulletins page with id " + nationalBulletinsId); |
|
1486 |
|
|
1487 |
subjectsId = db.page.insertOne({"name" : "Subjects", "route" : "/subjects", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":true,"right":false,"left":false}).insertedId.str; |
|
1488 |
print("Communities: Creating Subjects page with id " + subjectsId); |
|
1489 |
|
|
1490 |
communities = db.community.find().map( function(community) { return community; } ); |
|
1491 |
for (var i = 0; i < communities.length; i++) { |
|
1492 |
community_pages = communities[i].pages; |
|
1493 |
|
|
1494 |
community_pages[sourcesId] = true; |
|
1495 |
community_pages[projectsId] = false; |
|
1496 |
community_pages[nationalBulletinsId] = false; |
|
1497 |
community_pages[subjectsId] = false; |
|
1498 |
|
|
1499 |
community_pid = communities[i].pid; |
|
1500 |
db.community.update({ "pid" : community_pid },{$set: { "pages": community_pages}}); |
|
1501 |
print("Add Sources and methology page with id " + sourcesId + " on community " + community_pid); |
|
1502 |
print("Add Projects page with id " + projectsId + " on community " + community_pid); |
|
1503 |
print("Add National Bulletins page with id " + nationalBulletinsId + " on community " + community_pid); |
|
1504 |
print("Add Subjects page with id " + subjectsId + " on community " + community_pid); |
|
1505 |
} |
|
1506 |
} |
|
1507 |
|
|
1508 |
function removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage() { |
|
1509 |
contentId = db.page.find({route: "/content", "connect": true}).map(function (page) { |
|
1510 |
return page._id.str; |
|
1511 |
}).toString(); |
|
1512 |
db.page.remove({"route": "/content", "connect": true}); |
|
1513 |
print("Remove Content Policy page with id " + contentId + " and connect: true"); |
|
1514 |
|
|
1515 |
var connectCommunity = db.community.findOne({pid: "connect"}); |
|
1516 |
// connect_pages = connectCommunity.pages; |
|
1517 |
// delete connect_pages[contentId]; |
|
1518 |
// db.community.update({"pid": "connect"}, {$set: {"pages": connect_pages}}); |
|
1519 |
// print("Remove Content Policy page with id " + contentId + " on community: connect"); |
|
1520 |
|
|
1521 |
communities_contentId = db.page.find({route: "/content", "communities": true}).map(function (page) { |
|
1522 |
return page._id.str; |
|
1523 |
}).toString(); |
|
1524 |
communities = db.community.find().map(function (community) { |
|
1525 |
return community; |
|
1526 |
}); |
|
1527 |
for (var i = 0; i < communities.length; i++) { |
|
1528 |
community_pages = communities[i].pages; |
|
1529 |
delete community_pages[contentId]; |
|
1530 |
db.community.update({"pid": communities[i].pid}, {$set: {"pages": community_pages}}); |
|
1531 |
print("Remove Content Policy page with id " + contentId + " on community: "+communities[i].pid); |
|
1532 |
|
|
1533 |
db.pageHelpContent.find({ |
|
1534 |
community: connectCommunity._id.str, |
|
1535 |
page: contentId |
|
1536 |
}).forEach(function (pageHelpContentForContentPolicy) { |
|
1537 |
if(communities[i].pid != "openaire" && communities[i].pid != "connect") { |
|
1538 |
newCommunityPageHelpContent = db.pageHelpContent.save({ |
|
1539 |
"page": communities_contentId, "community": communities[i]._id.str, |
|
1540 |
"content": pageHelpContentForContentPolicy.content, |
|
1541 |
"placement": pageHelpContentForContentPolicy.placement, "order": pageHelpContentForContentPolicy.order, |
|
1542 |
"isActive": pageHelpContentForContentPolicy.isActive, "isPriorTo": pageHelpContentForContentPolicy.isPriorTo |
|
1543 |
}); |
|
1544 |
|
|
1545 |
print("Add pageHelpContent on community " + communities[i].pid); |
|
1546 |
} |
|
1547 |
}); |
|
1548 |
} |
|
1549 |
|
|
1550 |
pageHelpContentsForContentPolicy = db.pageHelpContent.find({ |
|
1551 |
community: connectCommunity._id.str, |
|
1552 |
page: contentId |
|
1553 |
}).map(function (pageHelpContent) { |
|
1554 |
return pageHelpContent; |
|
1555 |
}); |
|
1556 |
for (var i = 0; i < pageHelpContentsForContentPolicy.length; i++) { |
|
1557 |
db.pageHelpContent.remove({"_id": pageHelpContentsForContentPolicy[i]._id}); |
|
1558 |
print("Removed pageHelpContent with id " + pageHelpContentsForContentPolicy[i]._id.str + " from community: connect"); |
|
1559 |
} |
|
1560 |
} |
|
1561 |
|
|
1452 | 1562 |
use openaire_admin; |
1453 | 1563 |
|
1454 | 1564 |
//updatePages(); |
... | ... | |
1513 | 1623 |
// removeOldLayouts(); |
1514 | 1624 |
|
1515 | 1625 |
// 13-03-2020 |
1516 |
addSearchResearchOutcomesPages(); |
|
1626 |
//addSearchResearchOutcomesPages(); |
|
1627 |
|
|
1628 |
// 10-04-2020 |
|
1629 |
createNewPagesForConnect(); |
|
1630 |
createNewPagesForCommunities(); |
|
1631 |
removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage(); |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java | ||
---|---|---|
13 | 13 |
@SpringBootApplication |
14 | 14 |
@PropertySources({ |
15 | 15 |
@PropertySource("classpath:admintools.properties"), |
16 |
@PropertySource("classpath:dnet-override.properties")
|
|
16 |
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
|
17 | 17 |
}) |
18 | 18 |
@EnableConfigurationProperties({SecurityConfig.class, MailConfig.class, GoogleConfig.class, MongoConfig.class}) |
19 | 19 |
public class UoaAdminToolsApplication { |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/entities/Subscriber.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
private String email; |
17 | 17 |
|
18 |
public Subscriber() {} |
|
19 |
public Subscriber(String email) { |
|
20 |
this.email = email; |
|
21 |
} |
|
22 |
|
|
18 | 23 |
public String getId() { |
19 | 24 |
return id; |
20 | 25 |
} |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunitySubscribersController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig; |
|
3 | 4 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
4 | 5 |
import eu.dnetlib.uoaadmintools.dao.CommunitySubscribersDAO; |
5 | 6 |
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO; |
... | ... | |
7 | 8 |
import eu.dnetlib.uoaadmintools.entities.CommunitySubscribers; |
8 | 9 |
import eu.dnetlib.uoaadmintools.entities.Subscriber; |
9 | 10 |
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException; |
11 |
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils; |
|
12 |
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo; |
|
10 | 13 |
import org.apache.log4j.Logger; |
11 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 15 |
import org.springframework.web.bind.annotation.*; |
13 | 16 |
|
14 | 17 |
import java.util.ArrayList; |
18 |
import java.util.Iterator; |
|
15 | 19 |
import java.util.List; |
16 | 20 |
|
17 | 21 |
/** |
... | ... | |
27 | 31 |
@Autowired |
28 | 32 |
CommunityDAO communityDAO; |
29 | 33 |
|
34 |
@Autowired |
|
35 |
private SecurityConfig securityConfig; |
|
36 |
|
|
30 | 37 |
private final Logger log = Logger.getLogger(this.getClass()); |
31 | 38 |
@RequestMapping(value = "/community/subscribers", method = RequestMethod.GET) |
32 | 39 |
public List<CommunitySubscribers> getAllCommunitySubscribers(){ |
... | ... | |
43 | 50 |
} |
44 | 51 |
|
45 | 52 |
} |
53 |
|
|
54 |
@RequestMapping(value = "/community/{pid}/subscribers/count", method = RequestMethod.GET) |
|
55 |
public Integer getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException { |
|
56 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
|
57 |
if(communitySubscribers != null){ |
|
58 |
if(communitySubscribers.getSubscribers() != null) { |
|
59 |
return communitySubscribers.getSubscribers().size(); |
|
60 |
} |
|
61 |
}else{ |
|
62 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
63 |
|
|
64 |
} |
|
65 |
return 0; |
|
66 |
} |
|
67 |
|
|
68 |
@RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET) |
|
69 |
public Boolean getIsSubscribedToCommunity(@PathVariable(value="pid", required = true) String pid, |
|
70 |
//@RequestBody String email, |
|
71 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
72 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
73 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
74 |
UserInfo userInfo = helper.getUserInfo(token); |
|
75 |
|
|
76 |
if(userInfo != null) { |
|
77 |
String email = userInfo.getEmail(); |
|
78 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
|
79 |
if (communitySubscribers != null) { |
|
80 |
if (communitySubscribers.getSubscribers() != null) { |
|
81 |
for (Subscriber subscriber : communitySubscribers.getSubscribers()) { |
|
82 |
if (subscriber.getEmail().equals(email)) { |
|
83 |
return true; |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} else { |
|
88 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
89 |
|
|
90 |
} |
|
91 |
} |
|
92 |
return false; |
|
93 |
} |
|
94 |
|
|
95 |
@RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST) |
|
96 |
public Boolean addSubscriberInCommunity(@PathVariable(value="pid", required = true) String pid, |
|
97 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
98 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
99 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
100 |
UserInfo userInfo = helper.getUserInfo(token); |
|
101 |
|
|
102 |
if(userInfo != null) { |
|
103 |
String email = userInfo.getEmail(); |
|
104 |
Subscriber subscriber = new Subscriber(email); |
|
105 |
|
|
106 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
|
107 |
if (communitySubscribers == null) { |
|
108 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
109 |
} |
|
110 |
|
|
111 |
Subscriber savedSubscriber = subscriberDAO.findByEmail(email); |
|
112 |
if (savedSubscriber == null) { |
|
113 |
savedSubscriber = subscriberDAO.save(subscriber); |
|
114 |
} |
|
115 |
for (Subscriber sub : communitySubscribers.getSubscribers()) { |
|
116 |
if (sub.getEmail().equals(subscriber.getEmail())) { |
|
117 |
//already subscribed |
|
118 |
return false; |
|
119 |
} |
|
120 |
} |
|
121 |
//not subscribed yet |
|
122 |
communitySubscribers.getSubscribers().add(savedSubscriber); |
|
123 |
communitySubscriberDAO.save(communitySubscribers); |
|
124 |
return true; |
|
125 |
} |
|
126 |
return false; |
|
127 |
|
|
128 |
} |
|
129 |
@RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST) |
|
130 |
public Boolean deleteSubscriberFromCommunity(@PathVariable(value="pid", required = true) String pid, |
|
131 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
132 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
133 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
134 |
UserInfo userInfo = helper.getUserInfo(token); |
|
135 |
|
|
136 |
if(userInfo != null) { |
|
137 |
String email = userInfo.getEmail(); |
|
138 |
|
|
139 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
|
140 |
if (communitySubscribers == null) { |
|
141 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
142 |
} |
|
143 |
|
|
144 |
Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator(); |
|
145 |
while(subscriberIterator.hasNext()) { |
|
146 |
Subscriber subscriber = subscriberIterator.next(); |
|
147 |
if(subscriber.getEmail().equals(email)) { |
|
148 |
subscriberIterator.remove(); |
|
149 |
communitySubscriberDAO.save(communitySubscribers); |
|
150 |
return true; |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
return false; |
|
155 |
} |
|
156 |
|
|
46 | 157 |
@RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST) |
47 |
public CommunitySubscribers addSubscriberInCommunity(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException { |
|
158 |
public CommunitySubscribers addSubscriberInCommunityByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
|
48 | 159 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
49 | 160 |
if(communitySubscribers == null){ |
50 | 161 |
throw new ContentNotFoundException("Community Subscribers not found"); |
... | ... | |
66 | 177 |
|
67 | 178 |
} |
68 | 179 |
@RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST) |
69 |
public CommunitySubscribers deleteSubscriberFromCommunity(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException { |
|
180 |
public CommunitySubscribers deleteSubscriberFromCommunityByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
|
|
70 | 181 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid); |
71 | 182 |
if(communitySubscribers == null){ |
72 | 183 |
throw new ContentNotFoundException("Community Subscribers not found"); |
... | ... | |
82 | 193 |
} |
83 | 194 |
|
84 | 195 |
@RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET) |
85 |
public List<String> getCommunitiesPerSubcriber(@RequestParam(value="email", required = true) String email) { |
|
86 |
List<CommunitySubscribers> communitySubscribers = communitySubscriberDAO.findAll(); |
|
196 |
public List<String> getCommunitiesPerSubcriber(//@RequestParam(value="email", required = true) String email, |
|
197 |
@RequestHeader("X-XSRF-TOKEN") String token) { |
|
198 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
199 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
200 |
UserInfo userInfo = helper.getUserInfo(token); |
|
201 |
|
|
87 | 202 |
List<String> list = new ArrayList<>(); |
88 |
for(CommunitySubscribers s:communitySubscribers){ |
|
89 |
for(Subscriber sub:s.getSubscribers()) { |
|
90 |
if (sub.getEmail().equals(email)) { |
|
91 |
list.add(s.getPid()); |
|
92 |
break; |
|
203 |
|
|
204 |
if (userInfo != null) { |
|
205 |
String email = userInfo.getEmail(); |
|
206 |
List<CommunitySubscribers> communitySubscribers = communitySubscriberDAO.findAll(); |
|
207 |
|
|
208 |
for (CommunitySubscribers s : communitySubscribers) { |
|
209 |
for (Subscriber sub : s.getSubscribers()) { |
|
210 |
if (sub.getEmail().equals(email)) { |
|
211 |
list.add(s.getPid()); |
|
212 |
break; |
|
213 |
} |
|
93 | 214 |
} |
94 | 215 |
} |
95 | 216 |
} |
modules/uoa-admin-tools/trunk/src/main/resources/admintools.properties | ||
---|---|---|
1 | 1 |
#dev |
2 |
#admintool.security.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
|
3 |
#admintool.security.originServer = .di.uoa.gr
|
|
4 |
#admintool.security.postsAllowed = /contact,/contact/
|
|
5 |
#admintool.mail.host = smtp.gmail.com
|
|
6 |
#admintool.mail.port = 587
|
|
7 |
#admintool.mail.auth = true
|
|
8 |
#admintool.mail.from = openaire.test@gmail.com
|
|
9 |
#admintool.mail.username = openaire.test@gmail.com
|
|
10 |
#admintool.mail.password =
|
|
11 |
#admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
|
|
12 |
#admintool.mongodb.host=localhost
|
|
13 |
#admintool.mongodb.port=27017
|
|
14 |
#admintool.mongodb.database=openaire_admin
|
|
2 |
admintool.security.userInfoUrl = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
|
3 |
admintool.security.originServer = .di.uoa.gr |
|
4 |
admintool.security.postsAllowed = /contact,/contact/ |
|
5 |
admintool.mail.host = smtp.gmail.com |
|
6 |
admintool.mail.port = 587 |
|
7 |
admintool.mail.auth = true |
|
8 |
admintool.mail.from = openaire.test@gmail.com |
|
9 |
admintool.mail.username = openaire.test@gmail.com |
|
10 |
admintool.mail.password = |
|
11 |
admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_ |
|
12 |
admintool.mongodb.host=localhost |
|
13 |
admintool.mongodb.port=27017 |
|
14 |
admintool.mongodb.database=openaire_admin |
|
15 | 15 |
|
16 | 16 |
#beta |
17 | 17 |
#admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken= |
Also available in: Unified diff
[Trunk | Admin Tools Service]:
1. admintools.properties & UoaAdminToolsApplication.java: Uncomment admintools.properties and ignore if @PropertySource for dnet-override.properties not found, to let tests runs.
2. Subscriber.java: Add default constructor and constructor with email parameter.
3. CommunitySubscribersController.java:
a. Autowire SecurityConfig to let methods get UserInfo via token.
b. Add GET method "getNumberOfSubscribersPerCommunity()" (/community/{pid}/subscribers/count).
c. Add GET methos "getIsSubscribedToCommunity()" (/community/{pid}/is-subscriber): Return true/ false and gets user email via token in @RequestHeader("X-XSRF-TOKEN").
d. Method "addSubscriberInCommunity()" renamed to "addSubscriberInCommunityByEmail()" | Method "deleteSubscriberFromCommunity()" renamed to "deleteSubscriberFromCommunityByEmail()".
e. Add POST methods "addSubscriberInCommunity()" (/community/{pid}/subscriber) and "deleteSubscriberFromCommunity()" (/community/{pid}/subscriber/delete):
Return true/ false and get user email via token in @RequestHeader("X-XSRF-TOKEN").
f. Method getCommunitiesPerSubcriber(@RequestParam(value="email", required = true) String email) --> getCommunitiesPerSubcriber(@RequestHeader("X-XSRF-TOKEN") String token):
Get user email via token in @RequestHeader("X-XSRF-TOKEN").
4. update_db.js:
a. Add method "createNewPagesForConnect()": adds page "/publications" for connect (enabled).
b. Add method "createNewPagesForCommunities()": adds pages "/content" (enabled), "/projects" (disabled), "/national-bulletins" (disabled), "/subjects"(disabled) for communities.
c. Add method "removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage()": remove old "/content" connect page and move its contents to new "/content" for every community (NOT connect & openaire).